@@ -499,23 +499,10 @@ pub(crate) fn const_value_reference_to_constant_expr<'tcx, S: UnderOwnerState<'t
499
499
val : rustc_middle:: mir:: interpret:: ConstValue < ' tcx > ,
500
500
span : rustc_span:: Span ,
501
501
) -> ConstantExpr {
502
- use rustc_middle:: mir:: interpret;
503
- use rustc_middle:: ty;
504
-
505
502
let tcx = s. base ( ) . tcx ;
506
503
507
- // We use [try_destructure_mir_constant] to destructure the constant
508
- let param_env = s. param_env ( ) ;
509
- // We have to clone some values: it is a bit annoying, but I don't
510
- // manage to get the lifetimes working otherwise...
511
- let cvalue = rustc_middle:: mir:: ConstantKind :: Val ( val, ty) ;
512
- let param_env_and_const = rustc_middle:: ty:: ParamEnvAnd {
513
- param_env,
514
- value : cvalue,
515
- } ;
516
-
517
504
let dc = tcx
518
- . try_destructure_mir_constant ( param_env_and_const )
505
+ . try_destructure_mir_constant_for_diagnostics ( ( val , ty ) )
519
506
. s_unwrap ( s) ;
520
507
521
508
// Iterate over the fields, which should be values
@@ -530,19 +517,14 @@ pub(crate) fn const_value_reference_to_constant_expr<'tcx, S: UnderOwnerState<'t
530
517
}
531
518
} ;
532
519
533
- // The fields should be of the variant: [ConstantKind::Value]
534
- let fields: Vec < ( ty:: Ty , interpret:: ConstValue ) > = dc
535
- . fields
536
- . iter ( )
537
- . map ( |f| ( f. ty ( ) , f. try_to_value ( tcx) . s_unwrap ( s) ) )
538
- . collect ( ) ;
539
-
540
520
// Below: we are mutually recursive with [const_value_to_constant_expr],
541
- // which takes a [ConstantKind] as input (see `cvalue` above) , but it should be
521
+ // which takes a [ConstantKind] as input, but it should be
542
522
// ok because we call it on a strictly smaller value.
543
- let fields: Vec < ConstantExpr > = fields
544
- . into_iter ( )
545
- . map ( |( ty, f) | const_value_to_constant_expr ( s, ty, f, span) )
523
+ let fields: Vec < ConstantExpr > = dc
524
+ . fields
525
+ . iter ( )
526
+ . copied ( )
527
+ . map ( |( val, ty) | const_value_to_constant_expr ( s, ty, val, span) )
546
528
. collect ( ) ;
547
529
( ConstantExprKind :: Tuple { fields } ) . decorate ( hax_ty, span. sinto ( s) )
548
530
}
0 commit comments