Skip to content

Commit 458adfc

Browse files
authored
Rollup merge of rust-lang#124072 - saethlin:less-sysroot-libc-misc, r=jieyouxu
Remove libc from more tests The goal here is to trim down the number of tests that depend on libc from the sysroot to make rust-lang#123938 more plausible. This PR is a few simple cases that I missed in rust-lang#123943.
2 parents da901d3 + 1567d4d commit 458adfc

File tree

5 files changed

+30
-45
lines changed

5 files changed

+30
-45
lines changed

Diff for: tests/ui/abi/segfault-no-out-of-stack.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
11
//@ run-pass
2-
3-
#![allow(unused_imports)]
42
//@ ignore-wasm32 can't run commands
53
//@ ignore-sgx no processes
64
//@ ignore-fuchsia must translate zircon signal to SIGSEGV/SIGBUS, FIXME (#58590)
7-
#![feature(rustc_private)]
85

9-
extern crate libc;
6+
#![feature(rustc_private)]
107

118
use std::env;
9+
use std::ffi::c_char;
1210
use std::process::{Command, ExitStatus};
1311

1412
#[link(name = "rust_test_helpers", kind = "static")]
1513
extern "C" {
16-
fn rust_get_null_ptr() -> *mut ::libc::c_char;
14+
fn rust_get_null_ptr() -> *mut c_char;
1715
}
1816

1917
#[cfg(unix)]
20-
fn check_status(status: std::process::ExitStatus) {
21-
use libc;
18+
fn check_status(status: ExitStatus) {
19+
extern crate libc;
2220
use std::os::unix::process::ExitStatusExt;
2321

2422
assert!(status.signal() == Some(libc::SIGSEGV) || status.signal() == Some(libc::SIGBUS));
2523
}
2624

2725
#[cfg(not(unix))]
28-
fn check_status(status: std::process::ExitStatus) {
26+
fn check_status(status: ExitStatus) {
2927
assert!(!status.success());
3028
}
3129

Diff for: tests/ui/attributes/unix_sigpipe/unix_sigpipe-and-child-processes.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
// processes with and without the attribute. Search for
1212
// `unix_sigpipe_attr_specified()` in the code base to learn more.
1313

14-
#![feature(rustc_private)]
1514
#![cfg_attr(any(sig_dfl, sig_ign, inherit), feature(unix_sigpipe))]
1615

17-
extern crate libc;
1816
extern crate sigpipe_utils;
1917

2018
use sigpipe_utils::*;

Diff for: tests/ui/extern-flag/auxiliary/panic_handler.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
#![feature(lang_items)]
22
#![no_std]
33

4-
// Since `rustc` generally passes `-nodefaultlibs` to the linker,
5-
// Rust programs link necessary system libraries via `#[link()]`
6-
// attributes in the `libc` crate. `libc` is a dependency of `std`,
7-
// but as we are `#![no_std]`, we need to include it manually.
8-
#![feature(rustc_private)]
9-
extern crate libc;
10-
114
#[panic_handler]
125
pub fn begin_panic_handler(_info: &core::panic::PanicInfo<'_>) -> ! {
136
loop {}
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1+
// Test that println! to a closed stdout does not panic.
2+
// On Windows, close via SetStdHandle to 0.
13
//@ run-pass
2-
#![allow(dead_code)]
34

45
#![feature(rustc_private)]
56

6-
extern crate libc;
7-
8-
type DWORD = u32;
9-
type HANDLE = *mut u8;
10-
type BOOL = i32;
11-
12-
#[cfg(windows)]
13-
extern "system" {
14-
fn SetStdHandle(nStdHandle: DWORD, nHandle: HANDLE) -> BOOL;
15-
}
16-
177
#[cfg(windows)]
188
fn close_stdout() {
9+
type DWORD = u32;
10+
type HANDLE = *mut u8;
11+
type BOOL = i32;
12+
13+
extern "system" {
14+
fn SetStdHandle(nStdHandle: DWORD, nHandle: HANDLE) -> BOOL;
15+
}
16+
1917
const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
2018
unsafe { SetStdHandle(STD_OUTPUT_HANDLE, 0 as HANDLE); }
2119
}
2220

23-
#[cfg(windows)]
21+
#[cfg(not(windows))]
22+
fn close_stdout() {}
23+
2424
fn main() {
2525
close_stdout();
2626
println!("hello");
2727
println!("world");
2828
}
29-
30-
#[cfg(not(windows))]
31-
fn main() {}

Diff for: tests/ui/rfcs/rfc-1014-stdout-existential-crisis/rfc-1014.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1+
// Test that println! to a closed stdout does not panic.
2+
// On Windows, close via CloseHandle.
13
//@ run-pass
2-
#![allow(dead_code)]
34
//@ ignore-sgx no libc
45

56
#![feature(rustc_private)]
67

7-
extern crate libc;
8-
9-
type DWORD = u32;
10-
type HANDLE = *mut u8;
11-
12-
#[cfg(windows)]
13-
extern "system" {
14-
fn GetStdHandle(which: DWORD) -> HANDLE;
15-
fn CloseHandle(handle: HANDLE) -> i32;
16-
}
17-
188
#[cfg(windows)]
199
fn close_stdout() {
10+
type DWORD = u32;
11+
type HANDLE = *mut u8;
12+
13+
extern "system" {
14+
fn GetStdHandle(which: DWORD) -> HANDLE;
15+
fn CloseHandle(handle: HANDLE) -> i32;
16+
}
17+
2018
const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
2119
unsafe { CloseHandle(GetStdHandle(STD_OUTPUT_HANDLE)); }
2220
}
2321

2422
#[cfg(not(windows))]
2523
fn close_stdout() {
24+
extern crate libc;
2625
unsafe { libc::close(1); }
2726
}
2827

0 commit comments

Comments
 (0)