@@ -534,7 +534,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
534534 // * During ConstProp, with `TooGeneric` or since the `required_consts` were not all
535535 // checked yet.
536536 // * During CTFE, since promoteds in `const`/`static` initializer bodies can fail.
537- self . mir_const_to_op ( & val, layout) ?
537+ self . const_to_op ( & val, layout) ?
538538 }
539539 } ;
540540 trace ! ( "{:?}: {:?}" , mir_op, * op) ;
@@ -549,50 +549,42 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
549549 ops. iter ( ) . map ( |op| self . eval_operand ( op, None ) ) . collect ( )
550550 }
551551
552- // Used when the miri-engine runs into a constant and for extracting information from constants
553- // in patterns via the `const_eval` module
554- /// The `val` and `layout` are assumed to already be in our interpreter
555- /// "universe" (param_env).
556552 pub fn const_to_op (
557- & self ,
558- c : ty:: Const < ' tcx > ,
559- layout : Option < TyAndLayout < ' tcx > > ,
560- ) -> InterpResult < ' tcx , OpTy < ' tcx , M :: Provenance > > {
561- match c. kind ( ) {
562- ty:: ConstKind :: Param ( _) | ty:: ConstKind :: Placeholder ( ..) => throw_inval ! ( TooGeneric ) ,
563- ty:: ConstKind :: Error ( DelaySpanBugEmitted { reported, .. } ) => {
564- throw_inval ! ( AlreadyReported ( reported) )
565- }
566- ty:: ConstKind :: Unevaluated ( uv) => {
567- // NOTE: We evaluate to a `ValTree` here as a check to ensure
568- // we're working with valid constants, even though we never need it.
569- let instance = self . resolve ( uv. def , uv. substs ) ?;
570- let cid = GlobalId { instance, promoted : None } ;
571- let _valtree = self
572- . tcx
573- . eval_to_valtree ( self . param_env . and ( cid) ) ?
574- . unwrap_or_else ( || bug ! ( "unable to create ValTree for {:?}" , uv) ) ;
575-
576- Ok ( self . eval_to_allocation ( cid) ?. into ( ) )
577- }
578- ty:: ConstKind :: Bound ( ..) | ty:: ConstKind :: Infer ( ..) => {
579- span_bug ! ( self . cur_span( ) , "const_to_op: Unexpected ConstKind {:?}" , c)
580- }
581- ty:: ConstKind :: Value ( valtree) => {
582- let ty = c. ty ( ) ;
583- let const_val = self . tcx . valtree_to_const_val ( ( ty, valtree) ) ;
584- self . const_val_to_op ( const_val, ty, layout)
585- }
586- }
587- }
588-
589- pub fn mir_const_to_op (
590553 & self ,
591554 val : & mir:: ConstantKind < ' tcx > ,
592555 layout : Option < TyAndLayout < ' tcx > > ,
593556 ) -> InterpResult < ' tcx , OpTy < ' tcx , M :: Provenance > > {
594557 match val {
595- mir:: ConstantKind :: Ty ( ct) => self . const_to_op ( * ct, layout) ,
558+ mir:: ConstantKind :: Ty ( ct) => {
559+ match ct. kind ( ) {
560+ ty:: ConstKind :: Param ( _) | ty:: ConstKind :: Placeholder ( ..) => {
561+ throw_inval ! ( TooGeneric )
562+ }
563+ ty:: ConstKind :: Error ( DelaySpanBugEmitted { reported, .. } ) => {
564+ throw_inval ! ( AlreadyReported ( reported) )
565+ }
566+ ty:: ConstKind :: Unevaluated ( uv) => {
567+ // NOTE: We evaluate to a `ValTree` here as a check to ensure
568+ // we're working with valid constants, even though we never need it.
569+ let instance = self . resolve ( uv. def , uv. substs ) ?;
570+ let cid = GlobalId { instance, promoted : None } ;
571+ let _valtree = self
572+ . tcx
573+ . eval_to_valtree ( self . param_env . and ( cid) ) ?
574+ . unwrap_or_else ( || bug ! ( "unable to create ValTree for {uv:?}" ) ) ;
575+
576+ Ok ( self . eval_to_allocation ( cid) ?. into ( ) )
577+ }
578+ ty:: ConstKind :: Bound ( ..) | ty:: ConstKind :: Infer ( ..) => {
579+ span_bug ! ( self . cur_span( ) , "unexpected ConstKind in ctfe: {ct:?}" )
580+ }
581+ ty:: ConstKind :: Value ( valtree) => {
582+ let ty = ct. ty ( ) ;
583+ let const_val = self . tcx . valtree_to_const_val ( ( ty, valtree) ) ;
584+ self . const_val_to_op ( const_val, ty, layout)
585+ }
586+ }
587+ }
596588 mir:: ConstantKind :: Val ( val, ty) => self . const_val_to_op ( * val, * ty, layout) ,
597589 mir:: ConstantKind :: Unevaluated ( uv, _) => {
598590 let instance = self . resolve ( uv. def , uv. substs ) ?;
0 commit comments