@@ -207,18 +207,21 @@ 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 are reachable
211
+ // for codegen. Everything else is only needed during const-eval, so even if
212
+ // const-eval happens in a downstream crate, all they need is
213
+ // `mir_for_ctfe`.
213
214
match self . tcx . const_eval_poly_to_alloc ( item. owner_id . def_id . into ( ) ) {
214
215
Ok ( alloc) => {
215
216
let alloc = self . tcx . global_alloc ( alloc. alloc_id ) . unwrap_memory ( ) ;
216
217
self . propagate_from_alloc ( alloc) ;
217
218
}
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 .
219
+ // We can't figure out which value the constant will evaluate to. In
220
+ // lieu of that, we have to consider everything mentioned in the const
221
+ // initializer reachable, since it *may* end up in the final value .
221
222
Err ( ErrorHandled :: TooGeneric ( _) ) => self . visit_nested_body ( init) ,
223
+ // If there was an error evaluating the const, nothing can be reachable
224
+ // via it, and anyway compilation will fail.
222
225
Err ( ErrorHandled :: Reported ( ..) ) => { }
223
226
}
224
227
}
0 commit comments