|
30 | 30 |
|
31 | 31 | #![allow(dead_code, missing_doc)]
|
32 | 32 |
|
33 |
| -use fmt; |
34 |
| -use intrinsics; |
| 33 | +pub use failure::internal::{fail, fail_fmt}; |
35 | 34 |
|
36 |
| -#[cold] #[inline(never)] // this is the slow path, always |
37 |
| -#[lang="fail"] |
38 |
| -pub fn fail(expr_file_line: &(&'static str, &'static str, uint)) -> ! { |
39 |
| - let (expr, file, line) = *expr_file_line; |
40 |
| - let ref file_line = (file, line); |
41 |
| - format_args!(|args| -> () { |
42 |
| - fail_fmt(args, file_line); |
43 |
| - }, "{}", expr); |
| 35 | +#[cfg(not(no_fail_fmt))] |
| 36 | +mod internal { |
| 37 | + use fmt; |
| 38 | + use intrinsics; |
44 | 39 |
|
45 |
| - unsafe { intrinsics::abort() } |
46 |
| -} |
| 40 | + #[cold] #[inline(never)] // this is the slow path, always |
| 41 | + #[lang="fail"] |
| 42 | + pub fn fail(expr_file_line: &(&'static str, &'static str, uint)) -> ! { |
| 43 | + let (expr, file, line) = *expr_file_line; |
| 44 | + let ref file_line = (file, line); |
| 45 | + format_args!(|args| -> () { |
| 46 | + fail_fmt(args, file_line); |
| 47 | + }, "{}", expr); |
| 48 | + |
| 49 | + unsafe { intrinsics::abort() } |
| 50 | + } |
| 51 | + |
| 52 | + #[cold] #[inline(never)] |
| 53 | + #[lang="fail_bounds_check"] |
| 54 | + fn fail_bounds_check(file_line: &(&'static str, uint), |
| 55 | + index: uint, len: uint) -> ! { |
| 56 | + format_args!(|args| -> () { |
| 57 | + fail_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 | + #[cold] #[inline(never)] |
| 63 | + pub fn fail_fmt(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! { |
| 64 | + #[allow(ctypes)] |
| 65 | + extern { |
| 66 | + #[lang = "fail_fmt"] |
| 67 | + fn fail_impl(fmt: &fmt::Arguments, file: &'static str, |
| 68 | + line: uint) -> !; |
| 69 | + } |
47 | 70 |
|
48 |
| -#[cold] #[inline(never)] |
49 |
| -#[lang="fail_bounds_check"] |
50 |
| -fn fail_bounds_check(file_line: &(&'static str, uint), |
51 |
| - index: uint, len: uint) -> ! { |
52 |
| - format_args!(|args| -> () { |
53 |
| - fail_fmt(args, file_line); |
54 |
| - }, "index out of bounds: the len is {} but the index is {}", len, index); |
55 |
| - unsafe { intrinsics::abort() } |
| 71 | + let (file, line) = *file_line; |
| 72 | + unsafe { fail_impl(fmt, file, line) } |
| 73 | + } |
56 | 74 | }
|
57 | 75 |
|
58 |
| -#[cold] #[inline(never)] |
59 |
| -pub fn fail_fmt(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! { |
60 |
| - #[allow(ctypes)] |
61 |
| - extern { |
62 |
| - #[lang = "fail_fmt"] |
63 |
| - fn fail_impl(fmt: &fmt::Arguments, file: &'static str, |
64 |
| - line: uint) -> !; |
| 76 | +#[cfg(no_fail_fmt)] |
| 77 | +mod internal { |
| 78 | + use fmt; |
| 79 | + use intrinsics; |
| 80 | + |
| 81 | + #[cold] #[inline(never)] // this is the slow path, always |
| 82 | + #[lang="fail"] |
| 83 | + pub fn fail(_expr_file_line: &(&'static str, &'static str, uint)) -> ! { |
| 84 | + unsafe { intrinsics::abort() } |
| 85 | + } |
| 86 | + |
| 87 | + #[cold] #[inline(never)] |
| 88 | + #[lang="fail_bounds_check"] |
| 89 | + fn fail_bounds_check(_file_line: &(&'static str, uint), |
| 90 | + _index: uint, _len: uint) -> ! { |
| 91 | + unsafe { intrinsics::abort() } |
| 92 | + } |
65 | 93 |
|
| 94 | + #[cold] #[inline(never)] |
| 95 | + pub fn fail_fmt(_fmt: &fmt::Arguments, _file_line: &(&'static str, uint)) -> ! { |
| 96 | + unsafe { intrinsics::abort() } |
66 | 97 | }
|
67 |
| - let (file, line) = *file_line; |
68 |
| - unsafe { fail_impl(fmt, file, line) } |
69 | 98 | }
|
0 commit comments