@@ -2,16 +2,16 @@ use std::mem;
2
2
3
3
use rustc_errors:: { Diag , DiagArgName , DiagArgValue , DiagMessage , IntoDiagArg } ;
4
4
use rustc_middle:: mir:: AssertKind ;
5
- use rustc_middle:: mir:: interpret:: { Provenance , ReportedErrorInfo } ;
5
+ use rustc_middle:: mir:: interpret:: { Provenance , ReportedErrorInfo , UndefinedBehaviorInfo } ;
6
6
use rustc_middle:: query:: TyCtxtAt ;
7
+ use rustc_middle:: ty:: ConstInt ;
7
8
use rustc_middle:: ty:: layout:: LayoutError ;
8
- use rustc_middle:: ty:: { ConstInt , TyCtxt } ;
9
9
use rustc_span:: { Span , Symbol } ;
10
10
11
11
use super :: CompileTimeMachine ;
12
12
use crate :: errors:: { self , FrameNote , ReportErrorExt } ;
13
13
use crate :: interpret:: {
14
- ErrorHandled , Frame , InterpErrorInfo , InterpErrorKind , MachineStopType , err_inval,
14
+ ErrorHandled , Frame , InterpCx , InterpErrorInfo , InterpErrorKind , MachineStopType , err_inval,
15
15
err_machine_stop,
16
16
} ;
17
17
@@ -135,7 +135,7 @@ pub fn get_span_and_frames<'tcx>(
135
135
/// You can use it to add a stacktrace of current execution according to
136
136
/// `get_span_and_frames` or just give context on where the const eval error happened.
137
137
pub ( super ) fn report < ' tcx , C , F > (
138
- tcx : TyCtxt < ' tcx > ,
138
+ ecx : & InterpCx < ' tcx , CompileTimeMachine < ' tcx > > ,
139
139
error : InterpErrorKind < ' tcx > ,
140
140
span : Span ,
141
141
get_span_and_frames : C ,
@@ -145,6 +145,7 @@ where
145
145
C : FnOnce ( ) -> ( Span , Vec < FrameNote > ) ,
146
146
F : FnOnce ( & mut Diag < ' _ > , Span , Vec < FrameNote > ) ,
147
147
{
148
+ let tcx = ecx. tcx . tcx ;
148
149
// Special handling for certain errors
149
150
match error {
150
151
// Don't emit a new diagnostic for these errors, they are already reported elsewhere or
@@ -170,9 +171,24 @@ where
170
171
InterpErrorKind :: ResourceExhaustion ( _) | InterpErrorKind :: InvalidProgram ( _)
171
172
) ;
172
173
174
+ if let InterpErrorKind :: UndefinedBehavior ( UndefinedBehaviorInfo :: InvalidUninitBytes (
175
+ Some ( ( alloc_id, _access) ) ,
176
+ ) ) = error
177
+ {
178
+ let bytes = ecx. print_alloc_bytes_for_diagnostics ( alloc_id) ;
179
+ let info = ecx. get_alloc_info ( alloc_id) ;
180
+ let raw_bytes = errors:: RawBytesNote {
181
+ size : info. size . bytes ( ) ,
182
+ align : info. align . bytes ( ) ,
183
+ bytes,
184
+ } ;
185
+ err. subdiagnostic ( raw_bytes) ;
186
+ }
187
+
173
188
error. add_args ( & mut err) ;
174
189
175
190
mk ( & mut err, span, frames) ;
191
+
176
192
let g = err. emit ( ) ;
177
193
let reported = if allowed_in_infallible {
178
194
ReportedErrorInfo :: allowed_in_infallible ( g)
0 commit comments