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
use ty::tls;
use std::fmt;
use syntax_pos::{Span, MultiSpan};
#[cold]
#[inline(never)]
pub fn bug_fmt(file: &'static str, line: u32, args: fmt::Arguments) -> ! {
opt_span_bug_fmt(file, line, None::<Span>, args);
}
#[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);
}
fn opt_span_bug_fmt<S: Into<MultiSpan>>(
file: &'static str,
line: u32,
span: Option<S>,
args: fmt::Arguments,
) -> ! {
tls::with_opt(move |tcx| {
let msg = format!("{}:{}: {}", file, line, 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!(msg),
}
});
unreachable!();
}