@@ -2,16 +2,16 @@ use std::mem;
22
33use rustc_errors:: { Diag , DiagArgName , DiagArgValue , DiagMessage , IntoDiagArg } ;
44use rustc_middle:: mir:: AssertKind ;
5- use rustc_middle:: mir:: interpret:: { Provenance , ReportedErrorInfo } ;
5+ use rustc_middle:: mir:: interpret:: { Provenance , ReportedErrorInfo , UndefinedBehaviorInfo } ;
66use rustc_middle:: query:: TyCtxtAt ;
7+ use rustc_middle:: ty:: ConstInt ;
78use rustc_middle:: ty:: layout:: LayoutError ;
8- use rustc_middle:: ty:: { ConstInt , TyCtxt } ;
99use rustc_span:: { Span , Symbol } ;
1010
1111use super :: CompileTimeMachine ;
1212use crate :: errors:: { self , FrameNote , ReportErrorExt } ;
1313use crate :: interpret:: {
14- ErrorHandled , Frame , InterpErrorInfo , InterpErrorKind , MachineStopType , err_inval,
14+ ErrorHandled , Frame , InterpCx , InterpErrorInfo , InterpErrorKind , MachineStopType , err_inval,
1515 err_machine_stop,
1616} ;
1717
@@ -135,7 +135,7 @@ pub fn get_span_and_frames<'tcx>(
135135/// You can use it to add a stacktrace of current execution according to
136136/// `get_span_and_frames` or just give context on where the const eval error happened.
137137pub ( super ) fn report < ' tcx , C , F > (
138- tcx : TyCtxt < ' tcx > ,
138+ ecx : & InterpCx < ' tcx , CompileTimeMachine < ' tcx > > ,
139139 error : InterpErrorKind < ' tcx > ,
140140 span : Span ,
141141 get_span_and_frames : C ,
@@ -145,6 +145,7 @@ where
145145 C : FnOnce ( ) -> ( Span , Vec < FrameNote > ) ,
146146 F : FnOnce ( & mut Diag < ' _ > , Span , Vec < FrameNote > ) ,
147147{
148+ let tcx = ecx. tcx . tcx ;
148149 // Special handling for certain errors
149150 match error {
150151 // Don't emit a new diagnostic for these errors, they are already reported elsewhere or
@@ -170,9 +171,24 @@ where
170171 InterpErrorKind :: ResourceExhaustion ( _) | InterpErrorKind :: InvalidProgram ( _)
171172 ) ;
172173
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+
173188 error. add_args ( & mut err) ;
174189
175190 mk ( & mut err, span, frames) ;
191+
176192 let g = err. emit ( ) ;
177193 let reported = if allowed_in_infallible {
178194 ReportedErrorInfo :: allowed_in_infallible ( g)
0 commit comments