1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Failure support for libcore
13 #![allow(dead_code, missing_doc)]
16 use str::raw::c_str_to_static_slice;
18 // FIXME: Once std::fmt is in libcore, all of these functions should delegate
19 // to a common failure function with this signature:
22 // fn rust_unwind(f: &fmt::Arguments, file: &str, line: uint) -> !;
25 // Each of these functions can create a temporary fmt::Arguments
26 // structure to pass to this function.
28 #[cold] #[inline(never)] // this is the slow path, always
31 fn fail_(expr: *u8, file: *u8, line: uint) -> ! {
33 let expr = c_str_to_static_slice(expr as *i8);
34 let file = c_str_to_static_slice(file as *i8);
35 begin_unwind(expr, file, line)
40 #[lang="fail_bounds_check"]
42 fn fail_bounds_check(file: *u8, line: uint, index: uint, len: uint) -> ! {
44 extern { fn rust_fail_bounds_check(file: *u8, line: uint,
45 index: uint, len: uint,) -> !; }
46 unsafe { rust_fail_bounds_check(file, line, index, len) }
50 pub fn begin_unwind(msg: &str, file: &'static str, line: uint) -> ! {
52 extern { fn rust_begin_unwind(msg: &str, file: &'static str,
54 unsafe { rust_begin_unwind(msg, file, line) }