@@ -207,18 +207,20 @@ impl<'tcx> ReachableContext<'tcx> {
207
207
}
208
208
209
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 .
210
+ // Only things actually ending up in the final constant value need to be
211
+ // reachable. Everything else is only needed during const-eval and hence
212
+ // already available as `mir_for_ctfe` .
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
- // Reachable generic constants will be inlined into other crates
219
- // unconditionally, so we need to make sure that their
220
- // contents are also reachable .
218
+ // We can't figure out which value the constant will evaluate to. In
219
+ // lieu of that, we have to consider everything mentioned in the const
220
+ // initializer reachable, since it *may* end up in the final value .
221
221
Err ( ErrorHandled :: TooGeneric ( _) ) => self . visit_nested_body ( init) ,
222
+ // If there was an error evaluating the const, nothing can be reachable
223
+ // via it, and anyway compilation will fail.
222
224
Err ( ErrorHandled :: Reported ( ..) ) => { }
223
225
}
224
226
}
0 commit comments