//! * Executing a panic up to doing the actual implementation
//! * Shims around "try"
-use core::panic::BoxMeUp;
-
-use io::prelude::*;
-
-use any::Any;
-use cell::RefCell;
-use core::panic::{PanicInfo, Location};
-use fmt;
-use intrinsics;
-use mem;
-use ptr;
-use raw;
-use sys::stdio::panic_output;
-use sys_common::rwlock::RWLock;
-use sys_common::thread_info;
-use sys_common::util;
-use thread;
-
-thread_local! {
- pub static LOCAL_STDERR: RefCell<Option<Box<dyn Write + Send>>> = {
- RefCell::new(None)
- }
-}
+use core::panic::{BoxMeUp, PanicInfo, Location};
+
+use crate::any::Any;
+use crate::fmt;
+use crate::intrinsics;
+use crate::mem;
+use crate::ptr;
+use crate::raw;
+use crate::sys::stdio::panic_output;
+use crate::sys_common::rwlock::RWLock;
+use crate::sys_common::thread_info;
+use crate::sys_common::util;
+use crate::thread;
+
+#[cfg(not(test))]
+use crate::io::set_panic;
+// make sure to use the stderr output configured
+// by libtest in the real copy of std
+#[cfg(test)]
+use realstd::io::set_panic;
// Binary interface to the panic runtime that the standard library depends on.
//
fn default_hook(info: &PanicInfo) {
#[cfg(feature = "backtrace")]
- use sys_common::backtrace;
+ use crate::sys_common::backtrace;
// If this is a double panic, make sure that we print a backtrace
// for this panic. Otherwise only print it if logging is enabled.
let thread = thread_info::current_thread();
let name = thread.as_ref().and_then(|t| t.name()).unwrap_or("<unnamed>");
- let write = |err: &mut dyn (::io::Write)| {
+ let write = |err: &mut dyn crate::io::Write| {
let _ = writeln!(err, "thread '{}' panicked at '{}', {}",
name, msg, location);
#[cfg(feature = "backtrace")]
{
- use sync::atomic::{AtomicBool, Ordering};
+ use crate::sync::atomic::{AtomicBool, Ordering};
static FIRST_PANIC: AtomicBool = AtomicBool::new(true);
}
};
- if let Some(mut local) = LOCAL_STDERR.with(|s| s.borrow_mut().take()) {
- write(&mut *local);
- let mut s = Some(local);
- LOCAL_STDERR.with(|slot| {
- *slot.borrow_mut() = s.take();
- });
+ if let Some(mut local) = set_panic(None) {
+ // NB. In `cfg(test)` this uses the forwarding impl
+ // for `Box<dyn (::realstd::io::Write) + Send>`.
+ write(&mut local);
+ set_panic(Some(local));
} else if let Some(mut out) = panic_output() {
write(&mut out);
}
#[doc(hidden)]
#[unstable(feature = "update_panic_count", issue = "0")]
pub fn update_panic_count(amt: isize) -> usize {
- use cell::Cell;
+ use crate::cell::Cell;
thread_local! { static PANIC_COUNT: Cell<usize> = Cell::new(0) }
PANIC_COUNT.with(|c| {
pub use realstd::rt::update_panic_count;
/// Invoke a closure, capturing the cause of an unwinding panic if one occurs.
-pub unsafe fn try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>> {
+pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>> {
#[allow(unions_with_drop_fields)]
union Data<F, R> {
f: F,
}
fn fill(&mut self) -> &mut String {
- use fmt::Write;
+ use crate::fmt::Write;
let inner = self.inner;
self.string.get_or_insert_with(|| {