parent
40fb87d40f
commit
837dd14de3
4 changed files with 35 additions and 1 deletions
|
@ -211,7 +211,15 @@ macro_rules! debug_assert_eq(
|
||||||
/// ```
|
/// ```
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! unreachable(
|
macro_rules! unreachable(
|
||||||
() => (panic!("internal error: entered unreachable code"))
|
() => ({
|
||||||
|
panic!("internal error: entered unreachable code")
|
||||||
|
});
|
||||||
|
($msg:expr) => ({
|
||||||
|
unreachable!("{}", $msg)
|
||||||
|
});
|
||||||
|
($fmt:expr, $($arg:tt)*) => ({
|
||||||
|
panic!(concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
|
||||||
|
});
|
||||||
)
|
)
|
||||||
|
|
||||||
/// A standardised placeholder for marking unfinished code. It panics with the
|
/// A standardised placeholder for marking unfinished code. It panics with the
|
||||||
|
|
14
src/test/run-fail/unreachable-fmt-msg.rs
Normal file
14
src/test/run-fail/unreachable-fmt-msg.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// error-pattern:internal error: entered unreachable code: 6 is not prime
|
||||||
|
fn main() {
|
||||||
|
unreachable!("{} is not {}", 6u32, "prime");
|
||||||
|
}
|
12
src/test/run-fail/unreachable-static-msg.rs
Normal file
12
src/test/run-fail/unreachable-static-msg.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// error-pattern:internal error: entered unreachable code: uhoh
|
||||||
|
fn main() { unreachable!("uhoh") }
|
Loading…
Add table
Add a link
Reference in a new issue