]>
Commit | Line | Data |
---|---|---|
b7449926 XL |
1 | // These functions are used by macro expansion for bug! and span_bug! |
2 | ||
9fa01778 | 3 | use crate::ty::tls; |
dfeec247 | 4 | use rustc_span::{MultiSpan, Span}; |
b7449926 | 5 | use std::fmt; |
b7449926 XL |
6 | |
7 | #[cold] | |
8 | #[inline(never)] | |
0bf4aa26 | 9 | pub fn bug_fmt(file: &'static str, line: u32, args: fmt::Arguments<'_>) -> ! { |
b7449926 XL |
10 | // this wrapper mostly exists so I don't have to write a fully |
11 | // qualified path of None::<Span> inside the bug!() macro definition | |
12 | opt_span_bug_fmt(file, line, None::<Span>, args); | |
13 | } | |
14 | ||
15 | #[cold] | |
16 | #[inline(never)] | |
17 | pub fn span_bug_fmt<S: Into<MultiSpan>>( | |
18 | file: &'static str, | |
19 | line: u32, | |
20 | span: S, | |
0bf4aa26 | 21 | args: fmt::Arguments<'_>, |
b7449926 XL |
22 | ) -> ! { |
23 | opt_span_bug_fmt(file, line, Some(span), args); | |
24 | } | |
25 | ||
26 | fn opt_span_bug_fmt<S: Into<MultiSpan>>( | |
27 | file: &'static str, | |
28 | line: u32, | |
29 | span: Option<S>, | |
0bf4aa26 | 30 | args: fmt::Arguments<'_>, |
b7449926 XL |
31 | ) -> ! { |
32 | tls::with_opt(move |tcx| { | |
33 | let msg = format!("{}:{}: {}", file, line, args); | |
34 | match (tcx, span) { | |
35 | (Some(tcx), Some(span)) => tcx.sess.diagnostic().span_bug(span, &msg), | |
36 | (Some(tcx), None) => tcx.sess.diagnostic().bug(&msg), | |
37 | (None, _) => panic!(msg), | |
38 | } | |
39 | }); | |
40 | unreachable!(); | |
41 | } |