1
Fork 0

Add missing DiagnosticBuilder::eager_diagnostic method.

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`.
This commit is contained in:
Nicholas Nethercote 2024-01-09 09:26:53 +11:00
parent ed76b0b882
commit 700a396520
2 changed files with 7 additions and 5 deletions

View file

@ -265,7 +265,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
/// Converts the builder to a `Diagnostic` for later emission, /// Converts the builder to a `Diagnostic` for later emission,
/// unless dcx has disabled such buffering. /// 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)> {
if self.dcx.inner.lock().flags.treat_err_as_bug.is_some() { if self.dcx.inner.lock().flags.treat_err_as_bug.is_some() {
self.emit(); self.emit();
return None; return None;
@ -426,6 +426,10 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
forward!((subdiagnostic, with_subdiagnostic)( forward!((subdiagnostic, with_subdiagnostic)(
subdiagnostic: impl crate::AddToDiagnostic, subdiagnostic: impl crate::AddToDiagnostic,
)); ));
forward!((eager_subdiagnostic, with_eager_subdiagnostic)(
dcx: &DiagCtxt,
subdiagnostic: impl crate::AddToDiagnostic,
));
} }
impl<G: EmissionGuarantee> Debug for DiagnosticBuilder<'_, G> { impl<G: EmissionGuarantee> Debug for DiagnosticBuilder<'_, G> {

View file

@ -499,14 +499,12 @@ pub fn report_msg<'tcx>(
err.note(if extra_span { "BACKTRACE (of the first span):" } else { "BACKTRACE:" }); err.note(if extra_span { "BACKTRACE (of the first span):" } else { "BACKTRACE:" });
} }
let (mut err, handler) = err.into_diagnostic().unwrap();
// Add backtrace // Add backtrace
for (idx, frame_info) in stacktrace.iter().enumerate() { for (idx, frame_info) in stacktrace.iter().enumerate() {
let is_local = machine.is_local(frame_info); let is_local = machine.is_local(frame_info);
// No span for non-local frames and the first frame (which is the error site). // No span for non-local frames and the first frame (which is the error site).
if is_local && idx > 0 { 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 { } else {
let sm = sess.source_map(); let sm = sess.source_map();
let span = sm.span_to_embeddable_string(frame_info.span); let span = sm.span_to_embeddable_string(frame_info.span);
@ -514,7 +512,7 @@ pub fn report_msg<'tcx>(
} }
} }
handler.emit_diagnostic(err); err.emit();
} }
impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> { impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {