@@ -1117,8 +1117,30 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1117
1117
( result, dep_node)
1118
1118
}
1119
1119
1120
+ /// filter_impls filters candidates that have a positive impl for a negative goal and a
1121
+ /// negative impl for a positive goal
1120
1122
#[ instrument( level = "debug" , skip( self ) ) ]
1121
1123
fn filter_impls (
1124
+ & mut self ,
1125
+ candidates : & mut Vec < SelectionCandidate < ' tcx > > ,
1126
+ stack : & TraitObligationStack < ' o , ' tcx > ,
1127
+ ) {
1128
+ let tcx = self . tcx ( ) ;
1129
+ candidates. retain ( |candidate| {
1130
+ if let ImplCandidate ( def_id) = candidate {
1131
+ ty:: ImplPolarity :: Reservation == tcx. impl_polarity ( * def_id)
1132
+ || !self . allow_negative_impls
1133
+ && stack. obligation . predicate . skip_binder ( ) . polarity
1134
+ == tcx. impl_polarity ( * def_id)
1135
+ } else {
1136
+ true
1137
+ }
1138
+ } ) ;
1139
+ }
1140
+
1141
+ /// filter_reservation_impls filter reservation impl for any goal as ambiguous
1142
+ #[ instrument( level = "debug" , skip( self ) ) ]
1143
+ fn filter_reservation_impls (
1122
1144
& mut self ,
1123
1145
candidate : SelectionCandidate < ' tcx > ,
1124
1146
obligation : & TraitObligation < ' tcx > ,
@@ -1148,7 +1170,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1148
1170
}
1149
1171
}
1150
1172
}
1151
- // Treat negative impls as unimplemented, and reservation impls as ambiguity.
1173
+ // Treat reservation impls as ambiguity.
1152
1174
if let ImplCandidate ( def_id) = candidate {
1153
1175
if let ty:: ImplPolarity :: Reservation = tcx. impl_polarity ( def_id) {
1154
1176
if let Some ( intercrate_ambiguity_clauses) = & mut self . intercrate_ambiguity_causes {
@@ -1170,12 +1192,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1170
1192
}
1171
1193
return Ok ( None ) ;
1172
1194
}
1173
-
1174
- if !self . allow_negative_impls {
1175
- if obligation. predicate . skip_binder ( ) . polarity != tcx. impl_polarity ( def_id) {
1176
- return Err ( Unimplemented ) ;
1177
- }
1178
- }
1179
1195
}
1180
1196
Ok ( Some ( candidate) )
1181
1197
}
0 commit comments