@@ -430,7 +430,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
430430 None ,
431431 )
432432 . 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) ) ?;
434434 let result = miri_to_const ( self . lcx . tcx , result) ;
435435 if result. is_some ( ) {
436436 self . needed_resolution = true ;
@@ -581,16 +581,6 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
581581 }
582582}
583583
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-
594584pub fn miri_to_const < ' tcx > ( tcx : TyCtxt < ' tcx > , result : mir:: ConstantKind < ' tcx > ) -> Option < Constant > {
595585 use rustc_middle:: mir:: interpret:: ConstValue ;
596586 match result {
@@ -629,8 +619,8 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) -
629619 } ,
630620 mir:: ConstantKind :: Val ( ConstValue :: ByRef { alloc, offset : _ } , _) => match result. ty ( ) . kind ( ) {
631621 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
634624 . inner ( )
635625 . inspect_with_uninit_and_ptr_outside_interpreter ( 0 ..( 4 * len as usize ) )
636626 . to_owned ( )
@@ -644,8 +634,8 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) -
644634 . map ( Constant :: Vec ) ,
645635 _ => None ,
646636 } ,
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
649639 . inner ( )
650640 . inspect_with_uninit_and_ptr_outside_interpreter ( 0 ..( 8 * len as usize ) )
651641 . to_owned ( )
0 commit comments