diff options
| author | Steve Klabnik <steve@steveklabnik.com> | 2014-10-28 14:07:33 -0400 |
|---|---|---|
| committer | Steve Klabnik <steve@steveklabnik.com> | 2014-10-29 16:06:13 -0400 |
| commit | 6ac7fc73f5acfe30c698ea4f8bfc37b30473977e (patch) | |
| tree | a7b9c45aa38fbf458ea2afb6ddfc70ae782b1302 /src/libcore/panicking.rs | |
| parent | 7828c3dd2858d8f3a0448484d8093e22719dbda0 (diff) | |
| download | rust-6ac7fc73f5acfe30c698ea4f8bfc37b30473977e.tar.gz rust-6ac7fc73f5acfe30c698ea4f8bfc37b30473977e.zip | |
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
Diffstat (limited to 'src/libcore/panicking.rs')
| -rw-r--r-- | src/libcore/panicking.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/libcore/panicking.rs b/src/libcore/panicking.rs index cda21b6ecfa..62c9d907cb2 100644 --- a/src/libcore/panicking.rs +++ b/src/libcore/panicking.rs @@ -33,6 +33,49 @@ use fmt; use intrinsics; +// NOTE(stage0): remove after a snapshot +#[cfg(stage0)] +#[cold] #[inline(never)] // this is the slow path, always +#[lang="fail"] +pub fn panic(expr_file_line: &(&'static str, &'static str, uint)) -> ! { + let (expr, file, line) = *expr_file_line; + let ref file_line = (file, line); + format_args!(|args| -> () { + panic_fmt(args, file_line); + }, "{}", expr); + + unsafe { intrinsics::abort() } +} + +// NOTE(stage0): remove after a snapshot +#[cfg(stage0)] +#[cold] #[inline(never)] +#[lang="fail_bounds_check"] +fn panic_bounds_check(file_line: &(&'static str, uint), + index: uint, len: uint) -> ! { + format_args!(|args| -> () { + panic_fmt(args, file_line); + }, "index out of bounds: the len is {} but the index is {}", len, index); + unsafe { intrinsics::abort() } +} + +// NOTE(stage0): remove after a snapshot +#[cfg(stage0)] +#[cold] #[inline(never)] +pub fn panic_fmt(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! { + #[allow(ctypes)] + extern { + #[lang = "fail_fmt"] + fn panic_impl(fmt: &fmt::Arguments, file: &'static str, + line: uint) -> !; + + } + let (file, line) = *file_line; + unsafe { panic_impl(fmt, file, line) } +} + +// NOTE(stage0): remove cfg after a snapshot +#[cfg(not(stage0))] #[cold] #[inline(never)] // this is the slow path, always #[lang="panic"] 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)) -> ! { unsafe { intrinsics::abort() } } +// NOTE(stage0): remove cfg after a snapshot +#[cfg(not(stage0))] #[cold] #[inline(never)] #[lang="panic_bounds_check"] fn panic_bounds_check(file_line: &(&'static str, uint), @@ -55,6 +100,8 @@ fn panic_bounds_check(file_line: &(&'static str, uint), unsafe { intrinsics::abort() } } +// NOTE(stage0): remove cfg after a snapshot +#[cfg(not(stage0))] #[cold] #[inline(never)] pub fn panic_fmt(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! { #[allow(ctypes)] |
