@@ -3,7 +3,7 @@ use std::mem;
3
3
use either:: { Left , Right } ;
4
4
5
5
use rustc_hir:: def:: DefKind ;
6
- use rustc_middle:: mir:: interpret:: { ErrorHandled , InterpErrorInfo } ;
6
+ use rustc_middle:: mir:: interpret:: ErrorHandled ;
7
7
use rustc_middle:: mir:: pretty:: write_allocation_bytes;
8
8
use rustc_middle:: mir:: { self , ConstAlloc , ConstValue } ;
9
9
use rustc_middle:: traits:: Reveal ;
@@ -331,25 +331,9 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
331
331
Ok ( mplace) => {
332
332
// Since evaluation had no errors, validate the resulting constant.
333
333
// 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
+
353
337
let alloc_id = mplace. ptr ( ) . provenance . unwrap ( ) ;
354
338
355
339
// Validation failed, report an error.
@@ -391,3 +375,31 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
391
375
}
392
376
}
393
377
}
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