Skip to content

Commit

Permalink
Defailbloat fail!(&'static str)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobba committed Sep 28, 2014
1 parent 9a68da7 commit 3b9732e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
11 changes: 5 additions & 6 deletions src/libcore/failure.rs
Expand Up @@ -33,6 +33,10 @@
use fmt;
use intrinsics;

// NOTE: remove after next snapshot
#[cfg(stage0)]
pub use self::fail_ as fail;

// NOTE: remove after next snapshot
#[cfg(stage0)]
#[cold] #[inline(never)] // this is the slow path, always
Expand All @@ -50,7 +54,7 @@ fn fail_(expr_file_line: &(&'static str, &'static str, uint)) -> ! {
#[cfg(not(stage0))]
#[cold] #[inline(never)] // this is the slow path, always
#[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 ref file_line = (file, line);
format_args!(|args| -> () {
Expand All @@ -70,11 +74,6 @@ fn fail_bounds_check(file_line: &(&'static str, uint),
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)]
pub fn fail_fmt(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
#[allow(ctypes)]
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/macros.rs
Expand Up @@ -17,8 +17,8 @@ macro_rules! fail(
fail!("{}", "explicit failure")
);
($msg:expr) => ({
static _FILE_LINE: (&'static str, uint) = (file!(), line!());
::core::failure::fail_str($msg, &_FILE_LINE)
static _MSG_FILE_LINE: (&'static str, &'static str, uint) = ($msg, file!(), line!());
::core::failure::fail(&_MSG_FILE_LINE)
});
($fmt:expr, $($arg:tt)*) => ({
// a closure can't have return type !, so we need a full
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/option.rs
Expand Up @@ -312,7 +312,7 @@ impl<T> Option<T> {
pub fn expect(self, msg: &str) -> T {
match self {
Some(val) => val,
None => fail!(msg),
None => fail!("{}", msg),
}
}

Expand Down

0 comments on commit 3b9732e

Please sign in to comment.