From e7cb9515b4561a07e65f4ba2c7ffa56ac238f8ed Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Mon, 15 Apr 2024 23:46:27 -0400 Subject: [PATCH] Remove libc from more tests --- tests/ui/abi/anon-extern-mod.rs | 6 +---- tests/ui/abi/c-stack-as-value.rs | 6 +---- .../anon-extern-mod-cross-crate-1.rs | 5 +--- .../auxiliary/extern-crosscrate-source.rs | 17 +++++--------- tests/ui/abi/extern/extern-call-deep.rs | 18 +++++---------- tests/ui/abi/extern/extern-call-deep2.rs | 23 ++++++++----------- tests/ui/abi/extern/extern-call-indirect.rs | 16 ++++--------- tests/ui/abi/extern/extern-call-scrub.rs | 20 ++++++---------- tests/ui/abi/extern/extern-crosscrate.rs | 7 ++---- tests/ui/abi/foreign/auxiliary/foreign_lib.rs | 11 +++------ .../ui/abi/foreign/foreign-call-no-runtime.rs | 13 ++++------- tests/ui/abi/foreign/foreign-dupe.rs | 2 +- tests/ui/abi/foreign/foreign-no-abi.rs | 6 +---- tests/ui/abi/segfault-no-out-of-stack.rs | 14 +++++------ tests/ui/attributes/item-attributes.rs | 2 +- .../unix_sigpipe-and-child-processes.rs | 2 -- .../ui/extern-flag/auxiliary/panic_handler.rs | 7 ------ tests/ui/extern/issue-1251.rs | 5 +--- .../rfc-1014-2.rs | 4 ---- .../rfc-1014.rs | 7 +----- 20 files changed, 57 insertions(+), 134 deletions(-) diff --git a/tests/ui/abi/anon-extern-mod.rs b/tests/ui/abi/anon-extern-mod.rs index a424f93f637c9..bb3739bc4afab 100644 --- a/tests/ui/abi/anon-extern-mod.rs +++ b/tests/ui/abi/anon-extern-mod.rs @@ -1,13 +1,9 @@ //@ run-pass //@ pretty-expanded FIXME #23616 -#![feature(rustc_private)] - -extern crate libc; - #[link(name = "rust_test_helpers", kind = "static")] extern "C" { - fn rust_get_test_int() -> libc::intptr_t; + fn rust_get_test_int() -> isize; } pub fn main() { diff --git a/tests/ui/abi/c-stack-as-value.rs b/tests/ui/abi/c-stack-as-value.rs index 6ea2051b05b3e..401bc132b6e77 100644 --- a/tests/ui/abi/c-stack-as-value.rs +++ b/tests/ui/abi/c-stack-as-value.rs @@ -1,14 +1,10 @@ //@ run-pass //@ pretty-expanded FIXME #23616 -#![feature(rustc_private)] - mod rustrt { - extern crate libc; - #[link(name = "rust_test_helpers", kind = "static")] extern "C" { - pub fn rust_get_test_int() -> libc::intptr_t; + pub fn rust_get_test_int() -> isize; } } diff --git a/tests/ui/abi/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs b/tests/ui/abi/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs index 5cbf8093c5c3c..559c40546a8a5 100644 --- a/tests/ui/abi/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs +++ b/tests/ui/abi/cross-crate/auxiliary/anon-extern-mod-cross-crate-1.rs @@ -1,9 +1,6 @@ #![crate_name = "anonexternmod"] -#![feature(rustc_private)] - -extern crate libc; #[link(name = "rust_test_helpers", kind = "static")] extern "C" { - pub fn rust_get_test_int() -> libc::intptr_t; + pub fn rust_get_test_int() -> isize; } diff --git a/tests/ui/abi/extern/auxiliary/extern-crosscrate-source.rs b/tests/ui/abi/extern/auxiliary/extern-crosscrate-source.rs index 9c61518b94142..755f00d71fdb0 100644 --- a/tests/ui/abi/extern/auxiliary/extern-crosscrate-source.rs +++ b/tests/ui/abi/extern/auxiliary/extern-crosscrate-source.rs @@ -1,28 +1,23 @@ #![crate_name = "externcallback"] #![crate_type = "lib"] -#![feature(rustc_private)] - -extern crate libc; pub mod rustrt { - extern crate libc; - #[link(name = "rust_test_helpers", kind = "static")] extern "C" { pub fn rust_dbg_call( - cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, - data: libc::uintptr_t, - ) -> libc::uintptr_t; + cb: extern "C" fn(usize) -> usize, + data: usize, + ) -> usize; } } -pub fn fact(n: libc::uintptr_t) -> libc::uintptr_t { +pub fn fact(n: usize) -> usize { unsafe { - println!("n = {}", n); + println!("n = {:?}", n); rustrt::rust_dbg_call(cb, n) } } -pub extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t { +pub extern "C" fn cb(data: usize) -> usize { if data == 1 { data } else { fact(data - 1) * data } } diff --git a/tests/ui/abi/extern/extern-call-deep.rs b/tests/ui/abi/extern/extern-call-deep.rs index 062e70b1b6ee5..9f033d528e569 100644 --- a/tests/ui/abi/extern/extern-call-deep.rs +++ b/tests/ui/abi/extern/extern-call-deep.rs @@ -1,29 +1,23 @@ //@ run-pass //@ ignore-emscripten blows the JS stack -#![feature(rustc_private)] - -extern crate libc; - mod rustrt { - extern crate libc; - #[link(name = "rust_test_helpers", kind = "static")] extern "C" { pub fn rust_dbg_call( - cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, - data: libc::uintptr_t, - ) -> libc::uintptr_t; + cb: extern "C" fn(usize) -> usize, + data: usize, + ) -> usize; } } -extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t { +extern "C" fn cb(data: usize) -> usize { if data == 1 { data } else { count(data - 1) + 1 } } -fn count(n: libc::uintptr_t) -> libc::uintptr_t { +fn count(n: usize) -> usize { unsafe { - println!("n = {}", n); + println!("n = {:?}", n); rustrt::rust_dbg_call(cb, n) } } diff --git a/tests/ui/abi/extern/extern-call-deep2.rs b/tests/ui/abi/extern/extern-call-deep2.rs index c021bc223482d..093cd19b6ab90 100644 --- a/tests/ui/abi/extern/extern-call-deep2.rs +++ b/tests/ui/abi/extern/extern-call-deep2.rs @@ -1,30 +1,25 @@ //@ run-pass -#![allow(unused_must_use)] //@ needs-threads -#![feature(rustc_private)] -extern crate libc; use std::thread; mod rustrt { - extern crate libc; - #[link(name = "rust_test_helpers", kind = "static")] extern "C" { pub fn rust_dbg_call( - cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, - data: libc::uintptr_t, - ) -> libc::uintptr_t; + cb: extern "C" fn(usize) -> usize, + data: usize, + ) -> usize; } } -extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t { - if data == 1 { data } else { count(data - 1) + 1 } +extern "C" fn cb(data: usize) -> usize { + if data == 1 { data } else { count(data - 1 ) + 1 } } -fn count(n: libc::uintptr_t) -> libc::uintptr_t { +fn count(n: usize) -> usize { unsafe { - println!("n = {}", n); + println!("n = {:?}", n); rustrt::rust_dbg_call(cb, n) } } @@ -34,8 +29,8 @@ pub fn main() { // has a large stack) thread::spawn(move || { let result = count(1000); - println!("result = {}", result); + println!("result = {:?}", result); assert_eq!(result, 1000); }) - .join(); + .join().unwrap(); } diff --git a/tests/ui/abi/extern/extern-call-indirect.rs b/tests/ui/abi/extern/extern-call-indirect.rs index 18fb07d8c8bbd..cb6e0dff4340f 100644 --- a/tests/ui/abi/extern/extern-call-indirect.rs +++ b/tests/ui/abi/extern/extern-call-indirect.rs @@ -1,26 +1,20 @@ //@ run-pass -#![feature(rustc_private)] - -extern crate libc; - mod rustrt { - extern crate libc; - #[link(name = "rust_test_helpers", kind = "static")] extern "C" { pub fn rust_dbg_call( - cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, - data: libc::uintptr_t, - ) -> libc::uintptr_t; + cb: extern "C" fn(usize) -> usize, + data: usize, + ) -> usize; } } -extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t { +extern "C" fn cb(data: usize) -> usize { if data == 1 { data } else { fact(data - 1) * data } } -fn fact(n: libc::uintptr_t) -> libc::uintptr_t { +fn fact(n: usize) -> usize { unsafe { println!("n = {}", n); rustrt::rust_dbg_call(cb, n) diff --git a/tests/ui/abi/extern/extern-call-scrub.rs b/tests/ui/abi/extern/extern-call-scrub.rs index 7edf8975ad816..78bad9540d965 100644 --- a/tests/ui/abi/extern/extern-call-scrub.rs +++ b/tests/ui/abi/extern/extern-call-scrub.rs @@ -1,32 +1,26 @@ //@ run-pass -#![allow(unused_must_use)] +//@ needs-threads // This time we're testing repeatedly going up and down both stacks to // make sure the stack pointers are maintained properly in both // directions -//@ needs-threads -#![feature(rustc_private)] - -extern crate libc; use std::thread; mod rustrt { - extern crate libc; - #[link(name = "rust_test_helpers", kind = "static")] extern "C" { pub fn rust_dbg_call( - cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, - data: libc::uintptr_t, - ) -> libc::uintptr_t; + cb: extern "C" fn(usize) -> usize, + data: usize, + ) -> usize; } } -extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t { +extern "C" fn cb(data: usize) -> usize { if data == 1 { data } else { count(data - 1) + count(data - 1) } } -fn count(n: libc::uintptr_t) -> libc::uintptr_t { +fn count(n: usize) -> usize { unsafe { println!("n = {}", n); rustrt::rust_dbg_call(cb, n) @@ -41,5 +35,5 @@ pub fn main() { println!("result = {}", result); assert_eq!(result, 2048); }) - .join(); + .join().unwrap(); } diff --git a/tests/ui/abi/extern/extern-crosscrate.rs b/tests/ui/abi/extern/extern-crosscrate.rs index c283cbe321637..0f489d968ea77 100644 --- a/tests/ui/abi/extern/extern-crosscrate.rs +++ b/tests/ui/abi/extern/extern-crosscrate.rs @@ -1,14 +1,11 @@ //@ run-pass //@ aux-build:extern-crosscrate-source.rs -#![feature(rustc_private)] - extern crate externcallback; -extern crate libc; -fn fact(n: libc::uintptr_t) -> libc::uintptr_t { +fn fact(n: usize) -> usize { unsafe { - println!("n = {}", n); + println!("n = {:?}", n); externcallback::rustrt::rust_dbg_call(externcallback::cb, n) } } diff --git a/tests/ui/abi/foreign/auxiliary/foreign_lib.rs b/tests/ui/abi/foreign/auxiliary/foreign_lib.rs index 3c649b778bd1a..039af6c696bdd 100644 --- a/tests/ui/abi/foreign/auxiliary/foreign_lib.rs +++ b/tests/ui/abi/foreign/auxiliary/foreign_lib.rs @@ -1,20 +1,15 @@ #![crate_name = "foreign_lib"] -#![feature(rustc_private)] pub mod rustrt { - extern crate libc; - #[link(name = "rust_test_helpers", kind = "static")] extern "C" { - pub fn rust_get_test_int() -> libc::intptr_t; + pub fn rust_get_test_int() -> isize; } } pub mod rustrt2 { - extern crate libc; - extern "C" { - pub fn rust_get_test_int() -> libc::intptr_t; + pub fn rust_get_test_int() -> isize; } } @@ -32,6 +27,6 @@ pub fn local_uses() { unsafe { let x = rustrt::rust_get_test_int(); assert_eq!(x, rustrt2::rust_get_test_int()); - assert_eq!(x as *const _, rustrt3::rust_get_test_int()); + assert_eq!(x as *const u8, rustrt3::rust_get_test_int()); } } diff --git a/tests/ui/abi/foreign/foreign-call-no-runtime.rs b/tests/ui/abi/foreign/foreign-call-no-runtime.rs index fccd62b6100f3..dd683a3a45224 100644 --- a/tests/ui/abi/foreign/foreign-call-no-runtime.rs +++ b/tests/ui/abi/foreign/foreign-call-no-runtime.rs @@ -1,16 +1,13 @@ //@ run-pass //@ needs-threads -#![feature(rustc_private)] - -extern crate libc; - +use std::ffi::c_void; use std::mem; use std::thread; #[link(name = "rust_test_helpers", kind = "static")] extern "C" { - fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t), data: libc::uintptr_t) -> libc::uintptr_t; + fn rust_dbg_call(cb: extern "C" fn(*const c_void), data: *const c_void) -> *const c_void; } pub fn main() { @@ -38,21 +35,21 @@ pub fn main() { } } -extern "C" fn callback_isize(data: libc::uintptr_t) { +extern "C" fn callback_isize(data: *const c_void) { unsafe { let data = data as *const isize; assert_eq!(*data, 100); } } -extern "C" fn callback_i64(data: libc::uintptr_t) { +extern "C" fn callback_i64(data: *const c_void) { unsafe { let data = data as *const i64; assert_eq!(*data, 100); } } -extern "C" fn callback_i32(data: libc::uintptr_t) { +extern "C" fn callback_i32(data: *const c_void) { unsafe { let data = data as *const i32; assert_eq!(*data, 100); diff --git a/tests/ui/abi/foreign/foreign-dupe.rs b/tests/ui/abi/foreign/foreign-dupe.rs index 1b6df0892c70f..b5609af233522 100644 --- a/tests/ui/abi/foreign/foreign-dupe.rs +++ b/tests/ui/abi/foreign/foreign-dupe.rs @@ -11,6 +11,6 @@ pub fn main() { unsafe { let x = foreign_lib::rustrt::rust_get_test_int(); assert_eq!(x, foreign_lib::rustrt2::rust_get_test_int()); - assert_eq!(x as *const _, foreign_lib::rustrt3::rust_get_test_int()); + assert_eq!(x as *const u8, foreign_lib::rustrt3::rust_get_test_int()); } } diff --git a/tests/ui/abi/foreign/foreign-no-abi.rs b/tests/ui/abi/foreign/foreign-no-abi.rs index 4ac47df29a710..24698231232a9 100644 --- a/tests/ui/abi/foreign/foreign-no-abi.rs +++ b/tests/ui/abi/foreign/foreign-no-abi.rs @@ -3,14 +3,10 @@ //@ pretty-expanded FIXME #23616 -#![feature(rustc_private)] - mod rustrt { - extern crate libc; - #[link(name = "rust_test_helpers", kind = "static")] extern "C" { - pub fn rust_get_test_int() -> libc::intptr_t; + pub fn rust_get_test_int() -> isize; } } diff --git a/tests/ui/abi/segfault-no-out-of-stack.rs b/tests/ui/abi/segfault-no-out-of-stack.rs index fb1f8303f9ffd..113c82c30e927 100644 --- a/tests/ui/abi/segfault-no-out-of-stack.rs +++ b/tests/ui/abi/segfault-no-out-of-stack.rs @@ -1,31 +1,29 @@ //@ run-pass - -#![allow(unused_imports)] //@ ignore-wasm32 can't run commands //@ ignore-sgx no processes //@ ignore-fuchsia must translate zircon signal to SIGSEGV/SIGBUS, FIXME (#58590) -#![feature(rustc_private)] -extern crate libc; +#![feature(rustc_private)] use std::env; +use std::ffi::c_char; use std::process::{Command, ExitStatus}; #[link(name = "rust_test_helpers", kind = "static")] extern "C" { - fn rust_get_null_ptr() -> *mut ::libc::c_char; + fn rust_get_null_ptr() -> *mut c_char; } #[cfg(unix)] -fn check_status(status: std::process::ExitStatus) { - use libc; +fn check_status(status: ExitStatus) { + extern crate libc; use std::os::unix::process::ExitStatusExt; assert!(status.signal() == Some(libc::SIGSEGV) || status.signal() == Some(libc::SIGBUS)); } #[cfg(not(unix))] -fn check_status(status: std::process::ExitStatus) { +fn check_status(status: ExitStatus) { assert!(!status.success()); } diff --git a/tests/ui/attributes/item-attributes.rs b/tests/ui/attributes/item-attributes.rs index 7fe7fdd97584e..daab1bccb2c4d 100644 --- a/tests/ui/attributes/item-attributes.rs +++ b/tests/ui/attributes/item-attributes.rs @@ -148,7 +148,7 @@ mod test_foreign_items { #![rustc_dummy] #[rustc_dummy] - fn rust_get_test_int() -> u32; + fn rust_get_test_int() -> isize; } } } diff --git a/tests/ui/attributes/unix_sigpipe/unix_sigpipe-and-child-processes.rs b/tests/ui/attributes/unix_sigpipe/unix_sigpipe-and-child-processes.rs index f96bd634876fd..9d1bd9f9607ec 100644 --- a/tests/ui/attributes/unix_sigpipe/unix_sigpipe-and-child-processes.rs +++ b/tests/ui/attributes/unix_sigpipe/unix_sigpipe-and-child-processes.rs @@ -11,10 +11,8 @@ // processes with and without the attribute. Search for // `unix_sigpipe_attr_specified()` in the code base to learn more. -#![feature(rustc_private)] #![cfg_attr(any(sig_dfl, sig_ign, inherit), feature(unix_sigpipe))] -extern crate libc; extern crate sigpipe_utils; use sigpipe_utils::*; diff --git a/tests/ui/extern-flag/auxiliary/panic_handler.rs b/tests/ui/extern-flag/auxiliary/panic_handler.rs index a625761a838a8..9953b783c62db 100644 --- a/tests/ui/extern-flag/auxiliary/panic_handler.rs +++ b/tests/ui/extern-flag/auxiliary/panic_handler.rs @@ -1,13 +1,6 @@ #![feature(lang_items)] #![no_std] -// Since `rustc` generally passes `-nodefaultlibs` to the linker, -// Rust programs link necessary system libraries via `#[link()]` -// attributes in the `libc` crate. `libc` is a dependency of `std`, -// but as we are `#![no_std]`, we need to include it manually. -#![feature(rustc_private)] -extern crate libc; - #[panic_handler] pub fn begin_panic_handler(_info: &core::panic::PanicInfo<'_>) -> ! { loop {} diff --git a/tests/ui/extern/issue-1251.rs b/tests/ui/extern/issue-1251.rs index da2b8be7bc1f3..5581bddaddc16 100644 --- a/tests/ui/extern/issue-1251.rs +++ b/tests/ui/extern/issue-1251.rs @@ -2,13 +2,10 @@ #![allow(unused_attributes)] #![allow(dead_code)] //@ pretty-expanded FIXME #23616 -#![feature(rustc_private)] mod rustrt { - extern crate libc; - extern "C" { - pub fn rust_get_test_int() -> libc::intptr_t; + pub fn rust_get_test_int() -> isize; } } diff --git a/tests/ui/rfcs/rfc-1014-stdout-existential-crisis/rfc-1014-2.rs b/tests/ui/rfcs/rfc-1014-stdout-existential-crisis/rfc-1014-2.rs index 4944de0b82f33..3d387ec8d631a 100644 --- a/tests/ui/rfcs/rfc-1014-stdout-existential-crisis/rfc-1014-2.rs +++ b/tests/ui/rfcs/rfc-1014-stdout-existential-crisis/rfc-1014-2.rs @@ -1,10 +1,6 @@ //@ run-pass #![allow(dead_code)] -#![feature(rustc_private)] - -extern crate libc; - type DWORD = u32; type HANDLE = *mut u8; type BOOL = i32; diff --git a/tests/ui/rfcs/rfc-1014-stdout-existential-crisis/rfc-1014.rs b/tests/ui/rfcs/rfc-1014-stdout-existential-crisis/rfc-1014.rs index cc2d9bad02983..40008895b3a5a 100644 --- a/tests/ui/rfcs/rfc-1014-stdout-existential-crisis/rfc-1014.rs +++ b/tests/ui/rfcs/rfc-1014-stdout-existential-crisis/rfc-1014.rs @@ -1,14 +1,8 @@ //@ run-pass -#![allow(dead_code)] //@ ignore-sgx no libc #![feature(rustc_private)] -extern crate libc; - -type DWORD = u32; -type HANDLE = *mut u8; - #[cfg(windows)] extern "system" { fn GetStdHandle(which: DWORD) -> HANDLE; @@ -23,6 +17,7 @@ fn close_stdout() { #[cfg(not(windows))] fn close_stdout() { + extern crate libc; unsafe { libc::close(1); } }