Skip to content

Commit

Permalink
Rename fail_ lang item to fail, closes #16114
Browse files Browse the repository at this point in the history
  • Loading branch information
fhahn committed Sep 24, 2014
1 parent 45f4081 commit 1c7d253
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/doc/guide-unsafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ Other features provided by lang items include:
`==`, `<`, dereferencing (`*`) and `+` (etc.) operators are all
marked with lang items; those specific four are `eq`, `ord`,
`deref`, and `add` respectively.
- stack unwinding and general failure; the `eh_personality`, `fail_`
- stack unwinding and general failure; the `eh_personality`, `fail`
and `fail_bounds_checks` lang items.
- the traits in `std::kinds` used to indicate types that satisfy
various kinds; lang items `send`, `sync` and `copy`.
Expand Down
17 changes: 16 additions & 1 deletion src/libcore/failure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
use fmt;
use intrinsics;

// NOTE: remove after next snapshot
#[cfg(stage0)]
#[cold] #[inline(never)] // this is the slow path, always
#[lang="fail_"]
fn fail_(expr_file_line: &(&'static str, &'static str, uint)) -> ! {
Expand All @@ -45,6 +47,19 @@ fn fail_(expr_file_line: &(&'static str, &'static str, uint)) -> ! {
unsafe { intrinsics::abort() }
}

#[cfg(not(stage0))]
#[cold] #[inline(never)] // this is the slow path, always
#[lang="fail"]
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| -> () {
fail_impl(args, file_line);
}, "{}", expr);

unsafe { intrinsics::abort() }
}

#[cold] #[inline(never)]
#[lang="fail_bounds_check"]
fn fail_bounds_check(file_line: &(&'static str, uint),
Expand All @@ -65,6 +80,7 @@ pub fn fail_impl(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
#[allow(ctypes)]
extern {

// NOTE: remove after next snapshot
#[cfg(stage0)]
#[lang = "begin_unwind"]
fn fail_impl(fmt: &fmt::Arguments, file: &'static str,
Expand All @@ -79,4 +95,3 @@ pub fn fail_impl(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
let (file, line) = *file_line;
unsafe { fail_impl(fmt, file, line) }
}

4 changes: 2 additions & 2 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ lets_do_this! {

StrEqFnLangItem, "str_eq", str_eq_fn;

// A number of failure-related lang items. The `fail_` item corresponds to
// A number of failure-related lang items. The `fail` item corresponds to
// divide-by-zero and various failure cases with `match`. The
// `fail_bounds_check` item is for indexing arrays.
//
Expand All @@ -273,7 +273,7 @@ lets_do_this! {
// defined to use it, but a final product is required to define it
// somewhere. Additionally, there are restrictions on crates that use a weak
// lang item, but do not have it defined.
FailFnLangItem, "fail_", fail_fn;
FailFnLangItem, "fail", fail_fn;
FailBoundsCheckFnLangItem, "fail_bounds_check", fail_bounds_check_fn;
FailFmtLangItem, "fail_fmt", fail_fmt;

Expand Down
10 changes: 4 additions & 6 deletions src/librustrt/unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,24 +488,22 @@ pub mod eabi {
}

// Entry point of failure from the libcore crate
#[cfg(not(test))]
#[cfg(not(stage0))]
#[cfg(not(test), not(stage0))]
#[lang = "fail_fmt"]
pub extern fn rust_begin_unwind1(msg: &fmt::Arguments,
pub extern fn rust_begin_unwind(msg: &fmt::Arguments,
file: &'static str, line: uint) -> ! {
begin_unwind_fmt(msg, &(file, line))
}

//
// Entry point of failure from the libcore crate
#[cfg(not(test))]
#[cfg(stage0)]
#[cfg(stage0, not(test))]
#[lang = "begin_unwind"]
pub extern fn rust_begin_unwind(msg: &fmt::Arguments,
file: &'static str, line: uint) -> ! {
begin_unwind_fmt(msg, &(file, line))
}


/// The entry point for unwinding with a formatted message.
///
/// This is designed to reduce the amount of code required at the call
Expand Down
2 changes: 1 addition & 1 deletion src/test/auxiliary/lang-item-public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#![no_std]
#![feature(lang_items)]

#[lang="fail_"]
#[lang="fail"]
fn fail(_: &(&'static str, &'static str, uint)) -> ! { loop {} }

#[lang = "stack_exhausted"]
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/lint-dead-code-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,5 @@ fn g() { h(); }
fn h() {}

// Similarly, lang items are live
#[lang="fail_"]
#[lang="fail"]
fn fail(_: *const u8, _: *const u8, _: uint) -> ! { loop {} }

0 comments on commit 1c7d253

Please sign in to comment.