Skip to content

Commit 3d038d7

Browse files
authored
Unrolled build for rust-lang#139606
Rollup merge of rust-lang#139606 - jieyouxu:compiletest-edition2024, r=compiler-errors Update compiletest to Edition 2024 r? bootstrap (or compiler) try-job: x86_64-apple-1 try-job: x86_64-msvc-1 try-jbo: x86_64-mingw-1
2 parents 69b3959 + 59a1f33 commit 3d038d7

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

src/tools/compiletest/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "compiletest"
33
version = "0.0.0"
4-
edition = "2021"
4+
edition = "2024"
55

66
[lib]
77
doctest = false

src/tools/compiletest/src/debuggers.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ pub(crate) fn configure_gdb(config: &Config) -> Option<Arc<Config>> {
4040
//
4141
// we should figure out how to lift this restriction! (run them all
4242
// on different ports allocated dynamically).
43-
env::set_var("RUST_TEST_THREADS", "1");
43+
//
44+
// SAFETY: at this point we are still single-threaded.
45+
unsafe { env::set_var("RUST_TEST_THREADS", "1") };
4446
}
4547

4648
Some(Arc::new(Config { debugger: Some(Debugger::Gdb), ..config.clone() }))

src/tools/compiletest/src/lib.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,14 @@ pub fn run_tests(config: Arc<Config>) {
529529
}
530530
// Prevent issue #21352 UAC blocking .exe containing 'patch' etc. on Windows
531531
// If #11207 is resolved (adding manifest to .exe) this becomes unnecessary
532-
env::set_var("__COMPAT_LAYER", "RunAsInvoker");
533-
534-
// Let tests know which target they're running as
535-
env::set_var("TARGET", &config.target);
532+
//
533+
// SAFETY: at this point we're still single-threaded.
534+
unsafe { env::set_var("__COMPAT_LAYER", "RunAsInvoker") };
535+
536+
// Let tests know which target they're running as.
537+
//
538+
// SAFETY: at this point we're still single-threaded.
539+
unsafe { env::set_var("TARGET", &config.target) };
536540

537541
let mut configs = Vec::new();
538542
if let Mode::DebugInfo = config.mode {

src/tools/compiletest/src/raise_fd_limit.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/// This fixes issue #7772.
77
#[cfg(target_vendor = "apple")]
88
#[allow(non_camel_case_types)]
9+
// FIXME(#139616): document caller contract.
910
pub unsafe fn raise_fd_limit() {
1011
use std::ptr::null_mut;
1112
use std::{cmp, io};
@@ -21,16 +22,19 @@ pub unsafe fn raise_fd_limit() {
2122
let mut mib: [libc::c_int; 2] = [CTL_KERN, KERN_MAXFILESPERPROC];
2223
let mut maxfiles: libc::c_int = 0;
2324
let mut size: libc::size_t = size_of_val(&maxfiles) as libc::size_t;
24-
if libc::sysctl(&mut mib[0], 2, &mut maxfiles as *mut _ as *mut _, &mut size, null_mut(), 0)
25-
!= 0
25+
// FIXME(#139616): justify why this is sound.
26+
if unsafe {
27+
libc::sysctl(&mut mib[0], 2, &mut maxfiles as *mut _ as *mut _, &mut size, null_mut(), 0)
28+
} != 0
2629
{
2730
let err = io::Error::last_os_error();
2831
panic!("raise_fd_limit: error calling sysctl: {}", err);
2932
}
3033

3134
// Fetch the current resource limits
3235
let mut rlim = libc::rlimit { rlim_cur: 0, rlim_max: 0 };
33-
if libc::getrlimit(libc::RLIMIT_NOFILE, &mut rlim) != 0 {
36+
// FIXME(#139616): justify why this is sound.
37+
if unsafe { libc::getrlimit(libc::RLIMIT_NOFILE, &mut rlim) } != 0 {
3438
let err = io::Error::last_os_error();
3539
panic!("raise_fd_limit: error calling getrlimit: {}", err);
3640
}
@@ -41,7 +45,8 @@ pub unsafe fn raise_fd_limit() {
4145
rlim.rlim_cur = cmp::min(maxfiles as libc::rlim_t, rlim.rlim_max);
4246

4347
// Set our newly-increased resource limit.
44-
if libc::setrlimit(libc::RLIMIT_NOFILE, &rlim) != 0 {
48+
// FIXME(#139616): justify why this is sound.
49+
if unsafe { libc::setrlimit(libc::RLIMIT_NOFILE, &rlim) } != 0 {
4550
let err = io::Error::last_os_error();
4651
panic!("raise_fd_limit: error calling setrlimit: {}", err);
4752
}

src/tools/compiletest/src/read2.rs

+23-5
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ mod imp {
165165
mut err_pipe: ChildStderr,
166166
data: &mut dyn FnMut(bool, &mut Vec<u8>, bool),
167167
) -> io::Result<()> {
168+
// FIXME(#139616): justify why this is sound.
168169
unsafe {
169170
libc::fcntl(out_pipe.as_raw_fd(), libc::F_SETFL, libc::O_NONBLOCK);
170171
libc::fcntl(err_pipe.as_raw_fd(), libc::F_SETFL, libc::O_NONBLOCK);
@@ -175,6 +176,7 @@ mod imp {
175176
let mut out = Vec::new();
176177
let mut err = Vec::new();
177178

179+
// FIXME(#139616): justify why this is sound.
178180
let mut fds: [libc::pollfd; 2] = unsafe { mem::zeroed() };
179181
fds[0].fd = out_pipe.as_raw_fd();
180182
fds[0].events = libc::POLLIN;
@@ -185,6 +187,7 @@ mod imp {
185187

186188
while nfds > 0 {
187189
// wait for either pipe to become readable using `select`
190+
// FIXME(#139616): justify why this is sound.
188191
let r = unsafe { libc::poll(fds.as_mut_ptr(), nfds, -1) };
189192
if r == -1 {
190193
let err = io::Error::last_os_error();
@@ -256,6 +259,7 @@ mod imp {
256259
port.add_handle(0, &out_pipe)?;
257260
port.add_handle(1, &err_pipe)?;
258261

262+
// FIXME(#139616): justify why this is sound.
259263
unsafe {
260264
let mut out_pipe = Pipe::new(out_pipe, &mut out);
261265
let mut err_pipe = Pipe::new(err_pipe, &mut err);
@@ -284,18 +288,23 @@ mod imp {
284288
}
285289

286290
impl<'a> Pipe<'a> {
291+
// FIXME(#139616): document caller contract.
287292
unsafe fn new<P: IntoRawHandle>(p: P, dst: &'a mut Vec<u8>) -> Pipe<'a> {
288293
Pipe {
289294
dst,
290-
pipe: NamedPipe::from_raw_handle(p.into_raw_handle()),
295+
// FIXME(#139616): justify why this is sound.
296+
pipe: unsafe { NamedPipe::from_raw_handle(p.into_raw_handle()) },
291297
overlapped: Overlapped::zero(),
292298
done: false,
293299
}
294300
}
295301

302+
// FIXME(#139616): document caller contract.
296303
unsafe fn read(&mut self) -> io::Result<()> {
297-
let dst = slice_to_end(self.dst);
298-
match self.pipe.read_overlapped(dst, self.overlapped.raw()) {
304+
// FIXME(#139616): justify why this is sound.
305+
let dst = unsafe { slice_to_end(self.dst) };
306+
// FIXME(#139616): justify why this is sound.
307+
match unsafe { self.pipe.read_overlapped(dst, self.overlapped.raw()) } {
299308
Ok(_) => Ok(()),
300309
Err(e) => {
301310
if e.raw_os_error() == Some(ERROR_BROKEN_PIPE.0 as i32) {
@@ -308,22 +317,31 @@ mod imp {
308317
}
309318
}
310319

320+
// FIXME(#139616): document caller contract.
311321
unsafe fn complete(&mut self, status: &CompletionStatus) {
312322
let prev = self.dst.len();
313-
self.dst.set_len(prev + status.bytes_transferred() as usize);
323+
// FIXME(#139616): justify why this is sound.
324+
unsafe { self.dst.set_len(prev + status.bytes_transferred() as usize) };
314325
if status.bytes_transferred() == 0 {
315326
self.done = true;
316327
}
317328
}
318329
}
319330

331+
// FIXME(#139616): document caller contract.
320332
unsafe fn slice_to_end(v: &mut Vec<u8>) -> &mut [u8] {
321333
if v.capacity() == 0 {
322334
v.reserve(16);
323335
}
324336
if v.capacity() == v.len() {
325337
v.reserve(1);
326338
}
327-
slice::from_raw_parts_mut(v.as_mut_ptr().offset(v.len() as isize), v.capacity() - v.len())
339+
// FIXME(#139616): justify why this is sound.
340+
unsafe {
341+
slice::from_raw_parts_mut(
342+
v.as_mut_ptr().offset(v.len() as isize),
343+
v.capacity() - v.len(),
344+
)
345+
}
328346
}
329347
}

0 commit comments

Comments
 (0)