@@ -29,12 +29,12 @@ use rustc_hir::def::{DefKind, Res};
29
29
use rustc_hir:: def_id:: { DefId , LocalDefId } ;
30
30
use rustc_hir:: intravisit:: { self , Visitor } ;
31
31
use rustc_hir:: Node ;
32
+ use rustc_middle:: bug;
32
33
use rustc_middle:: middle:: codegen_fn_attrs:: { CodegenFnAttrFlags , CodegenFnAttrs } ;
33
34
use rustc_middle:: middle:: privacy:: { self , Level } ;
34
35
use rustc_middle:: mir:: interpret:: { ConstAllocation , ErrorHandled , GlobalAlloc } ;
35
36
use rustc_middle:: query:: Providers ;
36
37
use rustc_middle:: ty:: { self , ExistentialTraitRef , TyCtxt } ;
37
- use rustc_middle:: { bug, span_bug} ;
38
38
use rustc_privacy:: DefIdVisitor ;
39
39
use rustc_session:: config:: CrateType ;
40
40
use tracing:: debug;
@@ -206,19 +206,19 @@ impl<'tcx> ReachableContext<'tcx> {
206
206
}
207
207
}
208
208
209
- // Reachable constants will be inlined into other crates
210
- // unconditionally, so we need to make sure that their
211
- // contents are also reachable.
212
- hir :: ItemKind :: Const ( .. ) => {
209
+ hir :: ItemKind :: Const ( _ , _ , init ) => {
210
+ // Only things actually ending up in the final constant need to be reachable.
211
+ // Everything else is either already available as `mir_for_ctfe`, or can't be used
212
+ // by codegen anyway.
213
213
match self . tcx . const_eval_poly_to_alloc ( item. owner_id . def_id . into ( ) ) {
214
214
Ok ( alloc) => {
215
215
let alloc = self . tcx . global_alloc ( alloc. alloc_id ) . unwrap_memory ( ) ;
216
216
self . propagate_from_alloc ( alloc) ;
217
217
}
218
- Err ( ErrorHandled :: TooGeneric ( span ) ) => span_bug ! (
219
- span ,
220
- "generic constants aren't implemented in reachability"
221
- ) ,
218
+ // Reachable generic constants will be inlined into other crates
219
+ // unconditionally, so we need to make sure that their
220
+ // contents are also reachable.
221
+ Err ( ErrorHandled :: TooGeneric ( _ ) ) => self . visit_nested_body ( init ) ,
222
222
Err ( ErrorHandled :: Reported ( ..) ) => { }
223
223
}
224
224
}
0 commit comments