@@ -749,39 +749,15 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
749749 #[ instrument( skip( self ) , level = "debug" ) ]
750750 fn visit_constant ( & mut self , constant : & mir:: Constant < ' tcx > , location : Location ) {
751751 let literal = self . monomorphize ( constant. literal ) ;
752- let val = match literal {
753- mir:: ConstantKind :: Val ( val, _) => val,
754- mir:: ConstantKind :: Ty ( ct) => match ct. kind ( ) {
755- ty:: ConstKind :: Value ( val) => self . tcx . valtree_to_const_val ( ( ct. ty ( ) , val) ) ,
756- ty:: ConstKind :: Unevaluated ( ct) => {
757- debug ! ( ?ct) ;
758- let param_env = ty:: ParamEnv :: reveal_all ( ) ;
759- match self . tcx . const_eval_resolve ( param_env, ct. expand ( ) , None ) {
760- // The `monomorphize` call should have evaluated that constant already.
761- Ok ( val) => val,
762- Err ( ErrorHandled :: Reported ( _) ) => return ,
763- Err ( ErrorHandled :: TooGeneric ) => span_bug ! (
764- self . body. source_info( location) . span,
765- "collection encountered polymorphic constant: {:?}" ,
766- literal
767- ) ,
768- }
769- }
770- _ => return ,
771- } ,
772- mir:: ConstantKind :: Unevaluated ( uv, _) => {
773- let param_env = ty:: ParamEnv :: reveal_all ( ) ;
774- match self . tcx . const_eval_resolve ( param_env, uv, None ) {
775- // The `monomorphize` call should have evaluated that constant already.
776- Ok ( val) => val,
777- Err ( ErrorHandled :: Reported ( _) ) => return ,
778- Err ( ErrorHandled :: TooGeneric ) => span_bug ! (
779- self . body. source_info( location) . span,
780- "collection encountered polymorphic constant: {:?}" ,
781- literal
782- ) ,
783- }
784- }
752+ let param_env = ty:: ParamEnv :: reveal_all ( ) ;
753+ let val = match literal. eval ( self . tcx , param_env, None ) {
754+ Ok ( v) => v,
755+ Err ( ErrorHandled :: Reported ( _) ) => return ,
756+ Err ( ErrorHandled :: TooGeneric ) => span_bug ! (
757+ self . body. source_info( location) . span,
758+ "collection encountered polymorphic constant: {:?}" ,
759+ literal
760+ ) ,
785761 } ;
786762 collect_const_value ( self . tcx , val, self . output ) ;
787763 MirVisitor :: visit_ty ( self , literal. ty ( ) , TyContext :: Location ( location) ) ;
0 commit comments