@@ -86,8 +86,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
86
86
) -> QueryResult < ' tcx > {
87
87
if let Some ( poly_trait_pred) = assumption. to_opt_poly_trait_pred ( )
88
88
&& poly_trait_pred. def_id ( ) == goal. predicate . def_id ( )
89
+ && poly_trait_pred. polarity ( ) == goal. predicate . polarity
89
90
{
90
- // FIXME: Constness and polarity
91
+ // FIXME: Constness
91
92
ecx. probe ( |ecx| {
92
93
let assumption_trait_pred =
93
94
ecx. instantiate_binder_with_infer ( poly_trait_pred) ;
@@ -111,6 +112,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
111
112
) -> QueryResult < ' tcx > {
112
113
if let Some ( poly_trait_pred) = assumption. to_opt_poly_trait_pred ( )
113
114
&& poly_trait_pred. def_id ( ) == goal. predicate . def_id ( )
115
+ && poly_trait_pred. polarity ( ) == goal. predicate . polarity
114
116
{
115
117
// FIXME: Constness and polarity
116
118
ecx. probe ( |ecx| {
@@ -147,6 +149,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
147
149
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
148
150
goal : Goal < ' tcx , Self > ,
149
151
) -> QueryResult < ' tcx > {
152
+ if goal. predicate . polarity != ty:: ImplPolarity :: Positive {
153
+ return Err ( NoSolution ) ;
154
+ }
155
+
150
156
if let Some ( result) = ecx. disqualify_auto_trait_candidate_due_to_possible_impl ( goal) {
151
157
return result;
152
158
}
@@ -161,6 +167,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
161
167
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
162
168
goal : Goal < ' tcx , Self > ,
163
169
) -> QueryResult < ' tcx > {
170
+ if goal. predicate . polarity != ty:: ImplPolarity :: Positive {
171
+ return Err ( NoSolution ) ;
172
+ }
173
+
164
174
let tcx = ecx. tcx ( ) ;
165
175
166
176
ecx. probe ( |ecx| {
@@ -176,6 +186,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
176
186
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
177
187
goal : Goal < ' tcx , Self > ,
178
188
) -> QueryResult < ' tcx > {
189
+ if goal. predicate . polarity != ty:: ImplPolarity :: Positive {
190
+ return Err ( NoSolution ) ;
191
+ }
192
+
179
193
ecx. probe_and_evaluate_goal_for_constituent_tys (
180
194
goal,
181
195
structural_traits:: instantiate_constituent_tys_for_sized_trait,
@@ -186,6 +200,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
186
200
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
187
201
goal : Goal < ' tcx , Self > ,
188
202
) -> QueryResult < ' tcx > {
203
+ if goal. predicate . polarity != ty:: ImplPolarity :: Positive {
204
+ return Err ( NoSolution ) ;
205
+ }
206
+
189
207
ecx. probe_and_evaluate_goal_for_constituent_tys (
190
208
goal,
191
209
structural_traits:: instantiate_constituent_tys_for_copy_clone_trait,
@@ -196,6 +214,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
196
214
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
197
215
goal : Goal < ' tcx , Self > ,
198
216
) -> QueryResult < ' tcx > {
217
+ if goal. predicate . polarity != ty:: ImplPolarity :: Positive {
218
+ return Err ( NoSolution ) ;
219
+ }
220
+
199
221
if goal. predicate . self_ty ( ) . has_non_region_infer ( ) {
200
222
return ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: AMBIGUOUS ) ;
201
223
}
@@ -217,6 +239,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
217
239
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
218
240
goal : Goal < ' tcx , Self > ,
219
241
) -> QueryResult < ' tcx > {
242
+ if goal. predicate . polarity != ty:: ImplPolarity :: Positive {
243
+ return Err ( NoSolution ) ;
244
+ }
245
+
220
246
if let ty:: FnPtr ( ..) = goal. predicate . self_ty ( ) . kind ( ) {
221
247
ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
222
248
} else {
@@ -229,6 +255,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
229
255
goal : Goal < ' tcx , Self > ,
230
256
goal_kind : ty:: ClosureKind ,
231
257
) -> QueryResult < ' tcx > {
258
+ if goal. predicate . polarity != ty:: ImplPolarity :: Positive {
259
+ return Err ( NoSolution ) ;
260
+ }
261
+
232
262
let tcx = ecx. tcx ( ) ;
233
263
let tupled_inputs_and_output =
234
264
match structural_traits:: extract_tupled_inputs_and_output_from_callable (
@@ -259,6 +289,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
259
289
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
260
290
goal : Goal < ' tcx , Self > ,
261
291
) -> QueryResult < ' tcx > {
292
+ if goal. predicate . polarity != ty:: ImplPolarity :: Positive {
293
+ return Err ( NoSolution ) ;
294
+ }
295
+
262
296
if let ty:: Tuple ( ..) = goal. predicate . self_ty ( ) . kind ( ) {
263
297
ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
264
298
} else {
@@ -268,15 +302,23 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
268
302
269
303
fn consider_builtin_pointee_candidate (
270
304
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
271
- _goal : Goal < ' tcx , Self > ,
305
+ goal : Goal < ' tcx , Self > ,
272
306
) -> QueryResult < ' tcx > {
307
+ if goal. predicate . polarity != ty:: ImplPolarity :: Positive {
308
+ return Err ( NoSolution ) ;
309
+ }
310
+
273
311
ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
274
312
}
275
313
276
314
fn consider_builtin_future_candidate (
277
315
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
278
316
goal : Goal < ' tcx , Self > ,
279
317
) -> QueryResult < ' tcx > {
318
+ if goal. predicate . polarity != ty:: ImplPolarity :: Positive {
319
+ return Err ( NoSolution ) ;
320
+ }
321
+
280
322
let ty:: Generator ( def_id, _, _) = * goal. predicate . self_ty ( ) . kind ( ) else {
281
323
return Err ( NoSolution ) ;
282
324
} ;
@@ -297,6 +339,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
297
339
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
298
340
goal : Goal < ' tcx , Self > ,
299
341
) -> QueryResult < ' tcx > {
342
+ if goal. predicate . polarity != ty:: ImplPolarity :: Positive {
343
+ return Err ( NoSolution ) ;
344
+ }
345
+
300
346
let self_ty = goal. predicate . self_ty ( ) ;
301
347
let ty:: Generator ( def_id, substs, _) = * self_ty. kind ( ) else {
302
348
return Err ( NoSolution ) ;
@@ -326,6 +372,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
326
372
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
327
373
goal : Goal < ' tcx , Self > ,
328
374
) -> QueryResult < ' tcx > {
375
+ if goal. predicate . polarity != ty:: ImplPolarity :: Positive {
376
+ return Err ( NoSolution ) ;
377
+ }
378
+
329
379
let tcx = ecx. tcx ( ) ;
330
380
let a_ty = goal. predicate . self_ty ( ) ;
331
381
let b_ty = goal. predicate . trait_ref . substs . type_at ( 1 ) ;
@@ -447,6 +497,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
447
497
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
448
498
goal : Goal < ' tcx , Self > ,
449
499
) -> Vec < CanonicalResponse < ' tcx > > {
500
+ if goal. predicate . polarity != ty:: ImplPolarity :: Positive {
501
+ return vec ! [ ] ;
502
+ }
503
+
450
504
let tcx = ecx. tcx ( ) ;
451
505
452
506
let a_ty = goal. predicate . self_ty ( ) ;
@@ -521,8 +575,12 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
521
575
522
576
fn consider_builtin_discriminant_kind_candidate (
523
577
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
524
- _goal : Goal < ' tcx , Self > ,
578
+ goal : Goal < ' tcx , Self > ,
525
579
) -> QueryResult < ' tcx > {
580
+ if goal. predicate . polarity != ty:: ImplPolarity :: Positive {
581
+ return Err ( NoSolution ) ;
582
+ }
583
+
526
584
// `DiscriminantKind` is automatically implemented for every type.
527
585
ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
528
586
}
@@ -531,6 +589,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
531
589
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
532
590
goal : Goal < ' tcx , Self > ,
533
591
) -> QueryResult < ' tcx > {
592
+ if goal. predicate . polarity != ty:: ImplPolarity :: Positive {
593
+ return Err ( NoSolution ) ;
594
+ }
595
+
534
596
if !goal. param_env . is_const ( ) {
535
597
// `Destruct` is automatically implemented for every type in
536
598
// non-const environments.
@@ -545,6 +607,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
545
607
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
546
608
goal : Goal < ' tcx , Self > ,
547
609
) -> QueryResult < ' tcx > {
610
+ if goal. predicate . polarity != ty:: ImplPolarity :: Positive {
611
+ return Err ( NoSolution ) ;
612
+ }
613
+
548
614
// `rustc_transmute` does not have support for type or const params
549
615
if goal. has_non_region_placeholders ( ) {
550
616
return Err ( NoSolution ) ;
0 commit comments