Skip to content

Commit e910841

Browse files
committed
Make span_bug panic site useful again
1 parent 3e5c468 commit e910841

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

Diff for: compiler/rustc_middle/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#![feature(array_windows)]
3232
#![feature(assert_matches)]
3333
#![feature(box_patterns)]
34+
#![feature(closure_track_caller)]
3435
#![feature(core_intrinsics)]
3536
#![feature(const_type_name)]
3637
#![feature(discriminant_kind)]

Diff for: compiler/rustc_middle/src/ty/context/tls.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ where
8585

8686
/// Allows access to the current `ImplicitCtxt` in a closure if one is available.
8787
#[inline]
88+
#[track_caller]
8889
pub fn with_context_opt<F, R>(f: F) -> R
8990
where
9091
F: for<'a, 'tcx> FnOnce(Option<&ImplicitCtxt<'a, 'tcx>>) -> R,
@@ -147,9 +148,13 @@ where
147148
/// Allows access to the `TyCtxt` in the current `ImplicitCtxt`.
148149
/// The closure is passed None if there is no `ImplicitCtxt` available.
149150
#[inline]
151+
#[track_caller]
150152
pub fn with_opt<F, R>(f: F) -> R
151153
where
152154
F: for<'tcx> FnOnce(Option<TyCtxt<'tcx>>) -> R,
153155
{
154-
with_context_opt(|opt_context| f(opt_context.map(|context| context.tcx)))
156+
with_context_opt(
157+
#[track_caller]
158+
|opt_context| f(opt_context.map(|context| context.tcx)),
159+
)
155160
}

Diff for: compiler/rustc_middle/src/util/bug.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ fn opt_span_bug_fmt<S: Into<MultiSpan>>(
2828
args: fmt::Arguments<'_>,
2929
location: &Location<'_>,
3030
) -> ! {
31-
tls::with_opt(move |tcx| {
32-
let msg = format!("{location}: {args}");
33-
match (tcx, span) {
34-
(Some(tcx), Some(span)) => tcx.dcx().span_bug(span, msg),
35-
(Some(tcx), None) => tcx.dcx().bug(msg),
36-
(None, _) => panic_any(msg),
37-
}
38-
})
31+
tls::with_opt(
32+
#[track_caller]
33+
move |tcx| {
34+
let msg = format!("{location}: {args}");
35+
match (tcx, span) {
36+
(Some(tcx), Some(span)) => tcx.dcx().span_bug(span, msg),
37+
(Some(tcx), None) => tcx.dcx().bug(msg),
38+
(None, _) => panic_any(msg),
39+
}
40+
},
41+
)
3942
}
4043

4144
/// A query to trigger a delayed bug. Clearly, if one has a `tcx` one can already trigger a

0 commit comments

Comments
 (0)