@@ -205,22 +205,32 @@ impl<'tcx> ReachableContext<'tcx> {
205205 }
206206
207207 hir:: ItemKind :: Const ( _, _, _, init) => {
208- // Only things actually ending up in the final constant value are reachable
209- // for codegen. Everything else is only needed during const-eval, so even if
210- // const-eval happens in a downstream crate, all they need is
211- // `mir_for_ctfe`.
212- match self . tcx . const_eval_poly_to_alloc ( item. owner_id . def_id . into ( ) ) {
213- Ok ( alloc) => {
214- let alloc = self . tcx . global_alloc ( alloc. alloc_id ) . unwrap_memory ( ) ;
215- self . propagate_from_alloc ( alloc) ;
208+ let predicates = self . tcx . predicates_of ( item. owner_id ) ;
209+
210+ if predicates. predicates . is_empty ( )
211+ || !rustc_trait_selection:: traits:: impossible_predicates (
212+ self . tcx ,
213+ predicates. instantiate_identity ( self . tcx ) . predicates ,
214+ )
215+ {
216+ // Only things actually ending up in the final constant value are reachable
217+ // for codegen. Everything else is only needed during const-eval, so even if
218+ // const-eval happens in a downstream crate, all they need is
219+ // `mir_for_ctfe`.
220+ match self . tcx . const_eval_poly_to_alloc ( item. owner_id . def_id . into ( ) ) {
221+ Ok ( alloc) => {
222+ let alloc =
223+ self . tcx . global_alloc ( alloc. alloc_id ) . unwrap_memory ( ) ;
224+ self . propagate_from_alloc ( alloc) ;
225+ }
226+ // We can't figure out which value the constant will evaluate to. In
227+ // lieu of that, we have to consider everything mentioned in the const
228+ // initializer reachable, since it *may* end up in the final value.
229+ Err ( ErrorHandled :: TooGeneric ( _) ) => self . visit_nested_body ( init) ,
230+ // If there was an error evaluating the const, nothing can be reachable
231+ // via it, and anyway compilation will fail.
232+ Err ( ErrorHandled :: Reported ( ..) ) => { }
216233 }
217- // We can't figure out which value the constant will evaluate to. In
218- // lieu of that, we have to consider everything mentioned in the const
219- // initializer reachable, since it *may* end up in the final value.
220- Err ( ErrorHandled :: TooGeneric ( _) ) => self . visit_nested_body ( init) ,
221- // If there was an error evaluating the const, nothing can be reachable
222- // via it, and anyway compilation will fail.
223- Err ( ErrorHandled :: Reported ( ..) ) => { }
224234 }
225235 }
226236 hir:: ItemKind :: Static ( ..) => {
0 commit comments