Skip to content

Commit 700a396

Browse files
committed
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`.
1 parent ed76b0b commit 700a396

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Diff for: compiler/rustc_errors/src/diagnostic_builder.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
265265

266266
/// Converts the builder to a `Diagnostic` for later emission,
267267
/// unless dcx has disabled such buffering.
268-
pub fn into_diagnostic(mut self) -> Option<(Diagnostic, &'a DiagCtxt)> {
268+
fn into_diagnostic(mut self) -> Option<(Diagnostic, &'a DiagCtxt)> {
269269
if self.dcx.inner.lock().flags.treat_err_as_bug.is_some() {
270270
self.emit();
271271
return None;
@@ -426,6 +426,10 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
426426
forward!((subdiagnostic, with_subdiagnostic)(
427427
subdiagnostic: impl crate::AddToDiagnostic,
428428
));
429+
forward!((eager_subdiagnostic, with_eager_subdiagnostic)(
430+
dcx: &DiagCtxt,
431+
subdiagnostic: impl crate::AddToDiagnostic,
432+
));
429433
}
430434

431435
impl<G: EmissionGuarantee> Debug for DiagnosticBuilder<'_, G> {

Diff for: src/tools/miri/src/diagnostics.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -499,22 +499,20 @@ pub fn report_msg<'tcx>(
499499
err.note(if extra_span { "BACKTRACE (of the first span):" } else { "BACKTRACE:" });
500500
}
501501

502-
let (mut err, handler) = err.into_diagnostic().unwrap();
503-
504502
// Add backtrace
505503
for (idx, frame_info) in stacktrace.iter().enumerate() {
506504
let is_local = machine.is_local(frame_info);
507505
// No span for non-local frames and the first frame (which is the error site).
508506
if is_local && idx > 0 {
509-
err.eager_subdiagnostic(handler, frame_info.as_note(machine.tcx));
507+
err.eager_subdiagnostic(err.dcx, frame_info.as_note(machine.tcx));
510508
} else {
511509
let sm = sess.source_map();
512510
let span = sm.span_to_embeddable_string(frame_info.span);
513511
err.note(format!("{frame_info} at {span}"));
514512
}
515513
}
516514

517-
handler.emit_diagnostic(err);
515+
err.emit();
518516
}
519517

520518
impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {

0 commit comments

Comments
 (0)