@@ -184,7 +184,6 @@ use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
184
184
use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
185
185
use rustc_hir:: lang_items:: LangItem ;
186
186
use rustc_index:: bit_set:: GrowableBitSet ;
187
- use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
188
187
use rustc_middle:: mir:: interpret:: { AllocId , ConstValue } ;
189
188
use rustc_middle:: mir:: interpret:: { ErrorHandled , GlobalAlloc , Scalar } ;
190
189
use rustc_middle:: mir:: mono:: { InstantiationMode , MonoItem } ;
@@ -193,6 +192,7 @@ use rustc_middle::mir::{self, Local, Location};
193
192
use rustc_middle:: ty:: adjustment:: { CustomCoerceUnsized , PointerCast } ;
194
193
use rustc_middle:: ty:: subst:: { GenericArgKind , InternalSubsts } ;
195
194
use rustc_middle:: ty:: { self , GenericParamDefKind , Instance , Ty , TyCtxt , TypeFoldable } ;
195
+ use rustc_middle:: { middle:: codegen_fn_attrs:: CodegenFnAttrFlags , mir:: visit:: TyContext } ;
196
196
use rustc_session:: config:: EntryFnType ;
197
197
use rustc_span:: source_map:: { dummy_spanned, respan, Span , Spanned , DUMMY_SP } ;
198
198
use smallvec:: SmallVec ;
@@ -638,6 +638,35 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
638
638
self . super_rvalue ( rvalue, location) ;
639
639
}
640
640
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
+
641
670
fn visit_const ( & mut self , constant : & & ' tcx ty:: Const < ' tcx > , location : Location ) {
642
671
debug ! ( "visiting const {:?} @ {:?}" , * constant, location) ;
643
672
0 commit comments