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.
13 /// Entry point of task panic, for details, see std::macros
17 panic!("explicit panic")
20 static _MSG_FILE_LINE: (&'static str, &'static str, uint) = ($msg, file!(), line!());
21 ::core::panicking::panic(&_MSG_FILE_LINE)
23 ($fmt:expr, $($arg:tt)*) => ({
24 // The leading _'s are to avoid dead code warnings if this is
25 // used inside a dead function. Just `#[allow(dead_code)]` is
26 // insufficient, since the user may have
27 // `#[forbid(dead_code)]` and which cannot be overridden.
28 static _FILE_LINE: (&'static str, uint) = (file!(), line!());
29 ::core::panicking::panic_fmt(format_args!($fmt, $($arg)*), &_FILE_LINE)
33 /// Runtime assertion, for details see std::macros
38 panic!(concat!("assertion failed: ", stringify!($cond)))
41 ($cond:expr, $($arg:tt)*) => (
48 /// Runtime assertion for equality, for details see std::macros
50 macro_rules! assert_eq {
51 ($cond1:expr, $cond2:expr) => ({
54 if c1 != c2 || c2 != c1 {
55 panic!("expressions not equal, left: {}, right: {}", c1, c2);
60 /// Runtime assertion for equality, only without `--cfg ndebug`
62 macro_rules! debug_assert_eq {
64 if cfg!(not(ndebug)) {
70 /// Runtime assertion, disableable at compile time with `--cfg ndebug`
72 macro_rules! debug_assert {
73 ($($arg:tt)*) => (if cfg!(not(ndebug)) { assert!($($arg)*); })
76 /// Short circuiting evaluation on Err
79 ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
82 /// Writing a formatted string into a writer
85 ($dst:expr, $($arg:tt)*) => ((&mut *$dst).write_fmt(format_args!($($arg)*)))
88 /// Writing a formatted string plus a newline into a writer
90 macro_rules! writeln {
91 ($dst:expr, $fmt:expr $($arg:tt)*) => (
92 write!($dst, concat!($fmt, "\n") $($arg)*)
97 macro_rules! unreachable { () => (panic!("unreachable code")) }