about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLzu Tao <taolzu@gmail.com>2020-06-15 14:17:58 +0000
committerLzu Tao <taolzu@gmail.com>2020-06-15 14:17:58 +0000
commitfe7456ce94b8edd549176d004a4435e1132c9c36 (patch)
tree746cdbef2ecf8d4a5adffa3dc0c72f874f627fc6 /src
parent64a6de25eaa4ec1a251862d81392bc9e22704c21 (diff)
downloadrust-fe7456ce94b8edd549176d004a4435e1132c9c36.tar.gz
rust-fe7456ce94b8edd549176d004a4435e1132c9c36.zip
Use track caller for bug! macro
Diffstat (limited to 'src')
-rw-r--r--src/librustc_middle/macros.rs18
-rw-r--r--src/librustc_middle/util/bug.rs21
2 files changed, 20 insertions, 19 deletions
diff --git a/src/librustc_middle/macros.rs b/src/librustc_middle/macros.rs
index 88ddd96eec8..a5482b7bdcf 100644
--- a/src/librustc_middle/macros.rs
+++ b/src/librustc_middle/macros.rs
@@ -1,16 +1,20 @@
 #[macro_export]
 macro_rules! bug {
-    () => ( bug!("impossible case reached") );
-    ($($message:tt)*) => ({
-        $crate::util::bug::bug_fmt(file!(), line!(), format_args!($($message)*))
-    })
+    () => ( $crate::bug!("impossible case reached") );
+    ($msg:expr) => ({ $crate::util::bug::bug_fmt(::std::format_args!($msg)) });
+    ($msg:expr,) => ({ $crate::bug!($msg) });
+    ($fmt:expr, $($arg:tt)+) => ({
+        $crate::util::bug::bug_fmt(::std::format_args!($fmt, $($arg)+))
+    });
 }
 
 #[macro_export]
 macro_rules! span_bug {
-    ($span:expr, $($message:tt)*) => ({
-        $crate::util::bug::span_bug_fmt(file!(), line!(), $span, format_args!($($message)*))
-    })
+    ($span:expr, $msg:expr) => ({ $crate::util::bug::span_bug_fmt($span, ::std::format_args!($msg)) });
+    ($span:expr, $msg:expr,) => ({ $crate::span_bug!($span, $msg) });
+    ($span:expr, $fmt:expr, $($arg:tt)+) => ({
+        $crate::util::bug::span_bug_fmt($span, ::std::format_args!($fmt, $($arg)+))
+    });
 }
 
 ///////////////////////////////////////////////////////////////////////////
diff --git a/src/librustc_middle/util/bug.rs b/src/librustc_middle/util/bug.rs
index 54cd8a29f94..9c3a97d8332 100644
--- a/src/librustc_middle/util/bug.rs
+++ b/src/librustc_middle/util/bug.rs
@@ -3,34 +3,31 @@
 use crate::ty::{tls, TyCtxt};
 use rustc_span::{MultiSpan, Span};
 use std::fmt;
+use std::panic::Location;
 
 #[cold]
 #[inline(never)]
-pub fn bug_fmt(file: &'static str, line: u32, args: fmt::Arguments<'_>) -> ! {
+#[track_caller]
+pub fn bug_fmt(args: fmt::Arguments<'_>) -> ! {
     // this wrapper mostly exists so I don't have to write a fully
     // qualified path of None::<Span> inside the bug!() macro definition
-    opt_span_bug_fmt(file, line, None::<Span>, args);
+    opt_span_bug_fmt(None::<Span>, args, Location::caller());
 }
 
 #[cold]
 #[inline(never)]
-pub fn span_bug_fmt<S: Into<MultiSpan>>(
-    file: &'static str,
-    line: u32,
-    span: S,
-    args: fmt::Arguments<'_>,
-) -> ! {
-    opt_span_bug_fmt(file, line, Some(span), args);
+#[track_caller]
+pub fn span_bug_fmt<S: Into<MultiSpan>>(span: S, args: fmt::Arguments<'_>) -> ! {
+    opt_span_bug_fmt(Some(span), args, Location::caller());
 }
 
 fn opt_span_bug_fmt<S: Into<MultiSpan>>(
-    file: &'static str,
-    line: u32,
     span: Option<S>,
     args: fmt::Arguments<'_>,
+    location: &Location<'_>,
 ) -> ! {
     tls::with_opt(move |tcx| {
-        let msg = format!("{}:{}: {}", file, line, args);
+        let msg = format!("{}: {}", location, args);
         match (tcx, span) {
             (Some(tcx), Some(span)) => tcx.sess.diagnostic().span_bug(span, &msg),
             (Some(tcx), None) => tcx.sess.diagnostic().bug(&msg),