|
3 | 3 | use crate::ty::{tls, TyCtxt}; |
4 | 4 | use rustc_span::{MultiSpan, Span}; |
5 | 5 | use std::fmt; |
| 6 | +use std::panic::Location; |
6 | 7 |
|
7 | 8 | #[cold] |
8 | 9 | #[inline(never)] |
9 | | -pub fn bug_fmt(file: &'static str, line: u32, args: fmt::Arguments<'_>) -> ! { |
| 10 | +#[track_caller] |
| 11 | +pub fn bug_fmt(args: fmt::Arguments<'_>) -> ! { |
10 | 12 | // this wrapper mostly exists so I don't have to write a fully |
11 | 13 | // qualified path of None::<Span> inside the bug!() macro definition |
12 | | - opt_span_bug_fmt(file, line, None::<Span>, args); |
| 14 | + opt_span_bug_fmt(None::<Span>, args, Location::caller()); |
13 | 15 | } |
14 | 16 |
|
15 | 17 | #[cold] |
16 | 18 | #[inline(never)] |
17 | | -pub fn span_bug_fmt<S: Into<MultiSpan>>( |
18 | | - file: &'static str, |
19 | | - line: u32, |
20 | | - span: S, |
21 | | - args: fmt::Arguments<'_>, |
22 | | -) -> ! { |
23 | | - opt_span_bug_fmt(file, line, Some(span), args); |
| 19 | +#[track_caller] |
| 20 | +pub fn span_bug_fmt<S: Into<MultiSpan>>(span: S, args: fmt::Arguments<'_>) -> ! { |
| 21 | + opt_span_bug_fmt(Some(span), args, Location::caller()); |
24 | 22 | } |
25 | 23 |
|
26 | 24 | fn opt_span_bug_fmt<S: Into<MultiSpan>>( |
27 | | - file: &'static str, |
28 | | - line: u32, |
29 | 25 | span: Option<S>, |
30 | 26 | args: fmt::Arguments<'_>, |
| 27 | + location: &Location<'_>, |
31 | 28 | ) -> ! { |
32 | 29 | tls::with_opt(move |tcx| { |
33 | | - let msg = format!("{}:{}: {}", file, line, args); |
| 30 | + let msg = format!("{}: {}", location, args); |
34 | 31 | match (tcx, span) { |
35 | 32 | (Some(tcx), Some(span)) => tcx.sess.diagnostic().span_bug(span, &msg), |
36 | 33 | (Some(tcx), None) => tcx.sess.diagnostic().bug(&msg), |
|
0 commit comments