@@ -8,7 +8,9 @@ use crate::infer::{CombinedSnapshot, InferOk, TyCtxtInferExt};
8
8
use crate :: traits:: query:: evaluate_obligation:: InferCtxtExt ;
9
9
use crate :: traits:: select:: IntercrateAmbiguityCause ;
10
10
use crate :: traits:: SkipLeakCheck ;
11
- use crate :: traits:: { self , Normalized , Obligation , ObligationCause , SelectionContext } ;
11
+ use crate :: traits:: {
12
+ self , Normalized , Obligation , ObligationCause , PredicateObligation , SelectionContext ,
13
+ } ;
12
14
use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
13
15
use rustc_middle:: ty:: fold:: TypeFoldable ;
14
16
use rustc_middle:: ty:: subst:: Subst ;
@@ -159,6 +161,19 @@ fn overlap_within_probe(
159
161
b_def_id : DefId ,
160
162
snapshot : & CombinedSnapshot < ' _ , ' tcx > ,
161
163
) -> Option < OverlapResult < ' tcx > > {
164
+ fn loose_check ( selcx : & mut SelectionContext < ' cx , ' tcx > , o : & PredicateObligation < ' tcx > ) -> bool {
165
+ !selcx. predicate_may_hold_fatal ( o)
166
+ }
167
+
168
+ fn strict_check ( selcx : & SelectionContext < ' cx , ' tcx > , o : & PredicateObligation < ' tcx > ) -> bool {
169
+ let infcx = selcx. infcx ( ) ;
170
+ let tcx = infcx. tcx ;
171
+ o. flip_polarity ( tcx)
172
+ . as_ref ( )
173
+ . map ( |o| selcx. infcx ( ) . predicate_must_hold_modulo_regions ( o) )
174
+ . unwrap_or ( false )
175
+ }
176
+
162
177
// For the purposes of this check, we don't bring any placeholder
163
178
// types into scope; instead, we replace the generic types with
164
179
// fresh type variables, and hence we do our evaluations in an
@@ -227,17 +242,9 @@ fn overlap_within_probe(
227
242
if tcx. has_attr ( a_def_id, sym:: rustc_strict_coherence)
228
243
&& tcx. has_attr ( b_def_id, sym:: rustc_strict_coherence)
229
244
{
230
- o. flip_polarity ( tcx)
231
- . as_ref ( )
232
- . map ( |o| selcx. infcx ( ) . predicate_must_hold_modulo_regions ( o) )
233
- . unwrap_or ( false )
245
+ strict_check ( selcx, o)
234
246
} else {
235
- !selcx. predicate_may_hold_fatal ( o)
236
- || tcx. features ( ) . negative_impls
237
- && o. flip_polarity ( tcx)
238
- . as_ref ( )
239
- . map ( |o| selcx. infcx ( ) . predicate_must_hold_modulo_regions ( o) )
240
- . unwrap_or ( false )
247
+ loose_check ( selcx, o) || tcx. features ( ) . negative_impls && strict_check ( selcx, o)
241
248
}
242
249
} ) ;
243
250
// FIXME: the call to `selcx.predicate_may_hold_fatal` above should be ported
0 commit comments