Skip to content

Commit 9ff3081

Browse files
committed
auto merge of #17428 : fhahn/rust/issue-16114-rename-begin-unwind-2, r=alexcrichton
This is a PR for #16114 and includes to following things: * Rename `begin_unwind` lang item to `fail_fmt` * Rename `core::failure::begin_unwind` to `fail_impl` * Rename `fail_` lang item to `fail`
2 parents 5e13d3a + c8b767d commit 9ff3081

File tree

9 files changed

+56
-24
lines changed

9 files changed

+56
-24
lines changed

src/doc/guide-unsafe.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,8 @@ pub extern fn dot_product(a: *const u32, a_len: u32,
573573
return ret;
574574
}
575575
576-
#[lang = "begin_unwind"]
577-
extern fn begin_unwind(args: &core::fmt::Arguments,
576+
#[lang = "fail_fmt"]
577+
extern fn fail_fmt(args: &core::fmt::Arguments,
578578
file: &str,
579579
line: uint) -> ! {
580580
loop {}
@@ -587,8 +587,8 @@ extern fn begin_unwind(args: &core::fmt::Arguments,
587587
```
588588

589589
Note that there is one extra lang item here which differs from the examples
590-
above, `begin_unwind`. This must be defined by consumers of libcore because the
591-
core library declares failure, but it does not define it. The `begin_unwind`
590+
above, `fail_fmt`. This must be defined by consumers of libcore because the
591+
core library declares failure, but it does not define it. The `fail_fmt`
592592
lang item is this crate's definition of failure, and it must be guaranteed to
593593
never return.
594594

@@ -706,7 +706,7 @@ Other features provided by lang items include:
706706
`==`, `<`, dereferencing (`*`) and `+` (etc.) operators are all
707707
marked with lang items; those specific four are `eq`, `ord`,
708708
`deref`, and `add` respectively.
709-
- stack unwinding and general failure; the `eh_personality`, `fail_`
709+
- stack unwinding and general failure; the `eh_personality`, `fail`
710710
and `fail_bounds_checks` lang items.
711711
- the traits in `std::kinds` used to indicate types that satisfy
712712
various kinds; lang items `send`, `sync` and `copy`.

src/libcore/failure.rs

+32-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
//! interface for failure is:
1717
//!
1818
//! ```ignore
19-
//! fn begin_unwind(fmt: &fmt::Arguments, &(&'static str, uint)) -> !;
19+
//! fn fail_impl(fmt: &fmt::Arguments, &(&'static str, uint)) -> !;
2020
//! ```
2121
//!
2222
//! This definition allows for failing with any general message, but it does not
@@ -33,13 +33,28 @@
3333
use fmt;
3434
use intrinsics;
3535

36+
// NOTE: remove after next snapshot
37+
#[cfg(stage0)]
3638
#[cold] #[inline(never)] // this is the slow path, always
3739
#[lang="fail_"]
3840
fn fail_(expr_file_line: &(&'static str, &'static str, uint)) -> ! {
3941
let (expr, file, line) = *expr_file_line;
4042
let ref file_line = (file, line);
4143
format_args!(|args| -> () {
42-
begin_unwind(args, file_line);
44+
fail_fmt(args, file_line);
45+
}, "{}", expr);
46+
47+
unsafe { intrinsics::abort() }
48+
}
49+
50+
#[cfg(not(stage0))]
51+
#[cold] #[inline(never)] // this is the slow path, always
52+
#[lang="fail"]
53+
fn fail(expr_file_line: &(&'static str, &'static str, uint)) -> ! {
54+
let (expr, file, line) = *expr_file_line;
55+
let ref file_line = (file, line);
56+
format_args!(|args| -> () {
57+
fail_fmt(args, file_line);
4358
}, "{}", expr);
4459

4560
unsafe { intrinsics::abort() }
@@ -50,25 +65,33 @@ fn fail_(expr_file_line: &(&'static str, &'static str, uint)) -> ! {
5065
fn fail_bounds_check(file_line: &(&'static str, uint),
5166
index: uint, len: uint) -> ! {
5267
format_args!(|args| -> () {
53-
begin_unwind(args, file_line);
68+
fail_fmt(args, file_line);
5469
}, "index out of bounds: the len is {} but the index is {}", len, index);
5570
unsafe { intrinsics::abort() }
5671
}
5772

5873
#[cold] #[inline(never)]
59-
pub fn begin_unwind_string(msg: &str, file: &(&'static str, uint)) -> ! {
60-
format_args!(|fmt| begin_unwind(fmt, file), "{}", msg)
74+
pub fn fail_str(msg: &str, file: &(&'static str, uint)) -> ! {
75+
format_args!(|fmt| fail_fmt(fmt, file), "{}", msg)
6176
}
6277

6378
#[cold] #[inline(never)]
64-
pub fn begin_unwind(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
79+
pub fn fail_fmt(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
6580
#[allow(ctypes)]
6681
extern {
82+
83+
// NOTE: remove after next snapshot
84+
#[cfg(stage0)]
6785
#[lang = "begin_unwind"]
68-
fn begin_unwind(fmt: &fmt::Arguments, file: &'static str,
86+
fn fail_impl(fmt: &fmt::Arguments, file: &'static str,
6987
line: uint) -> !;
88+
89+
#[cfg(not(stage0))]
90+
#[lang = "fail_fmt"]
91+
fn fail_impl(fmt: &fmt::Arguments, file: &'static str,
92+
line: uint) -> !;
93+
7094
}
7195
let (file, line) = *file_line;
72-
unsafe { begin_unwind(fmt, file, line) }
96+
unsafe { fail_impl(fmt, file, line) }
7397
}
74-

src/libcore/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ macro_rules! fail(
1818
);
1919
($msg:expr) => ({
2020
static _FILE_LINE: (&'static str, uint) = (file!(), line!());
21-
::core::failure::begin_unwind_string($msg, &_FILE_LINE)
21+
::core::failure::fail_str($msg, &_FILE_LINE)
2222
});
2323
($fmt:expr, $($arg:tt)*) => ({
2424
// a closure can't have return type !, so we need a full
@@ -40,7 +40,7 @@ macro_rules! fail(
4040
#[inline(always)]
4141
fn _run_fmt(fmt: &::std::fmt::Arguments) -> ! {
4242
static _FILE_LINE: (&'static str, uint) = (file!(), line!());
43-
::core::failure::begin_unwind(fmt, &_FILE_LINE)
43+
::core::failure::fail_fmt(fmt, &_FILE_LINE)
4444
}
4545
format_args!(_run_fmt, $fmt, $($arg)*)
4646
});

src/librustc/middle/lang_items.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ lets_do_this! {
264264

265265
StrEqFnLangItem, "str_eq", str_eq_fn;
266266

267-
// A number of failure-related lang items. The `fail_` item corresponds to
267+
// A number of failure-related lang items. The `fail` item corresponds to
268268
// divide-by-zero and various failure cases with `match`. The
269269
// `fail_bounds_check` item is for indexing arrays.
270270
//
@@ -273,9 +273,9 @@ lets_do_this! {
273273
// defined to use it, but a final product is required to define it
274274
// somewhere. Additionally, there are restrictions on crates that use a weak
275275
// lang item, but do not have it defined.
276-
FailFnLangItem, "fail_", fail_fn;
276+
FailFnLangItem, "fail", fail_fn;
277277
FailBoundsCheckFnLangItem, "fail_bounds_check", fail_bounds_check_fn;
278-
BeginUnwindLangItem, "begin_unwind", begin_unwind;
278+
FailFmtLangItem, "fail_fmt", fail_fmt;
279279

280280
ExchangeMallocFnLangItem, "exchange_malloc", exchange_malloc_fn;
281281
ExchangeFreeFnLangItem, "exchange_free", exchange_free_fn;

src/librustc/middle/weak_lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'a, 'v> Visitor<'v> for Context<'a> {
118118
) )
119119

120120
weak_lang_items!(
121-
begin_unwind, BeginUnwindLangItem, rust_begin_unwind;
121+
fail_fmt, FailFmtLangItem, rust_begin_unwind;
122122
stack_exhausted, StackExhaustedLangItem, rust_stack_exhausted;
123123
eh_personality, EhPersonalityLangItem, rust_eh_personality;
124124
)

src/librustrt/unwind.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,16 @@ pub mod eabi {
488488
}
489489

490490
// Entry point of failure from the libcore crate
491-
#[cfg(not(test))]
491+
#[cfg(not(test), not(stage0))]
492+
#[lang = "fail_fmt"]
493+
pub extern fn rust_begin_unwind(msg: &fmt::Arguments,
494+
file: &'static str, line: uint) -> ! {
495+
begin_unwind_fmt(msg, &(file, line))
496+
}
497+
498+
//
499+
// Entry point of failure from the libcore crate
500+
#[cfg(stage0, not(test))]
492501
#[lang = "begin_unwind"]
493502
pub extern fn rust_begin_unwind(msg: &fmt::Arguments,
494503
file: &'static str, line: uint) -> ! {

src/test/auxiliary/lang-item-public.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#![no_std]
1212
#![feature(lang_items)]
1313

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

1717
#[lang = "stack_exhausted"]

src/test/compile-fail/lint-dead-code-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,5 @@ fn g() { h(); }
108108
fn h() {}
109109

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

src/test/compile-fail/weak-lang-item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
// aux-build:weak-lang-items.rs
12-
// error-pattern: language item required, but not found: `begin_unwind`
12+
// error-pattern: language item required, but not found: `fail_fmt`
1313
// error-pattern: language item required, but not found: `stack_exhausted`
1414
// error-pattern: language item required, but not found: `eh_personality`
1515

0 commit comments

Comments
 (0)