rust/tests/ui/rfcs/rfc-1014-stdout-existential-crisis/rfc-1014-2.rs
2024-04-17 08:36:49 -04:00

29 lines
589 B
Rust

// Test that println! to a closed stdout does not panic.
// On Windows, close via SetStdHandle to 0.
//@ run-pass
#![feature(rustc_private)]
#[cfg(windows)]
fn close_stdout() {
type DWORD = u32;
type HANDLE = *mut u8;
type BOOL = i32;
extern "system" {
fn SetStdHandle(nStdHandle: DWORD, nHandle: HANDLE) -> BOOL;
}
const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
unsafe { SetStdHandle(STD_OUTPUT_HANDLE, 0 as HANDLE); }
}
#[cfg(not(windows))]
fn close_stdout() {}
fn main() {
close_stdout();
println!("hello");
println!("world");
}