@@ -184,7 +184,6 @@ use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
184184use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
185185use rustc_hir:: lang_items:: LangItem ;
186186use rustc_index:: bit_set:: GrowableBitSet ;
187- use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
188187use rustc_middle:: mir:: interpret:: { AllocId , ConstValue } ;
189188use rustc_middle:: mir:: interpret:: { ErrorHandled , GlobalAlloc , Scalar } ;
190189use rustc_middle:: mir:: mono:: { InstantiationMode , MonoItem } ;
@@ -193,6 +192,7 @@ use rustc_middle::mir::{self, Local, Location};
193192use rustc_middle:: ty:: adjustment:: { CustomCoerceUnsized , PointerCast } ;
194193use rustc_middle:: ty:: subst:: { GenericArgKind , InternalSubsts } ;
195194use rustc_middle:: ty:: { self , GenericParamDefKind , Instance , Ty , TyCtxt , TypeFoldable } ;
195+ use rustc_middle:: { middle:: codegen_fn_attrs:: CodegenFnAttrFlags , mir:: visit:: TyContext } ;
196196use rustc_session:: config:: EntryFnType ;
197197use rustc_span:: source_map:: { dummy_spanned, respan, Span , Spanned , DUMMY_SP } ;
198198use smallvec:: SmallVec ;
@@ -638,6 +638,35 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
638638 self . super_rvalue ( rvalue, location) ;
639639 }
640640
641+ /// This does not walk the constant, as it has been handled entirely here and trying
642+ /// to walk it would attempt to evaluate the `ty::Const` inside, which doesn't necessarily
643+ /// work, as some constants cannot be represented in the type system.
644+ fn visit_constant ( & mut self , constant : & mir:: Constant < ' tcx > , location : Location ) {
645+ let literal = self . monomorphize ( constant. literal ) ;
646+ let val = match literal {
647+ mir:: ConstantKind :: Val ( val, _) => val,
648+ mir:: ConstantKind :: Ty ( ct) => match ct. val {
649+ ty:: ConstKind :: Value ( val) => val,
650+ ty:: ConstKind :: Unevaluated ( ct) => {
651+ let param_env = ty:: ParamEnv :: reveal_all ( ) ;
652+ match self . tcx . const_eval_resolve ( param_env, ct, None ) {
653+ // The `monomorphize` call should have evaluated that constant already.
654+ Ok ( val) => val,
655+ Err ( ErrorHandled :: Reported ( ErrorReported ) | ErrorHandled :: Linted ) => return ,
656+ Err ( ErrorHandled :: TooGeneric ) => span_bug ! (
657+ self . body. source_info( location) . span,
658+ "collection encountered polymorphic constant: {:?}" ,
659+ literal
660+ ) ,
661+ }
662+ }
663+ _ => return ,
664+ } ,
665+ } ;
666+ collect_const_value ( self . tcx , val, self . output ) ;
667+ self . visit_ty ( literal. ty ( ) , TyContext :: Location ( location) ) ;
668+ }
669+
641670 fn visit_const ( & mut self , constant : & & ' tcx ty:: Const < ' tcx > , location : Location ) {
642671 debug ! ( "visiting const {:?} @ {:?}" , * constant, location) ;
643672
0 commit comments