From 1e01f7f470f1d79be710d546ab25426fcede59f9 Mon Sep 17 00:00:00 2001 From: Kevin Yap Date: Fri, 13 Feb 2015 19:59:53 -0800 Subject: Rename std::failure to std::panicking Closes #22306. --- src/libstd/failure.rs | 76 ---------------------------------------------- src/libstd/lib.rs | 2 +- src/libstd/old_io/stdio.rs | 2 +- src/libstd/panicking.rs | 76 ++++++++++++++++++++++++++++++++++++++++++++++ src/libstd/rt/unwind.rs | 6 ++-- 5 files changed, 81 insertions(+), 81 deletions(-) delete mode 100644 src/libstd/failure.rs create mode 100644 src/libstd/panicking.rs (limited to 'src/libstd') diff --git a/src/libstd/failure.rs b/src/libstd/failure.rs deleted file mode 100644 index c184d3f4661..00000000000 --- a/src/libstd/failure.rs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![unstable(feature = "std_misc")] - -use prelude::v1::*; - -use any::Any; -use cell::RefCell; -use old_io::IoResult; -use rt::{backtrace, unwind}; -use rt::util::{Stderr, Stdio}; -use thread::Thread; - -// Defined in this module instead of old_io::stdio so that the unwinding -thread_local! { - pub static LOCAL_STDERR: RefCell>> = { - RefCell::new(None) - } -} - -impl Writer for Stdio { - fn write_all(&mut self, bytes: &[u8]) -> IoResult<()> { - let _ = self.write_bytes(bytes); - Ok(()) - } -} - -pub fn on_fail(obj: &(Any+Send), file: &'static str, line: uint) { - let msg = match obj.downcast_ref::<&'static str>() { - Some(s) => *s, - None => match obj.downcast_ref::() { - Some(s) => &s[], - None => "Box", - } - }; - let mut err = Stderr; - let thread = Thread::current(); - let name = thread.name().unwrap_or(""); - let prev = LOCAL_STDERR.with(|s| s.borrow_mut().take()); - match prev { - Some(mut stderr) => { - // FIXME: what to do when the thread printing panics? - let _ = writeln!(stderr, - "thread '{}' panicked at '{}', {}:{}\n", - name, msg, file, line); - if backtrace::log_enabled() { - let _ = backtrace::write(&mut *stderr); - } - let mut s = Some(stderr); - LOCAL_STDERR.with(|slot| { - *slot.borrow_mut() = s.take(); - }); - } - None => { - let _ = writeln!(&mut err, "thread '{}' panicked at '{}', {}:{}", - name, msg, file, line); - if backtrace::log_enabled() { - let _ = backtrace::write(&mut err); - } - } - } - - // If this is a double panic, make sure that we printed a backtrace - // for this panic. - if unwind::panicking() && !backtrace::log_enabled() { - let _ = backtrace::write(&mut err); - } -} diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 83f0b7bc0e9..42eed5f4dbd 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -278,7 +278,7 @@ pub mod sync; #[path = "sys/common/mod.rs"] mod sys_common; pub mod rt; -mod failure; +mod panicking; // Documentation for primitive types diff --git a/src/libstd/old_io/stdio.rs b/src/libstd/old_io/stdio.rs index 8e55251d285..70cce1f7e76 100644 --- a/src/libstd/old_io/stdio.rs +++ b/src/libstd/old_io/stdio.rs @@ -30,7 +30,7 @@ use self::StdSource::*; use boxed::Box; use cell::RefCell; use clone::Clone; -use failure::LOCAL_STDERR; +use panicking::LOCAL_STDERR; use fmt; use old_io::{Reader, Writer, IoResult, IoError, OtherIoError, Buffer, standard_error, EndOfFile, LineBufferedWriter, BufferedReader}; diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs new file mode 100644 index 00000000000..e485c6a63c6 --- /dev/null +++ b/src/libstd/panicking.rs @@ -0,0 +1,76 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![unstable(feature = "std_misc")] + +use prelude::v1::*; + +use any::Any; +use cell::RefCell; +use old_io::IoResult; +use rt::{backtrace, unwind}; +use rt::util::{Stderr, Stdio}; +use thread::Thread; + +// Defined in this module instead of old_io::stdio so that the unwinding +thread_local! { + pub static LOCAL_STDERR: RefCell>> = { + RefCell::new(None) + } +} + +impl Writer for Stdio { + fn write_all(&mut self, bytes: &[u8]) -> IoResult<()> { + let _ = self.write_bytes(bytes); + Ok(()) + } +} + +pub fn on_panic(obj: &(Any+Send), file: &'static str, line: uint) { + let msg = match obj.downcast_ref::<&'static str>() { + Some(s) => *s, + None => match obj.downcast_ref::() { + Some(s) => &s[], + None => "Box", + } + }; + let mut err = Stderr; + let thread = Thread::current(); + let name = thread.name().unwrap_or(""); + let prev = LOCAL_STDERR.with(|s| s.borrow_mut().take()); + match prev { + Some(mut stderr) => { + // FIXME: what to do when the thread printing panics? + let _ = writeln!(stderr, + "thread '{}' panicked at '{}', {}:{}\n", + name, msg, file, line); + if backtrace::log_enabled() { + let _ = backtrace::write(&mut *stderr); + } + let mut s = Some(stderr); + LOCAL_STDERR.with(|slot| { + *slot.borrow_mut() = s.take(); + }); + } + None => { + let _ = writeln!(&mut err, "thread '{}' panicked at '{}', {}:{}", + name, msg, file, line); + if backtrace::log_enabled() { + let _ = backtrace::write(&mut err); + } + } + } + + // If this is a double panic, make sure that we printed a backtrace + // for this panic. + if unwind::panicking() && !backtrace::log_enabled() { + let _ = backtrace::write(&mut err); + } +} diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 659e787a9ff..464adadde62 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -62,7 +62,7 @@ use prelude::v1::*; use any::Any; use cell::Cell; use cmp; -use failure; +use panicking; use fmt; use intrinsics; use libc::c_void; @@ -534,10 +534,10 @@ pub fn begin_unwind(msg: M, file_line: &(&'static str, uint)) -> /// }` from ~1900/3700 (-O/no opts) to 180/590. #[inline(never)] #[cold] // this is the slow path, please never inline this fn begin_unwind_inner(msg: Box, file_line: &(&'static str, uint)) -> ! { - // Make sure the default failure handler is registered before we look at the + // Make sure the default panic handler is registered before we look at the // callbacks. static INIT: Once = ONCE_INIT; - INIT.call_once(|| unsafe { register(failure::on_fail); }); + INIT.call_once(|| unsafe { register(panicking::on_panic); }); // First, invoke call the user-defined callbacks triggered on thread panic. // -- cgit 1.4.1-3-g733a5