about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-11-13 06:12:10 +0000
committerbors <bors@rust-lang.org>2014-11-13 06:12:10 +0000
commite2cd4765fb51551ecdbbb59365b9e0b70eecd576 (patch)
tree1cfafb3e46c21f4bd9d765126daa048407180cc2 /src
parent6a62ad3e2998d516fea15ddf37d4bfcc9846f9b2 (diff)
parent837dd14de31bd4adc92d962559047e7b449c20a6 (diff)
downloadrust-e2cd4765fb51551ecdbbb59365b9e0b70eecd576.tar.gz
rust-e2cd4765fb51551ecdbbb59365b9e0b70eecd576.zip
auto merge of #18867 : michaelsproul/rust/unreachable-formatting, r=pcwalton
Closes #18842.
Diffstat (limited to 'src')
-rw-r--r--src/libstd/macros.rs10
-rw-r--r--src/test/run-fail/unreachable-fmt-msg.rs14
-rw-r--r--src/test/run-fail/unreachable-static-msg.rs12
-rw-r--r--src/test/run-fail/unreachable.rs (renamed from src/test/run-fail/unreachable-macro-fail.rs)0
4 files changed, 35 insertions, 1 deletions
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs
index d82147947de..0c91542e5eb 100644
--- a/src/libstd/macros.rs
+++ b/src/libstd/macros.rs
@@ -211,7 +211,15 @@ macro_rules! debug_assert_eq(
 /// ```
 #[macro_export]
 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
diff --git a/src/test/run-fail/unreachable-fmt-msg.rs b/src/test/run-fail/unreachable-fmt-msg.rs
new file mode 100644
index 00000000000..f005fa4476c
--- /dev/null
+++ b/src/test/run-fail/unreachable-fmt-msg.rs
@@ -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");
+}
diff --git a/src/test/run-fail/unreachable-static-msg.rs b/src/test/run-fail/unreachable-static-msg.rs
new file mode 100644
index 00000000000..25894a88541
--- /dev/null
+++ b/src/test/run-fail/unreachable-static-msg.rs
@@ -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") }
diff --git a/src/test/run-fail/unreachable-macro-fail.rs b/src/test/run-fail/unreachable.rs
index 07e05c6fed9..07e05c6fed9 100644
--- a/src/test/run-fail/unreachable-macro-fail.rs
+++ b/src/test/run-fail/unreachable.rs