Skip to content

Commit

Permalink
Rollup merge of #123943 - saethlin:less-sysroot-libc, r=workingjubilee
Browse files Browse the repository at this point in the history
Use the rustc_private libc less in tests

I started looking into our use of `rustc_private` + `extern crate libc;` in tests because of #123938 and it looks like some fraction of the users of libc simply don't need the libc crate anymore.
  • Loading branch information
compiler-errors authored Apr 15, 2024
2 parents 20a5fb3 + 7457a0d commit 89e55f7
Show file tree
Hide file tree
Showing 25 changed files with 88 additions and 125 deletions.
3 changes: 1 addition & 2 deletions tests/ui-fulldeps/regions-mock-tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
// - Multiple lifetime parameters
// - Arenas

#![feature(rustc_private, libc)]
#![feature(rustc_private)]

extern crate rustc_arena;
extern crate libc;

// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
// files.
Expand Down
6 changes: 1 addition & 5 deletions tests/ui/abi/c-stack-returning-int64.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
//@ run-pass
//@ ignore-sgx no libc

#![feature(rustc_private)]

extern crate libc;

use std::ffi::CString;

mod mlibc {
use libc::{c_char, c_long, c_longlong};
use std::ffi::{c_char, c_long, c_longlong};

extern "C" {
pub fn atol(x: *const c_char) -> c_long;
Expand Down
10 changes: 4 additions & 6 deletions tests/ui/abi/statics/static-mut-foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
// statics cannot. This ensures that there's some form of error if this is
// attempted.

#![feature(rustc_private)]

extern crate libc;
use std::ffi::c_int;

#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
static mut rust_dbg_static_mut: libc::c_int;
static mut rust_dbg_static_mut: c_int;
pub fn rust_dbg_static_mut_check_four();
}

unsafe fn static_bound(_: &'static libc::c_int) {}
unsafe fn static_bound(_: &'static c_int) {}

fn static_bound_set(a: &'static mut libc::c_int) {
fn static_bound_set(a: &'static mut c_int) {
*a = 3;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/abi/statics/static-mut-foreign.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: creating a shared reference to mutable static is discouraged
--> $DIR/static-mut-foreign.rs:33:18
--> $DIR/static-mut-foreign.rs:31:18
|
LL | static_bound(&rust_dbg_static_mut);
| ^^^^^^^^^^^^^^^^^^^^ shared reference to mutable static
Expand All @@ -14,7 +14,7 @@ LL | static_bound(addr_of!(rust_dbg_static_mut));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

warning: creating a mutable reference to mutable static is discouraged
--> $DIR/static-mut-foreign.rs:35:22
--> $DIR/static-mut-foreign.rs:33:22
|
LL | static_bound_set(&mut rust_dbg_static_mut);
| ^^^^^^^^^^^^^^^^^^^^^^^^ mutable reference to mutable static
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/array-slice-vec/vec-macro-no-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

extern crate std as other;

extern crate libc;

#[macro_use]
extern crate alloc;

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/auxiliary/check_static_recursion_foreign_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![crate_name = "check_static_recursion_foreign_helper"]
#![crate_type = "lib"]

extern crate libc;
use std::ffi::c_int;

#[no_mangle]
pub static test_static: libc::c_int = 0;
pub static test_static: c_int = 0;
5 changes: 1 addition & 4 deletions tests/ui/check-static-recursion-foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@

//@ pretty-expanded FIXME #23616

#![feature(rustc_private)]

extern crate check_static_recursion_foreign_helper;
extern crate libc;

use libc::c_int;
use std::ffi::c_int;

extern "C" {
static test_static: c_int;
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/extern/extern-const.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

//@ run-rustfix
//@ compile-flags: -g
#![feature(rustc_private)]
extern crate libc;

use std::ffi::c_int;

#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
static rust_dbg_static_mut: libc::c_int; //~ ERROR extern items cannot be `const`
static rust_dbg_static_mut: c_int; //~ ERROR extern items cannot be `const`
}

fn main() {
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/extern/extern-const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

//@ run-rustfix
//@ compile-flags: -g
#![feature(rustc_private)]
extern crate libc;

use std::ffi::c_int;

#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
const rust_dbg_static_mut: libc::c_int; //~ ERROR extern items cannot be `const`
const rust_dbg_static_mut: c_int; //~ ERROR extern items cannot be `const`
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/extern/extern-const.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: extern items cannot be `const`
--> $DIR/extern-const.rs:14:11
|
LL | const rust_dbg_static_mut: libc::c_int;
LL | const rust_dbg_static_mut: c_int;
| ------^^^^^^^^^^^^^^^^^^^
| |
| help: try using a static value: `static`
Expand Down
1 change: 0 additions & 1 deletion tests/ui/internal-lints/existing_doc_keyword.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//@ compile-flags: -Z unstable-options

#![feature(rustc_private)]
#![feature(rustdoc_internals)]

#![crate_type = "lib"]
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/internal-lints/existing_doc_keyword.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error: found non-existing keyword `tadam` used in `#[doc(keyword = "...")]`
--> $DIR/existing_doc_keyword.rs:10:1
--> $DIR/existing_doc_keyword.rs:9:1
|
LL | #[doc(keyword = "tadam")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: only existing keywords are allowed in core/std
note: the lint level is defined here
--> $DIR/existing_doc_keyword.rs:8:9
--> $DIR/existing_doc_keyword.rs:7:9
|
LL | #![deny(rustc::existing_doc_keyword)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
3 changes: 0 additions & 3 deletions tests/ui/issues/issue-13259-windows-tcb-trash.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
//@ run-pass
#![feature(rustc_private)]

extern crate libc;

#[cfg(windows)]
mod imp {
Expand Down
4 changes: 0 additions & 4 deletions tests/ui/issues/issue-22034.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#![feature(rustc_private)]

extern crate libc;

fn main() {
let ptr: *mut () = core::ptr::null_mut();
let _: &mut dyn Fn() = unsafe {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-22034.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0277]: expected a `Fn()` closure, found `()`
--> $DIR/issue-22034.rs:8:16
--> $DIR/issue-22034.rs:4:16
|
LL | &mut *(ptr as *mut dyn Fn())
| ^^^ expected an `Fn()` closure, found `()`
Expand Down
8 changes: 2 additions & 6 deletions tests/ui/issues/issue-2214.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
//@ run-pass
//@ ignore-wasm32 wasi-libc does not have lgamma
//@ ignore-sgx no libc
#![feature(rustc_private)]

extern crate libc;

use libc::{c_double, c_int};
use std::ffi::{c_double, c_int};
use std::mem;

fn to_c_int(v: &mut isize) -> &mut c_int {
Expand All @@ -19,8 +16,7 @@ fn lgamma(n: c_double, value: &mut isize) -> c_double {
}

mod m {
use libc::{c_double, c_int};

use std::ffi::{c_double, c_int};
extern "C" {
#[cfg(all(unix, not(target_os = "vxworks")))]
#[link_name="lgamma_r"]
Expand Down
4 changes: 1 addition & 3 deletions tests/ui/issues/issue-3656.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
// the alignment of elements into account.

//@ pretty-expanded FIXME #23616
#![feature(rustc_private)]

extern crate libc;
use libc::{c_uint, c_void};
use std::ffi::{c_uint, c_void};

pub struct KEYGEN {
hash_algorithm: [c_uint; 2],
Expand Down
9 changes: 3 additions & 6 deletions tests/ui/lint/lint-ctypes-fn.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#![feature(rustc_private)]

#![allow(private_interfaces)]
#![deny(improper_ctypes_definitions)]

extern crate libc;

use std::default::Default;
use std::marker::PhantomData;
use std::ffi::{c_int, c_uint};

trait Trait {}

Expand Down Expand Up @@ -165,10 +162,10 @@ pub extern "C" fn good17(p: TransparentCustomZst) { }
pub extern "C" fn good18(_: &String) { }

#[cfg(not(target_arch = "wasm32"))]
pub extern "C" fn good1(size: *const libc::c_int) { }
pub extern "C" fn good1(size: *const c_int) { }

#[cfg(not(target_arch = "wasm32"))]
pub extern "C" fn good2(size: *const libc::c_uint) { }
pub extern "C" fn good2(size: *const c_uint) { }

pub extern "C" fn unused_generic1<T>(size: *const Foo) { }

Expand Down
Loading

0 comments on commit 89e55f7

Please sign in to comment.