@@ -430,7 +430,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
430
430
None ,
431
431
)
432
432
. ok ( )
433
- . and_then ( |val| Some ( rustc_middle:: mir:: ConstantKind :: from_value ( val, ty) ) ) ?;
433
+ . map ( |val| rustc_middle:: mir:: ConstantKind :: from_value ( val, ty) ) ?;
434
434
let result = miri_to_const ( self . lcx . tcx , result) ;
435
435
if result. is_some ( ) {
436
436
self . needed_resolution = true ;
@@ -581,16 +581,6 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
581
581
}
582
582
}
583
583
584
- fn try_const_to_constant < ' tcx > ( tcx : TyCtxt < ' tcx > , c : ty:: Const < ' tcx > ) -> Option < Constant > {
585
- match c. kind ( ) {
586
- ty:: ConstKind :: Value ( valtree) => {
587
- let const_val = tcx. valtree_to_const_val ( ( c. ty ( ) , valtree) ) ;
588
- miri_to_const ( tcx, mir:: ConstantKind :: from_value ( const_val, c. ty ( ) ) )
589
- } ,
590
- _ => None ,
591
- }
592
- }
593
-
594
584
pub fn miri_to_const < ' tcx > ( tcx : TyCtxt < ' tcx > , result : mir:: ConstantKind < ' tcx > ) -> Option < Constant > {
595
585
use rustc_middle:: mir:: interpret:: ConstValue ;
596
586
match result {
@@ -629,8 +619,8 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) -
629
619
} ,
630
620
mir:: ConstantKind :: Val ( ConstValue :: ByRef { alloc, offset : _ } , _) => match result. ty ( ) . kind ( ) {
631
621
ty:: Array ( sub_type, len) => match sub_type. kind ( ) {
632
- ty:: Float ( FloatTy :: F32 ) => match try_const_to_constant ( tcx, * len ) {
633
- Some ( Constant :: Int ( len) ) => alloc
622
+ ty:: Float ( FloatTy :: F32 ) => match len . try_eval_usize ( tcx, ty :: ParamEnv :: empty ( ) ) {
623
+ Some ( len) => alloc
634
624
. inner ( )
635
625
. inspect_with_uninit_and_ptr_outside_interpreter ( 0 ..( 4 * len as usize ) )
636
626
. to_owned ( )
@@ -644,8 +634,8 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) -
644
634
. map ( Constant :: Vec ) ,
645
635
_ => None ,
646
636
} ,
647
- ty:: Float ( FloatTy :: F64 ) => match try_const_to_constant ( tcx, * len ) {
648
- Some ( Constant :: Int ( len) ) => alloc
637
+ ty:: Float ( FloatTy :: F64 ) => match len . try_eval_usize ( tcx, ty :: ParamEnv :: empty ( ) ) {
638
+ Some ( len) => alloc
649
639
. inner ( )
650
640
. inspect_with_uninit_and_ptr_outside_interpreter ( 0 ..( 8 * len as usize ) )
651
641
. to_owned ( )
0 commit comments