Skip to content

Commit 3d044f6

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 6190559 commit 3d044f6

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
let flags = self.dcx.inner.lock().flags;
270270
if flags.dont_buffer_diagnostics || flags.treat_err_as_bug.is_some() {
271271
self.emit();
@@ -427,6 +427,10 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
427427
forward!((subdiagnostic, with_subdiagnostic)(
428428
subdiagnostic: impl crate::AddToDiagnostic,
429429
));
430+
forward!((eager_subdiagnostic, with_eager_subdiagnostic)(
431+
dcx: &DiagCtxt,
432+
subdiagnostic: impl crate::AddToDiagnostic,
433+
));
430434
}
431435

432436
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)