@@ -29,12 +29,12 @@ use rustc_hir::def::{DefKind, Res};
2929use rustc_hir:: def_id:: { DefId , LocalDefId } ;
3030use rustc_hir:: intravisit:: { self , Visitor } ;
3131use rustc_hir:: Node ;
32+ use rustc_middle:: bug;
3233use rustc_middle:: middle:: codegen_fn_attrs:: { CodegenFnAttrFlags , CodegenFnAttrs } ;
3334use rustc_middle:: middle:: privacy:: { self , Level } ;
3435use rustc_middle:: mir:: interpret:: { ConstAllocation , ErrorHandled , GlobalAlloc } ;
3536use rustc_middle:: query:: Providers ;
3637use rustc_middle:: ty:: { self , ExistentialTraitRef , TyCtxt } ;
37- use rustc_middle:: { bug, span_bug} ;
3838use rustc_privacy:: DefIdVisitor ;
3939use rustc_session:: config:: CrateType ;
4040use tracing:: debug;
@@ -205,19 +205,19 @@ impl<'tcx> ReachableContext<'tcx> {
205205 }
206206 }
207207
208- // Reachable constants will be inlined into other crates
209- // unconditionally, so we need to make sure that their
210- // contents are also reachable.
211- hir :: ItemKind :: Const ( .. ) => {
208+ hir :: ItemKind :: Const ( _ , _ , init ) => {
209+ // Only things actually ending up in the final constant need to be reachable.
210+ // Everything else is either already available as `mir_for_ctfe`, or can't be used
211+ // by codegen anyway.
212212 match self . tcx . const_eval_poly_to_alloc ( item. owner_id . def_id . into ( ) ) {
213213 Ok ( alloc) => {
214214 let alloc = self . tcx . global_alloc ( alloc. alloc_id ) . unwrap_memory ( ) ;
215215 self . propagate_from_alloc ( alloc) ;
216216 }
217- Err ( ErrorHandled :: TooGeneric ( span ) ) => span_bug ! (
218- span ,
219- "generic constants aren't implemented in reachability"
220- ) ,
217+ // Reachable generic constants will be inlined into other crates
218+ // unconditionally, so we need to make sure that their
219+ // contents are also reachable.
220+ Err ( ErrorHandled :: TooGeneric ( _ ) ) => self . visit_nested_body ( init ) ,
221221 Err ( ErrorHandled :: Reported ( ..) ) => { }
222222 }
223223 }
0 commit comments