Skip to content

Commit

Permalink
Add missing DiagnosticBuilder::eager_diagnostic method.
Browse files Browse the repository at this point in the history
This lets us avoid the use of `DiagnosticBuilder::into_diagnostic` in
miri, when then means that `DiagnosticBuilder::into_diagnostic` can
become private, being now only used by `stash` and `buffer`.
  • Loading branch information
nnethercote committed Jan 9, 2024
1 parent e7b6d0e commit 9fef2f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 5 additions & 1 deletion compiler/rustc_errors/src/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {

/// Converts the builder to a `Diagnostic` for later emission,
/// unless dcx has disabled such buffering.
pub fn into_diagnostic(mut self) -> Option<(Diagnostic, &'a DiagCtxt)> {
fn into_diagnostic(mut self) -> Option<(Diagnostic, &'a DiagCtxt)> {
let flags = self.dcx.inner.lock().flags;
if flags.dont_buffer_diagnostics || flags.treat_err_as_bug.is_some() {
self.emit();
Expand Down Expand Up @@ -427,6 +427,10 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
forward!((subdiagnostic, with_subdiagnostic)(
subdiagnostic: impl crate::AddToDiagnostic,
));
forward!((eager_subdiagnostic, with_eager_subdiagnostic)(
dcx: &DiagCtxt,
subdiagnostic: impl crate::AddToDiagnostic,
));
}

impl<G: EmissionGuarantee> Debug for DiagnosticBuilder<'_, G> {
Expand Down
6 changes: 2 additions & 4 deletions src/tools/miri/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,22 +499,20 @@ pub fn report_msg<'tcx>(
err.note(if extra_span { "BACKTRACE (of the first span):" } else { "BACKTRACE:" });
}

let (mut err, handler) = err.into_diagnostic().unwrap();

// Add backtrace
for (idx, frame_info) in stacktrace.iter().enumerate() {
let is_local = machine.is_local(frame_info);
// No span for non-local frames and the first frame (which is the error site).
if is_local && idx > 0 {
err.eager_subdiagnostic(handler, frame_info.as_note(machine.tcx));
err.eager_subdiagnostic(err.dcx, frame_info.as_note(machine.tcx));
} else {
let sm = sess.source_map();
let span = sm.span_to_embeddable_string(frame_info.span);
err.note(format!("{frame_info} at {span}"));
}
}

handler.emit_diagnostic(err);
err.emit();
}

impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
Expand Down

0 comments on commit 9fef2f7

Please sign in to comment.