Skip to content

Commit e855b90

Browse files
committed
track caller for delay_span_bug
1 parent 268decb commit e855b90

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

src/librustc_errors/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
66
#![feature(crate_visibility_modifier)]
77
#![feature(nll)]
8+
#![feature(track_caller)]
89

910
pub use emitter::ColorConfig;
1011

@@ -621,6 +622,7 @@ impl Handler {
621622
self.inner.borrow_mut().span_bug(span, msg)
622623
}
623624

625+
#[track_caller]
624626
pub fn delay_span_bug(&self, span: impl Into<MultiSpan>, msg: &str) {
625627
self.inner.borrow_mut().delay_span_bug(span, msg)
626628
}
@@ -873,6 +875,7 @@ impl HandlerInner {
873875
self.emit_diagnostic(diag.set_span(sp));
874876
}
875877

878+
#[track_caller]
876879
fn delay_span_bug(&mut self, sp: impl Into<MultiSpan>, msg: &str) {
877880
// This is technically `self.treat_err_as_bug()` but `delay_span_bug` is called before
878881
// incrementing `err_count` by one, so we need to +1 the comparing.
@@ -883,6 +886,7 @@ impl HandlerInner {
883886
}
884887
let mut diagnostic = Diagnostic::new(Level::Bug, msg);
885888
diagnostic.set_span(sp.into());
889+
diagnostic.note(&format!("delayed at {}", std::panic::Location::caller()));
886890
self.delay_as_bug(diagnostic)
887891
}
888892

src/librustc_middle/ty/context.rs

+4-22
Original file line numberDiff line numberDiff line change
@@ -1144,40 +1144,22 @@ impl<'tcx> TyCtxt<'tcx> {
11441144
/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` to ensure it gets used.
11451145
#[track_caller]
11461146
pub fn ty_error(self) -> Ty<'tcx> {
1147-
self.err_with_message_and_location(
1148-
DUMMY_SP,
1149-
"TyKind::Error constructed but no error reported",
1150-
std::panic::Location::caller(),
1151-
)
1147+
self.ty_error_with_message(DUMMY_SP, "TyKind::Error constructed but no error reported")
11521148
}
11531149

11541150
/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` with the given `msg to
11551151
/// ensure it gets used.
11561152
#[track_caller]
11571153
pub fn ty_error_with_message<S: Into<MultiSpan>>(self, span: S, msg: &str) -> Ty<'tcx> {
1158-
self.err_with_message_and_location(span, msg, std::panic::Location::caller())
1159-
}
1160-
1161-
pub fn err_with_message_and_location<S: Into<MultiSpan>>(
1162-
self,
1163-
span: S,
1164-
msg: &str,
1165-
loc: &'static std::panic::Location<'static>,
1166-
) -> Ty<'tcx> {
1167-
self.sess.delay_span_bug(span, &format!("{}: {}", loc, msg));
1154+
self.sess.delay_span_bug(span, msg);
11681155
self.mk_ty(Error(super::sty::DelaySpanBugEmitted(())))
11691156
}
11701157

11711158
/// Like `err` but for constants.
11721159
#[track_caller]
11731160
pub fn const_error(self, ty: Ty<'tcx>) -> &'tcx Const<'tcx> {
1174-
self.sess.delay_span_bug(
1175-
DUMMY_SP,
1176-
&format!(
1177-
"ty::ConstKind::Error constructed but no error reported. {}",
1178-
std::panic::Location::caller()
1179-
),
1180-
);
1161+
self.sess
1162+
.delay_span_bug(DUMMY_SP, "ty::ConstKind::Error constructed but no error reported.");
11811163
self.mk_const(ty::Const {
11821164
val: ty::ConstKind::Error(super::sty::DelaySpanBugEmitted(())),
11831165
ty,

0 commit comments

Comments
 (0)