Skip to content

Commit

Permalink
track caller for delay_span_bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-i-m committed Jun 15, 2020
1 parent 268decb commit e855b90
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
4 changes: 4 additions & 0 deletions src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(crate_visibility_modifier)]
#![feature(nll)]
#![feature(track_caller)]

pub use emitter::ColorConfig;

Expand Down Expand Up @@ -621,6 +622,7 @@ impl Handler {
self.inner.borrow_mut().span_bug(span, msg)
}

#[track_caller]
pub fn delay_span_bug(&self, span: impl Into<MultiSpan>, msg: &str) {
self.inner.borrow_mut().delay_span_bug(span, msg)
}
Expand Down Expand Up @@ -873,6 +875,7 @@ impl HandlerInner {
self.emit_diagnostic(diag.set_span(sp));
}

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

Expand Down
26 changes: 4 additions & 22 deletions src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,40 +1144,22 @@ impl<'tcx> TyCtxt<'tcx> {
/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` to ensure it gets used.
#[track_caller]
pub fn ty_error(self) -> Ty<'tcx> {
self.err_with_message_and_location(
DUMMY_SP,
"TyKind::Error constructed but no error reported",
std::panic::Location::caller(),
)
self.ty_error_with_message(DUMMY_SP, "TyKind::Error constructed but no error reported")
}

/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` with the given `msg to
/// ensure it gets used.
#[track_caller]
pub fn ty_error_with_message<S: Into<MultiSpan>>(self, span: S, msg: &str) -> Ty<'tcx> {
self.err_with_message_and_location(span, msg, std::panic::Location::caller())
}

pub fn err_with_message_and_location<S: Into<MultiSpan>>(
self,
span: S,
msg: &str,
loc: &'static std::panic::Location<'static>,
) -> Ty<'tcx> {
self.sess.delay_span_bug(span, &format!("{}: {}", loc, msg));
self.sess.delay_span_bug(span, msg);
self.mk_ty(Error(super::sty::DelaySpanBugEmitted(())))
}

/// Like `err` but for constants.
#[track_caller]
pub fn const_error(self, ty: Ty<'tcx>) -> &'tcx Const<'tcx> {
self.sess.delay_span_bug(
DUMMY_SP,
&format!(
"ty::ConstKind::Error constructed but no error reported. {}",
std::panic::Location::caller()
),
);
self.sess
.delay_span_bug(DUMMY_SP, "ty::ConstKind::Error constructed but no error reported.");
self.mk_const(ty::Const {
val: ty::ConstKind::Error(super::sty::DelaySpanBugEmitted(())),
ty,
Expand Down

0 comments on commit e855b90

Please sign in to comment.