Defailbloat fail!(&'static str)

This commit is contained in:
Tobba 2014-09-28 02:00:13 +02:00
parent 9a68da7401
commit 3b9732eae7
3 changed files with 8 additions and 9 deletions

View File

@ -33,6 +33,10 @@
use fmt; use fmt;
use intrinsics; use intrinsics;
// NOTE: remove after next snapshot
#[cfg(stage0)]
pub use self::fail_ as fail;
// NOTE: remove after next snapshot // NOTE: remove after next snapshot
#[cfg(stage0)] #[cfg(stage0)]
#[cold] #[inline(never)] // this is the slow path, always #[cold] #[inline(never)] // this is the slow path, always
@ -50,7 +54,7 @@ fn fail_(expr_file_line: &(&'static str, &'static str, uint)) -> ! {
#[cfg(not(stage0))] #[cfg(not(stage0))]
#[cold] #[inline(never)] // this is the slow path, always #[cold] #[inline(never)] // this is the slow path, always
#[lang="fail"] #[lang="fail"]
fn fail(expr_file_line: &(&'static str, &'static str, uint)) -> ! { pub fn fail(expr_file_line: &(&'static str, &'static str, uint)) -> ! {
let (expr, file, line) = *expr_file_line; let (expr, file, line) = *expr_file_line;
let ref file_line = (file, line); let ref file_line = (file, line);
format_args!(|args| -> () { format_args!(|args| -> () {
@ -70,11 +74,6 @@ fn fail_bounds_check(file_line: &(&'static str, uint),
unsafe { intrinsics::abort() } unsafe { intrinsics::abort() }
} }
#[cold] #[inline(never)]
pub fn fail_str(msg: &str, file: &(&'static str, uint)) -> ! {
format_args!(|fmt| fail_fmt(fmt, file), "{}", msg)
}
#[cold] #[inline(never)] #[cold] #[inline(never)]
pub fn fail_fmt(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! { pub fn fail_fmt(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
#[allow(ctypes)] #[allow(ctypes)]

View File

@ -17,8 +17,8 @@ macro_rules! fail(
fail!("{}", "explicit failure") fail!("{}", "explicit failure")
); );
($msg:expr) => ({ ($msg:expr) => ({
static _FILE_LINE: (&'static str, uint) = (file!(), line!()); static _MSG_FILE_LINE: (&'static str, &'static str, uint) = ($msg, file!(), line!());
::core::failure::fail_str($msg, &_FILE_LINE) ::core::failure::fail(&_MSG_FILE_LINE)
}); });
($fmt:expr, $($arg:tt)*) => ({ ($fmt:expr, $($arg:tt)*) => ({
// a closure can't have return type !, so we need a full // a closure can't have return type !, so we need a full

View File

@ -312,7 +312,7 @@ impl<T> Option<T> {
pub fn expect(self, msg: &str) -> T { pub fn expect(self, msg: &str) -> T {
match self { match self {
Some(val) => val, Some(val) => val,
None => fail!(msg), None => fail!("{}", msg),
} }
} }