diff --git a/library/std/src/alloc.rs b/library/std/src/alloc.rs index 9e9052ff92e1b..8ee55234cea43 100644 --- a/library/std/src/alloc.rs +++ b/library/std/src/alloc.rs @@ -315,7 +315,7 @@ pub fn take_alloc_error_hook() -> fn(Layout) { } fn default_alloc_error_hook(layout: Layout) { - rterr!("memory allocation of {} bytes failed\n", layout.size()); + rtprintpanic!("memory allocation of {} bytes failed\n", layout.size()); } #[cfg(not(test))] diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 9091151518579..02957e75a7409 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -596,15 +596,12 @@ fn rust_panic_with_hook( if panics > 2 { // Don't try to print the message in this case // - perhaps that is causing the recursive panics. - rterr!("thread panicked while processing panic. aborting.\n"); + rtprintpanic!("thread panicked while processing panic. aborting.\n"); } else { // Unfortunately, this does not print a backtrace, because creating // a `Backtrace` will allocate, which we must to avoid here. let panicinfo = PanicInfo::internal_constructor(message, location); - rterr!( - "{}\npanicked after panic::always_abort(), aborting.\n", - panicinfo - ); + rtprintpanic!("{}\npanicked after panic::always_abort(), aborting.\n", panicinfo); } intrinsics::abort() } @@ -637,7 +634,7 @@ fn rust_panic_with_hook( // have limited options. Currently our preference is to // just abort. In the future we may consider resuming // unwinding or otherwise exiting the thread cleanly. - rterr!("thread panicked while panicking. aborting.\n"); + rtprintpanic!("thread panicked while panicking. aborting.\n"); intrinsics::abort() } diff --git a/library/std/src/sys/unix/stack_overflow.rs b/library/std/src/sys/unix/stack_overflow.rs index 72fd48278bc16..81f47a779d33b 100644 --- a/library/std/src/sys/unix/stack_overflow.rs +++ b/library/std/src/sys/unix/stack_overflow.rs @@ -102,7 +102,7 @@ mod imp { // If the faulting address is within the guard page, then we print a // message saying so and abort. if guard.start <= addr && addr < guard.end { - rterr!( + rtprintpanic!( "\nthread '{}' has overflowed its stack\n", thread::current().name().unwrap_or("") ); diff --git a/library/std/src/sys/windows/stack_overflow.rs b/library/std/src/sys/windows/stack_overflow.rs index 24ba35ad17e63..755dc0a6c8b47 100644 --- a/library/std/src/sys/windows/stack_overflow.rs +++ b/library/std/src/sys/windows/stack_overflow.rs @@ -24,7 +24,7 @@ extern "system" fn vectored_handler(ExceptionInfo: *mut c::EXCEPTION_POINTERS) - let code = rec.ExceptionCode; if code == c::EXCEPTION_STACK_OVERFLOW { - rterr!( + rtprintpanic!( "\nthread '{}' has overflowed its stack\n", thread::current().name().unwrap_or("") ); diff --git a/library/std/src/sys_common/rt.rs b/library/std/src/sys_common/rt.rs index e4c9b60594ef7..02013ecc4ced6 100644 --- a/library/std/src/sys_common/rt.rs +++ b/library/std/src/sys_common/rt.rs @@ -39,7 +39,11 @@ pub fn cleanup() { }); } -macro_rules! rterr { +// Prints to the "panic output", depending on the platform this may be: +// - the standard error output +// - some dedicated platform specific output +// - nothing (so this macro is a no-op) +macro_rules! rtprintpanic { ($($t:tt)*) => { if let Some(mut out) = crate::sys::stdio::panic_output() { let _ = crate::io::Write::write_fmt(&mut out, format_args!($($t)*)); @@ -50,7 +54,7 @@ macro_rules! rterr { macro_rules! rtabort { ($($t:tt)*) => { { - rterr!("fatal runtime error: {}\n", format_args!($($t)*)); + rtprintpanic!("fatal runtime error: {}\n", format_args!($($t)*)); crate::sys::abort_internal(); } }