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

+9-9
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

+47
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

+3-3
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

+8
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

+2-2
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

+1-1
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

+1-1
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

+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: `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

+1-1
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

+1-1
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");

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

+1-1
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-owned'
11+
// error-pattern:panicked at 'test-assert-owned'
1212

1313
fn main() {
1414
assert!(false, "test-assert-owned".to_string());

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

+1-1
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-static'
11+
// error-pattern:panicked at 'test-assert-static'
1212

1313
fn main() {
1414
assert!(false, "test-assert-static");

src/test/run-fail/by-value-self-objects-fail.rs

+1-1
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:explicit failure
11+
// error-pattern:explicit panic
1212

1313
trait Foo {
1414
fn foo(self, x: int);

src/test/run-fail/expr-fn-fail.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// error-pattern:explicit panic
1112

12-
13-
14-
// error-pattern:explicit failure
1513
fn f() -> ! { panic!() }
1614

1715
fn main() { f(); }

src/test/run-fail/expr-if-fail-fn.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// error-pattern:explicit panic
1112

12-
13-
14-
// error-pattern:explicit failure
1513
fn f() -> ! { panic!() }
1614

1715
fn g() -> int { let x = if true { f() } else { 10 }; return x; }

src/test/run-fail/expr-if-fail.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// error-pattern:explicit panic
1112

12-
13-
14-
// error-pattern:explicit failure
1513
fn main() { let _x = if false { 0i } else if true { panic!() } else { 10i }; }

src/test/run-fail/expr-match-fail-fn.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// error-pattern:explicit panic
1112

12-
13-
14-
// error-pattern:explicit failure
1513
fn f() -> ! { panic!() }
1614

1715
fn g() -> int { let x = match true { true => { f() } false => { 10 } }; return x; }

src/test/run-fail/expr-match-fail.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// error-pattern:explicit panic
1112

12-
13-
14-
// error-pattern:explicit failure
1513
fn main() { let _x = match true { false => { 0i } true => { panic!() } }; }

src/test/run-fail/fail-macro-any-wrapped.rs

+1-1
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 'Box<Any>'
11+
// error-pattern:panicked at 'Box<Any>'
1212

1313
fn main() {
1414
panic!(box 612_i64);

src/test/run-fail/fail-macro-any.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +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 'Box<Any>'
12-
11+
// error-pattern:panicked at 'Box<Any>'
1312

1413
fn main() {
1514
panic!(box 413i as Box<::std::any::Any+Send>);

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

+1-1
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 'explicit failure'
11+
// error-pattern:panicked at 'explicit panic'
1212

1313
fn main() {
1414
panic!();

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

+1-1
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-fail-fmt 42 rust'
11+
// error-pattern:panicked at 'test-fail-fmt 42 rust'
1212

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

src/test/run-fail/fail-macro-owned.rs

+1-1
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-fail-owned'
11+
// error-pattern:panicked at 'test-fail-owned'
1212

1313
fn main() {
1414
panic!("test-fail-owned");

src/test/run-fail/fail-macro-static.rs

+1-1
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-fail-static'
11+
// error-pattern:panicked at 'test-fail-static'
1212

1313
fn main() {
1414
panic!("test-fail-static");

src/test/run-fail/fail-non-utf8.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// Previously failed formating invalid utf8.
1313
// cc #16877
1414

15-
// error-pattern:failed at 'hello�'
15+
// error-pattern:panicked at 'hello�'
1616

1717
struct Foo;
1818
impl std::fmt::Show for Foo {

src/test/run-fail/fail-task-name-none.rs

+1-1
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:task '<unnamed>' failed at 'test'
11+
// error-pattern:task '<unnamed>' panicked at 'test'
1212

1313
use std::task;
1414

src/test/run-fail/fail-task-name-owned.rs

+1-1
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:task 'owned name' failed at 'test'
11+
// error-pattern:task 'owned name' panicked at 'test'
1212

1313
use std::task::TaskBuilder;
1414

src/test/run-fail/fail-task-name-send-str.rs

+1-1
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:task 'send name' failed at 'test'
11+
// error-pattern:task 'send name' panicked at 'test'
1212

1313
fn main() {
1414
let r: Result<int,_> =

0 commit comments

Comments
 (0)