1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use crate::ty::{tls, TyCtxt};
use rustc_errors::MultiSpan;
use rustc_span::Span;
use std::fmt;
use std::panic::{panic_any, Location};
#[cold]
#[inline(never)]
#[track_caller]
pub fn bug_fmt(args: fmt::Arguments<'_>) -> ! {
opt_span_bug_fmt(None::<Span>, args, Location::caller());
}
#[cold]
#[inline(never)]
#[track_caller]
pub fn span_bug_fmt<S: Into<MultiSpan>>(span: S, args: fmt::Arguments<'_>) -> ! {
opt_span_bug_fmt(Some(span), args, Location::caller());
}
#[track_caller]
fn opt_span_bug_fmt<S: Into<MultiSpan>>(
span: Option<S>,
args: fmt::Arguments<'_>,
location: &Location<'_>,
) -> ! {
tls::with_opt(move |tcx| {
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),
(None, _) => panic_any(msg),
}
});
unreachable!();
}
pub fn trigger_delay_span_bug(tcx: TyCtxt<'_>, key: rustc_hir::def_id::DefId) {
tcx.sess.delay_span_bug(
tcx.def_span(key),
"delayed span bug triggered by #[rustc_error(delay_span_bug_from_inside_query)]",
);
}
pub fn provide(providers: &mut crate::ty::query::Providers) {
*providers = crate::ty::query::Providers { trigger_delay_span_bug, ..*providers };
}