Skip to content

Commit 6ac7fc7

Browse files
committed
Update infrastructure for fail -> panic
This includes updating the language items and marking what needs to change after a snapshot. If you do not use the standard library, the language items you need to implement have changed. For example: ```rust #[lang = "fail_fmt"] fn fail_fmt() -> ! { loop {} } ``` is now ```rust #[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} } ``` Related, lesser-implemented language items `fail` and `fail_bounds_check` have become `panic` and `panic_bounds_check`, as well. These are implemented by `libcore`, so it is unlikely (though possible!) that these two renamings will affect you. [breaking-change] Fix test suite
1 parent 7828c3d commit 6ac7fc7

40 files changed

+104
-60
lines changed

src/doc/guide-unsafe.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ fn start(_argc: int, _argv: *const *const u8) -> int {
462462
// provided by libstd.
463463
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
464464
#[lang = "eh_personality"] extern fn eh_personality() {}
465-
#[lang = "fail_fmt"] fn fail_fmt() -> ! { loop {} }
465+
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }
466466
# // fn main() {} tricked you, rustdoc!
467467
```
468468

@@ -485,7 +485,7 @@ pub extern fn main(argc: int, argv: *const *const u8) -> int {
485485
486486
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
487487
#[lang = "eh_personality"] extern fn eh_personality() {}
488-
#[lang = "fail_fmt"] fn fail_fmt() -> ! { loop {} }
488+
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }
489489
# // fn main() {} tricked you, rustdoc!
490490
```
491491

@@ -505,7 +505,7 @@ failure mechanisms of the compiler. This is often mapped to GCC's
505505
personality function (see the
506506
[libstd implementation](std/rt/unwind/index.html) for more
507507
information), but crates which do not trigger a panic can be assured
508-
that this function is never called. The final function, `fail_fmt`, is
508+
that this function is never called. The final function, `panic_fmt`, is
509509
also used by the failure mechanisms of the compiler.
510510

511511
## Using libcore
@@ -565,8 +565,8 @@ pub extern fn dot_product(a: *const u32, a_len: u32,
565565
return ret;
566566
}
567567
568-
#[lang = "fail_fmt"]
569-
extern fn fail_fmt(args: &core::fmt::Arguments,
568+
#[lang = "panic_fmt"]
569+
extern fn panic_fmt(args: &core::fmt::Arguments,
570570
file: &str,
571571
line: uint) -> ! {
572572
loop {}
@@ -579,9 +579,9 @@ extern fn fail_fmt(args: &core::fmt::Arguments,
579579
```
580580

581581
Note that there is one extra lang item here which differs from the examples
582-
above, `fail_fmt`. This must be defined by consumers of libcore because the
583-
core library declares failure, but it does not define it. The `fail_fmt`
584-
lang item is this crate's definition of failure, and it must be guaranteed to
582+
above, `panic_fmt`. This must be defined by consumers of libcore because the
583+
core library declares panics, but it does not define it. The `panic_fmt`
584+
lang item is this crate's definition of panic, and it must be guaranteed to
585585
never return.
586586

587587
As can be seen in this example, the core library is intended to provide the
@@ -686,7 +686,7 @@ fn main(argc: int, argv: *const *const u8) -> int {
686686
687687
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
688688
#[lang = "eh_personality"] extern fn eh_personality() {}
689-
#[lang = "fail_fmt"] fn fail_fmt() -> ! { loop {} }
689+
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }
690690
```
691691

692692
Note the use of `abort`: the `exchange_malloc` lang item is assumed to

src/libcore/panicking.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,49 @@
3333
use fmt;
3434
use intrinsics;
3535

36+
// NOTE(stage0): remove after a snapshot
37+
#[cfg(stage0)]
38+
#[cold] #[inline(never)] // this is the slow path, always
39+
#[lang="fail"]
40+
pub fn panic(expr_file_line: &(&'static str, &'static str, uint)) -> ! {
41+
let (expr, file, line) = *expr_file_line;
42+
let ref file_line = (file, line);
43+
format_args!(|args| -> () {
44+
panic_fmt(args, file_line);
45+
}, "{}", expr);
46+
47+
unsafe { intrinsics::abort() }
48+
}
49+
50+
// NOTE(stage0): remove after a snapshot
51+
#[cfg(stage0)]
52+
#[cold] #[inline(never)]
53+
#[lang="fail_bounds_check"]
54+
fn panic_bounds_check(file_line: &(&'static str, uint),
55+
index: uint, len: uint) -> ! {
56+
format_args!(|args| -> () {
57+
panic_fmt(args, file_line);
58+
}, "index out of bounds: the len is {} but the index is {}", len, index);
59+
unsafe { intrinsics::abort() }
60+
}
61+
62+
// NOTE(stage0): remove after a snapshot
63+
#[cfg(stage0)]
64+
#[cold] #[inline(never)]
65+
pub fn panic_fmt(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
66+
#[allow(ctypes)]
67+
extern {
68+
#[lang = "fail_fmt"]
69+
fn panic_impl(fmt: &fmt::Arguments, file: &'static str,
70+
line: uint) -> !;
71+
72+
}
73+
let (file, line) = *file_line;
74+
unsafe { panic_impl(fmt, file, line) }
75+
}
76+
77+
// NOTE(stage0): remove cfg after a snapshot
78+
#[cfg(not(stage0))]
3679
#[cold] #[inline(never)] // this is the slow path, always
3780
#[lang="panic"]
3881
pub fn panic(expr_file_line: &(&'static str, &'static str, uint)) -> ! {
@@ -45,6 +88,8 @@ pub fn panic(expr_file_line: &(&'static str, &'static str, uint)) -> ! {
4588
unsafe { intrinsics::abort() }
4689
}
4790

91+
// NOTE(stage0): remove cfg after a snapshot
92+
#[cfg(not(stage0))]
4893
#[cold] #[inline(never)]
4994
#[lang="panic_bounds_check"]
5095
fn panic_bounds_check(file_line: &(&'static str, uint),
@@ -55,6 +100,8 @@ fn panic_bounds_check(file_line: &(&'static str, uint),
55100
unsafe { intrinsics::abort() }
56101
}
57102

103+
// NOTE(stage0): remove cfg after a snapshot
104+
#[cfg(not(stage0))]
58105
#[cold] #[inline(never)]
59106
pub fn panic_fmt(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
60107
#[allow(ctypes)]

src/librustc/middle/trans/controlflow.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use llvm::*;
1212
use driver::config::FullDebugInfo;
1313
use middle::def;
14-
use middle::lang_items::{FailFnLangItem, FailBoundsCheckFnLangItem};
14+
use middle::lang_items::{PanicFnLangItem, PanicBoundsCheckFnLangItem};
1515
use middle::trans::_match;
1616
use middle::trans::adt;
1717
use middle::trans::base::*;
@@ -498,7 +498,7 @@ pub fn trans_fail<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
498498
let expr_file_line_const = C_struct(ccx, &[v_str, filename, line], false);
499499
let expr_file_line = consts::const_addr_of(ccx, expr_file_line_const, ast::MutImmutable);
500500
let args = vec!(expr_file_line);
501-
let did = langcall(bcx, Some(sp), "", FailFnLangItem);
501+
let did = langcall(bcx, Some(sp), "", PanicFnLangItem);
502502
let bcx = callee::trans_lang_call(bcx,
503503
did,
504504
args.as_slice(),
@@ -525,7 +525,7 @@ pub fn trans_fail_bounds_check<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
525525
let file_line_const = C_struct(ccx, &[filename, line], false);
526526
let file_line = consts::const_addr_of(ccx, file_line_const, ast::MutImmutable);
527527
let args = vec!(file_line, index, len);
528-
let did = langcall(bcx, Some(sp), "", FailBoundsCheckFnLangItem);
528+
let did = langcall(bcx, Some(sp), "", PanicBoundsCheckFnLangItem);
529529
let bcx = callee::trans_lang_call(bcx,
530530
did,
531531
args.as_slice(),

src/librustrt/unwind.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,14 @@ pub extern fn rust_begin_unwind(msg: &fmt::Arguments,
497497
begin_unwind_fmt(msg, &(file, line))
498498
}
499499

500+
// NOTE(stage0): remove after a snapshot
501+
#[cfg(not(test))]
502+
#[lang = "fail_fmt"]
503+
pub extern fn rust_fail_begin_unwind(msg: &fmt::Arguments,
504+
file: &'static str, line: uint) -> ! {
505+
rust_begin_unwind(msg, file, line)
506+
}
507+
500508
/// The entry point for unwinding with a formatted message.
501509
///
502510
/// This is designed to reduce the amount of code required at the call

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#[lang="sized"]
1515
pub trait Sized for Sized? {}
1616

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

2020
#[lang = "stack_exhausted"]
2121
extern fn stack_exhausted() {}

src/test/compile-fail/binop-fail-3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
fn foo() -> ! { fail!("quux"); }
11+
fn foo() -> ! { panic!("quux"); }
1212
fn main() {
1313
foo() //~ ERROR the type of this value must be known in this context
1414
==

src/test/compile-fail/issue-5500.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
&fail!()
12+
&panic!()
1313
//~^ ERROR mismatched types: expected `()`, found `&<generic #2>` (expected (), found &-ptr)
1414
}

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

Lines changed: 1 addition & 1 deletion
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: `fail_fmt`
12+
// error-pattern: language item required, but not found: `panic_fmt`
1313
// error-pattern: language item required, but not found: `stack_exhausted`
1414
// error-pattern: language item required, but not found: `eh_personality`
1515

src/test/run-fail/assert-macro-explicit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:failed at 'assertion failed: false'
11+
// error-pattern:panicked at 'assertion failed: false'
1212

1313
fn main() {
1414
assert!(false);

src/test/run-fail/assert-macro-fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:failed at 'test-assert-fmt 42 rust'
11+
// error-pattern:panicked at 'test-assert-fmt 42 rust'
1212

1313
fn main() {
1414
assert!(false, "test-assert-fmt {} {}", 42i, "rust");

0 commit comments

Comments
 (0)