diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-05-26 10:33:18 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-05-27 00:33:05 -0700 |
| commit | 5c1a70d49874ce3922af5cd3eeea7ae2dbc9db7e (patch) | |
| tree | bad348aeea3af5b9a50b2dfa07947e553634d8cd /src/libcore | |
| parent | 746d086f9322d24fa7b389dd911e204ca35012ae (diff) | |
rustc: Use rust strings for failure arguments
This avoids having to perform conversions from `*u8` to `&'static str` which can suck in a good deal of code. Closes #14442
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/failure.rs | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/libcore/failure.rs b/src/libcore/failure.rs index 003ebed6364..a53a380d737 100644 --- a/src/libcore/failure.rs +++ b/src/libcore/failure.rs @@ -28,13 +28,25 @@ #![allow(dead_code, missing_doc)] -#[cfg(not(test))] -use str::raw::c_str_to_static_slice; use fmt; +use intrinsics; +#[cfg(not(test), stage0)] +use str::raw::c_str_to_static_slice; + +#[cold] #[inline(never)] // this is the slow path, always +#[lang="fail_"] +#[cfg(not(test), not(stage0))] +fn fail_(expr: &'static str, file: &'static str, line: uint) -> ! { + format_args!(|args| -> () { + begin_unwind(args, file, line); + }, "{}", expr); + + unsafe { intrinsics::abort() } +} #[cold] #[inline(never)] // this is the slow path, always #[lang="fail_"] -#[cfg(not(test))] +#[cfg(not(test), stage0)] fn fail_(expr: *u8, file: *u8, line: uint) -> ! { unsafe { let expr = c_str_to_static_slice(expr as *i8); @@ -43,19 +55,30 @@ fn fail_(expr: *u8, file: *u8, line: uint) -> ! { begin_unwind(args, file, line); }, "{}", expr); - loop {} + intrinsics::abort() } } #[cold] #[lang="fail_bounds_check"] -#[cfg(not(test))] +#[cfg(not(test), not(stage0))] +fn fail_bounds_check(file: &'static str, line: uint, + index: uint, len: uint) -> ! { + format_args!(|args| -> () { + begin_unwind(args, file, line); + }, "index out of bounds: the len is {} but the index is {}", len, index); + unsafe { intrinsics::abort() } +} + +#[cold] +#[lang="fail_bounds_check"] +#[cfg(not(test), stage0)] fn fail_bounds_check(file: *u8, line: uint, index: uint, len: uint) -> ! { let file = unsafe { c_str_to_static_slice(file as *i8) }; format_args!(|args| -> () { begin_unwind(args, file, line); }, "index out of bounds: the len is {} but the index is {}", len, index); - loop {} + unsafe { intrinsics::abort() } } #[cold] |
