@@ -22,7 +22,6 @@ use rustc_middle::ty::{self, ConstKind, Instance, ParamEnv, Ty, TyCtxt, TypeFold
2222use rustc_span:: { def_id:: DefId , Span } ;
2323use rustc_target:: abi:: { HasDataLayout , Size , TargetDataLayout } ;
2424use rustc_target:: spec:: abi:: Abi ;
25- use rustc_trait_selection:: traits;
2625
2726use crate :: MirPass ;
2827use rustc_const_eval:: interpret:: {
@@ -90,41 +89,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
9089 return ;
9190 }
9291
93- // Check if it's even possible to satisfy the 'where' clauses
94- // for this item.
95- // This branch will never be taken for any normal function.
96- // However, it's possible to `#!feature(trivial_bounds)]` to write
97- // a function with impossible to satisfy clauses, e.g.:
98- // `fn foo() where String: Copy {}`
99- //
100- // We don't usually need to worry about this kind of case,
101- // since we would get a compilation error if the user tried
102- // to call it. However, since we can do const propagation
103- // even without any calls to the function, we need to make
104- // sure that it even makes sense to try to evaluate the body.
105- // If there are unsatisfiable where clauses, then all bets are
106- // off, and we just give up.
107- //
108- // We manually filter the predicates, skipping anything that's not
109- // "global". We are in a potentially generic context
110- // (e.g. we are evaluating a function without substituting generic
111- // parameters, so this filtering serves two purposes:
112- //
113- // 1. We skip evaluating any predicates that we would
114- // never be able prove are unsatisfiable (e.g. `<T as Foo>`
115- // 2. We avoid trying to normalize predicates involving generic
116- // parameters (e.g. `<T as Foo>::MyItem`). This can confuse
117- // the normalization code (leading to cycle errors), since
118- // it's usually never invoked in this way.
119- let predicates = tcx
120- . predicates_of ( def_id. to_def_id ( ) )
121- . predicates
122- . iter ( )
123- . filter_map ( |( p, _) | if p. is_global ( ) { Some ( * p) } else { None } ) ;
124- if traits:: impossible_predicates (
125- tcx,
126- traits:: elaborate_predicates ( tcx, predicates) . map ( |o| o. predicate ) . collect ( ) ,
127- ) {
92+ if tcx. item_has_impossible_predicates_for_item ( def_id) {
12893 trace ! ( "ConstProp skipped for {:?}: found unsatisfiable predicates" , def_id) ;
12994 return ;
13095 }
0 commit comments