about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-03-12 13:49:50 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-03-19 09:19:12 +0000
commite91084180e2171fd229241adfb4b1463ebb79958 (patch)
tree83d4bb7275adff3e56a0482bf28bee35e1c62529
parent3e5c468662d0137665a4381ad85912a763c7a3ef (diff)
downloadrust-e91084180e2171fd229241adfb4b1463ebb79958.tar.gz
rust-e91084180e2171fd229241adfb4b1463ebb79958.zip
Make span_bug panic site useful again
-rw-r--r--compiler/rustc_middle/src/lib.rs1
-rw-r--r--compiler/rustc_middle/src/ty/context/tls.rs7
-rw-r--r--compiler/rustc_middle/src/util/bug.rs19
3 files changed, 18 insertions, 9 deletions
diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs
index e47668b9110..d910a15e262 100644
--- a/compiler/rustc_middle/src/lib.rs
+++ b/compiler/rustc_middle/src/lib.rs
@@ -31,6 +31,7 @@
 #![feature(array_windows)]
 #![feature(assert_matches)]
 #![feature(box_patterns)]
+#![feature(closure_track_caller)]
 #![feature(core_intrinsics)]
 #![feature(const_type_name)]
 #![feature(discriminant_kind)]
diff --git a/compiler/rustc_middle/src/ty/context/tls.rs b/compiler/rustc_middle/src/ty/context/tls.rs
index 788ccd5dbbd..5e256dc8d26 100644
--- a/compiler/rustc_middle/src/ty/context/tls.rs
+++ b/compiler/rustc_middle/src/ty/context/tls.rs
@@ -85,6 +85,7 @@ where
 
 /// Allows access to the current `ImplicitCtxt` in a closure if one is available.
 #[inline]
+#[track_caller]
 pub fn with_context_opt<F, R>(f: F) -> R
 where
     F: for<'a, 'tcx> FnOnce(Option<&ImplicitCtxt<'a, 'tcx>>) -> R,
@@ -147,9 +148,13 @@ where
 /// Allows access to the `TyCtxt` in the current `ImplicitCtxt`.
 /// The closure is passed None if there is no `ImplicitCtxt` available.
 #[inline]
+#[track_caller]
 pub fn with_opt<F, R>(f: F) -> R
 where
     F: for<'tcx> FnOnce(Option<TyCtxt<'tcx>>) -> R,
 {
-    with_context_opt(|opt_context| f(opt_context.map(|context| context.tcx)))
+    with_context_opt(
+        #[track_caller]
+        |opt_context| f(opt_context.map(|context| context.tcx)),
+    )
 }
diff --git a/compiler/rustc_middle/src/util/bug.rs b/compiler/rustc_middle/src/util/bug.rs
index a67ec991582..43853a10896 100644
--- a/compiler/rustc_middle/src/util/bug.rs
+++ b/compiler/rustc_middle/src/util/bug.rs
@@ -28,14 +28,17 @@ fn opt_span_bug_fmt<S: Into<MultiSpan>>(
     args: fmt::Arguments<'_>,
     location: &Location<'_>,
 ) -> ! {
-    tls::with_opt(move |tcx| {
-        let msg = format!("{location}: {args}");
-        match (tcx, span) {
-            (Some(tcx), Some(span)) => tcx.dcx().span_bug(span, msg),
-            (Some(tcx), None) => tcx.dcx().bug(msg),
-            (None, _) => panic_any(msg),
-        }
-    })
+    tls::with_opt(
+        #[track_caller]
+        move |tcx| {
+            let msg = format!("{location}: {args}");
+            match (tcx, span) {
+                (Some(tcx), Some(span)) => tcx.dcx().span_bug(span, msg),
+                (Some(tcx), None) => tcx.dcx().bug(msg),
+                (None, _) => panic_any(msg),
+            }
+        },
+    )
 }
 
 /// A query to trigger a delayed bug. Clearly, if one has a `tcx` one can already trigger a