@@ -22,7 +22,6 @@ use rustc_middle::ty::{self, ConstKind, Instance, ParamEnv, Ty, TyCtxt, TypeFold
22
22
use rustc_span:: { def_id:: DefId , Span } ;
23
23
use rustc_target:: abi:: { HasDataLayout , Size , TargetDataLayout } ;
24
24
use rustc_target:: spec:: abi:: Abi ;
25
- use rustc_trait_selection:: traits;
26
25
27
26
use crate :: MirPass ;
28
27
use rustc_const_eval:: interpret:: {
@@ -90,41 +89,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
90
89
return ;
91
90
}
92
91
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) {
128
93
trace ! ( "ConstProp skipped for {:?}: found unsatisfiable predicates" , def_id) ;
129
94
return ;
130
95
}
0 commit comments