about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-08-11 09:01:06 +0000
committerbors <bors@rust-lang.org>2014-08-11 09:01:06 +0000
commit5e720f0e5453e7b113f313df7827f3ad0a6dbe46 (patch)
tree3886a48dc274a6598a4ed7fd4354e92c5e614143 /src/libstd
parent9c772cd391034ad29a444e748708df5a0bfff0a2 (diff)
parent07aadc2e8b1923b28595393922a816e46d3903f4 (diff)
downloadrust-5e720f0e5453e7b113f313df7827f3ad0a6dbe46.tar.gz
rust-5e720f0e5453e7b113f313df7827f3ad0a6dbe46.zip
auto merge of #16196 : huonw/rust/fail-dead-code, r=alexcrichton
The fail macro defines some function/static items internally, which got
a dead_code warning when `fail!()` is used inside a dead function. This
is ugly and unnecessarily reveals implementation details, so the
warnings can be squashed.

Fixes #16192.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/macros.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs
index f2d7fb0cea6..85e614ab47e 100644
--- a/src/libstd/macros.rs
+++ b/src/libstd/macros.rs
@@ -43,8 +43,8 @@ macro_rules! fail(
     });
     ($msg:expr) => ({
         // static requires less code at runtime, more constant data
-        static FILE_LINE: (&'static str, uint) = (file!(), line!());
-        ::std::rt::begin_unwind($msg, &FILE_LINE)
+        static _FILE_LINE: (&'static str, uint) = (file!(), line!());
+        ::std::rt::begin_unwind($msg, &_FILE_LINE)
     });
     ($fmt:expr, $($arg:tt)*) => ({
         // a closure can't have return type !, so we need a full
@@ -58,12 +58,17 @@ macro_rules! fail(
         // because it's just a tiny wrapper. Small wins (156K to 149K in size)
         // were seen when forcing this to be inlined, and that number just goes
         // up with the number of calls to fail!()
+        //
+        // The leading _'s are to avoid dead code warnings if this is
+        // used inside a dead function. Just `#[allow(dead_code)]` is
+        // insufficient, since the user may have
+        // `#[forbid(dead_code)]` and which cannot be overridden.
         #[inline(always)]
-        fn run_fmt(fmt: &::std::fmt::Arguments) -> ! {
-            static FILE_LINE: (&'static str, uint) = (file!(), line!());
-            ::std::rt::begin_unwind_fmt(fmt, &FILE_LINE)
+        fn _run_fmt(fmt: &::std::fmt::Arguments) -> ! {
+            static _FILE_LINE: (&'static str, uint) = (file!(), line!());
+            ::std::rt::begin_unwind_fmt(fmt, &_FILE_LINE)
         }
-        format_args!(run_fmt, $fmt, $($arg)*)
+        format_args!(_run_fmt, $fmt, $($arg)*)
     });
 )