1
1
use std:: mem;
2
2
3
- use rustc_errors:: { DiagArgName , DiagArgValue , DiagMessage , Diagnostic , IntoDiagArg } ;
3
+ use rustc_errors:: { Diag , DiagArgName , DiagArgValue , DiagMessage , IntoDiagArg } ;
4
4
use rustc_middle:: mir:: AssertKind ;
5
5
use rustc_middle:: mir:: interpret:: { Provenance , ReportedErrorInfo } ;
6
6
use rustc_middle:: query:: TyCtxtAt ;
@@ -131,10 +131,10 @@ pub fn get_span_and_frames<'tcx>(
131
131
132
132
/// Create a diagnostic for a const eval error.
133
133
///
134
- /// This will use the `mk` function for creating the error which will get passed labels according to
135
- /// the `InterpError` and the span and a stacktrace of current execution according to
136
- /// `get_span_and_frames`.
137
- pub ( super ) fn report < ' tcx , C , F , E > (
134
+ /// This will use the `mk` function for adding more information to the error.
135
+ /// You can use it to add a stacktrace of current execution according to
136
+ /// `get_span_and_frames` or just give context on where the const eval error happened .
137
+ pub ( super ) fn report < ' tcx , C , F > (
138
138
tcx : TyCtxt < ' tcx > ,
139
139
error : InterpErrorKind < ' tcx > ,
140
140
span : Span ,
@@ -143,8 +143,7 @@ pub(super) fn report<'tcx, C, F, E>(
143
143
) -> ErrorHandled
144
144
where
145
145
C : FnOnce ( ) -> ( Span , Vec < FrameNote > ) ,
146
- F : FnOnce ( Span , Vec < FrameNote > ) -> E ,
147
- E : Diagnostic < ' tcx > ,
146
+ F : FnOnce ( & mut Diag < ' _ > , Span , Vec < FrameNote > ) ,
148
147
{
149
148
// Special handling for certain errors
150
149
match error {
@@ -163,20 +162,17 @@ where
163
162
_ => {
164
163
let ( our_span, frames) = get_span_and_frames ( ) ;
165
164
let span = span. substitute_dummy ( our_span) ;
166
- let err = mk ( span, frames) ;
167
- let mut err = tcx. dcx ( ) . create_err ( err) ;
165
+ let mut err = tcx. dcx ( ) . struct_span_err ( our_span, error. diagnostic_message ( ) ) ;
168
166
// We allow invalid programs in infallible promoteds since invalid layouts can occur
169
167
// anyway (e.g. due to size overflow). And we allow OOM as that can happen any time.
170
168
let allowed_in_infallible = matches ! (
171
169
error,
172
170
InterpErrorKind :: ResourceExhaustion ( _) | InterpErrorKind :: InvalidProgram ( _)
173
171
) ;
174
172
175
- let msg = error. diagnostic_message ( ) ;
176
173
error. add_args ( & mut err) ;
177
174
178
- // Use *our* span to label the interp error
179
- err. span_label ( our_span, msg) ;
175
+ mk ( & mut err, span, frames) ;
180
176
let g = err. emit ( ) ;
181
177
let reported = if allowed_in_infallible {
182
178
ReportedErrorInfo :: allowed_in_infallible ( g)
0 commit comments