@@ -3,7 +3,7 @@ use std::mem;
33use either:: { Left , Right } ;
44
55use rustc_hir:: def:: DefKind ;
6- use rustc_middle:: mir:: interpret:: { ErrorHandled , InterpErrorInfo } ;
6+ use rustc_middle:: mir:: interpret:: ErrorHandled ;
77use rustc_middle:: mir:: pretty:: write_allocation_bytes;
88use rustc_middle:: mir:: { self , ConstAlloc , ConstValue } ;
99use rustc_middle:: traits:: Reveal ;
@@ -331,25 +331,9 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
331331 Ok ( mplace) => {
332332 // Since evaluation had no errors, validate the resulting constant.
333333 // This is a separate `try` block to provide more targeted error reporting.
334- let validation: Result < _ , InterpErrorInfo < ' _ > > = try {
335- let mut ref_tracking = RefTracking :: new ( mplace. clone ( ) ) ;
336- let mut inner = false ;
337- while let Some ( ( mplace, path) ) = ref_tracking. todo . pop ( ) {
338- let mode = if is_static {
339- if cid. promoted . is_some ( ) {
340- // Promoteds in statics are allowed to point to statics.
341- CtfeValidationMode :: Const { inner, allow_static_ptrs : true }
342- } else {
343- // a `static`
344- CtfeValidationMode :: Regular
345- }
346- } else {
347- CtfeValidationMode :: Const { inner, allow_static_ptrs : false }
348- } ;
349- ecx. const_validate_operand ( & mplace. into ( ) , path, & mut ref_tracking, mode) ?;
350- inner = true ;
351- }
352- } ;
334+ let validation =
335+ const_validate_mplace ( & ecx, & mplace, is_static, cid. promoted . is_some ( ) ) ;
336+
353337 let alloc_id = mplace. ptr ( ) . provenance . unwrap ( ) ;
354338
355339 // Validation failed, report an error.
@@ -391,3 +375,31 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
391375 }
392376 }
393377}
378+
379+ #[ inline( always) ]
380+ pub fn const_validate_mplace < ' mir , ' tcx > (
381+ ecx : & InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > ,
382+ mplace : & MPlaceTy < ' tcx > ,
383+ is_static : bool ,
384+ is_promoted : bool ,
385+ ) -> InterpResult < ' tcx > {
386+ let mut ref_tracking = RefTracking :: new ( mplace. clone ( ) ) ;
387+ let mut inner = false ;
388+ while let Some ( ( mplace, path) ) = ref_tracking. todo . pop ( ) {
389+ let mode = if is_static {
390+ if is_promoted {
391+ // Promoteds in statics are allowed to point to statics.
392+ CtfeValidationMode :: Const { inner, allow_static_ptrs : true }
393+ } else {
394+ // a `static`
395+ CtfeValidationMode :: Regular
396+ }
397+ } else {
398+ CtfeValidationMode :: Const { inner, allow_static_ptrs : false }
399+ } ;
400+ ecx. const_validate_operand ( & mplace. into ( ) , path, & mut ref_tracking, mode) ?;
401+ inner = true ;
402+ }
403+
404+ Ok ( ( ) )
405+ }
0 commit comments