@@ -1107,10 +1107,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1107
1107
// const impl
1108
1108
ImplCandidate ( def_id) if tcx. impl_constness ( def_id) == hir:: Constness :: Const => { }
1109
1109
// const param
1110
- ParamCandidate ( ty :: ConstnessAnd {
1111
- constness : ty:: BoundConstness :: ConstIfConst ,
1112
- ..
1113
- } ) => { }
1110
+ ParamCandidate ( (
1111
+ ty :: ConstnessAnd { constness : ty:: BoundConstness :: ConstIfConst , .. } ,
1112
+ _ ,
1113
+ ) ) => { }
1114
1114
// auto trait impl
1115
1115
AutoImplCandidate ( ..) => { }
1116
1116
// generator, this will raise error in other places
@@ -1219,14 +1219,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1219
1219
if self . can_use_global_caches ( param_env) {
1220
1220
if let Some ( res) = tcx
1221
1221
. selection_cache
1222
- . get ( & param_env. and ( trait_ref) . with_constness ( pred. constness ) , tcx)
1222
+ . get ( & ( param_env. and ( trait_ref) . with_constness ( pred. constness ) , pred . polarity ) , tcx)
1223
1223
{
1224
1224
return Some ( res) ;
1225
1225
}
1226
1226
}
1227
1227
self . infcx
1228
1228
. selection_cache
1229
- . get ( & param_env. and ( trait_ref) . with_constness ( pred. constness ) , tcx)
1229
+ . get ( & ( param_env. and ( trait_ref) . with_constness ( pred. constness ) , pred . polarity ) , tcx)
1230
1230
}
1231
1231
1232
1232
/// Determines whether can we safely cache the result
@@ -1286,7 +1286,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1286
1286
debug ! ( ?trait_ref, ?candidate, "insert_candidate_cache global" ) ;
1287
1287
// This may overwrite the cache with the same value.
1288
1288
tcx. selection_cache . insert (
1289
- param_env. and ( trait_ref) . with_constness ( pred. constness ) ,
1289
+ ( param_env. and ( trait_ref) . with_constness ( pred. constness ) , pred . polarity ) ,
1290
1290
dep_node,
1291
1291
candidate,
1292
1292
) ;
@@ -1297,7 +1297,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1297
1297
1298
1298
debug ! ( ?trait_ref, ?candidate, "insert_candidate_cache local" ) ;
1299
1299
self . infcx . selection_cache . insert (
1300
- param_env. and ( trait_ref) . with_constness ( pred. constness ) ,
1300
+ ( param_env. and ( trait_ref) . with_constness ( pred. constness ) , pred . polarity ) ,
1301
1301
dep_node,
1302
1302
candidate,
1303
1303
) ;
@@ -1523,10 +1523,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1523
1523
| ConstDropCandidate ,
1524
1524
) => false ,
1525
1525
1526
- ( ParamCandidate ( other) , ParamCandidate ( victim) ) => {
1526
+ (
1527
+ ParamCandidate ( ( other, other_polarity) ) ,
1528
+ ParamCandidate ( ( victim, victim_polarity) ) ,
1529
+ ) => {
1527
1530
let same_except_bound_vars = other. value . skip_binder ( )
1528
1531
== victim. value . skip_binder ( )
1529
1532
&& other. constness == victim. constness
1533
+ && other_polarity == victim_polarity
1530
1534
&& !other. value . skip_binder ( ) . has_escaping_bound_vars ( ) ;
1531
1535
if same_except_bound_vars {
1532
1536
// See issue #84398. In short, we can generate multiple ParamCandidates which are
@@ -1537,6 +1541,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1537
1541
other. value . bound_vars ( ) . len ( ) <= victim. value . bound_vars ( ) . len ( )
1538
1542
} else if other. value == victim. value
1539
1543
&& victim. constness == ty:: BoundConstness :: NotConst
1544
+ && other_polarity == victim_polarity
1540
1545
{
1541
1546
// Drop otherwise equivalent non-const candidates in favor of const candidates.
1542
1547
true
@@ -1566,11 +1571,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1566
1571
| TraitAliasCandidate ( ..)
1567
1572
| ObjectCandidate ( _)
1568
1573
| ProjectionCandidate ( _) ,
1569
- ) => !is_global ( & cand. value ) ,
1574
+ ) => !is_global ( & cand. 0 . value ) ,
1570
1575
( ObjectCandidate ( _) | ProjectionCandidate ( _) , ParamCandidate ( ref cand) ) => {
1571
1576
// Prefer these to a global where-clause bound
1572
1577
// (see issue #50825).
1573
- is_global ( & cand. value )
1578
+ is_global ( & cand. 0 . value )
1574
1579
}
1575
1580
(
1576
1581
ImplCandidate ( _)
@@ -1586,7 +1591,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1586
1591
) => {
1587
1592
// Prefer these to a global where-clause bound
1588
1593
// (see issue #50825).
1589
- is_global ( & cand. value ) && other. evaluation . must_apply_modulo_regions ( )
1594
+ is_global ( & cand. 0 . value ) && other. evaluation . must_apply_modulo_regions ( )
1590
1595
}
1591
1596
1592
1597
( ProjectionCandidate ( i) , ProjectionCandidate ( j) )
0 commit comments