Skip to content

Commit a1077a1

Browse files
Remove ReportErrorExt and try to use IntoDiagnostic trait
1 parent 0209ac0 commit a1077a1

File tree

6 files changed

+31
-443
lines changed

6 files changed

+31
-443
lines changed

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ use rustc_span::source_map::Spanned;
88
use rustc_span::{ErrorGuaranteed, Span, Symbol};
99

1010
use super::InterpCx;
11-
use crate::errors::{self, FrameNote, ReportErrorExt};
11+
use crate::errors::{self, FrameNote};
1212
use crate::interpret::{ErrorHandled, InterpError, InterpErrorInfo, Machine, MachineStopType};
13+
use crate::InterpErrorExt;
1314

1415
/// The CTFE machine has some custom error kinds.
1516
#[derive(Clone, Debug)]
@@ -125,7 +126,7 @@ pub(super) fn report<'tcx, C, F, E>(
125126
error: InterpError<'tcx>,
126127
span: Option<Span>,
127128
get_span_and_frames: C,
128-
mk: F,
129+
_mk: F,
129130
) -> ErrorHandled
130131
where
131132
C: FnOnce() -> (Span, Vec<FrameNote>),
@@ -162,15 +163,18 @@ where
162163
// Report as hard error.
163164
let (our_span, frames) = get_span_and_frames();
164165
let span = span.unwrap_or(our_span);
165-
let err = mk(span, frames);
166-
let mut err = tcx.sess.create_err(err);
166+
let err = tcx.sess.create_err(Spanned { span, node: InterpErrorExt(error) });
167167

168-
let msg = error.diagnostic_message();
169-
error.add_args(&tcx.sess.parse_sess.span_diagnostic, &mut err);
168+
let Some((mut err, handler)) = err.into_diagnostic() else {
169+
panic!("did not emit diag");
170+
};
171+
172+
for frame in frames {
173+
err.eager_subdiagnostic(handler, frame);
174+
}
170175

171176
// Use *our* span to label the interp error
172-
err.span_label(our_span, msg);
173-
ErrorHandled::Reported(err.emit().into())
177+
ErrorHandled::Reported(handler.emit_diagnostic(&mut err).unwrap().into())
174178
}
175179
}
176180
}

0 commit comments

Comments
 (0)