@@ -6,8 +6,8 @@ use rustc_type_ir::inherent::*;
66use rustc_type_ir:: lang_items:: TraitSolverLangItem ;
77use rustc_type_ir:: solve:: { CanonicalResponse , SizedTraitKind } ;
88use rustc_type_ir:: {
9- self as ty, Interner , Movability , TraitPredicate , TraitRef , TypeVisitableExt as _ , TypingMode ,
10- Upcast as _, elaborate,
9+ self as ty, Interner , Movability , PredicatePolarity , TraitPredicate , TraitRef ,
10+ TypeVisitableExt as _ , TypingMode , Upcast as _, elaborate,
1111} ;
1212use tracing:: { debug, instrument, trace} ;
1313
@@ -133,19 +133,26 @@ where
133133 cx : I ,
134134 clause_def_id : I :: DefId ,
135135 goal_def_id : I :: DefId ,
136+ polarity : PredicatePolarity ,
136137 ) -> bool {
137138 clause_def_id == goal_def_id
138139 // PERF(sized-hierarchy): Sizedness supertraits aren't elaborated to improve perf, so
139140 // check for a `MetaSized` supertrait being matched against a `Sized` assumption.
140141 //
141142 // `PointeeSized` bounds are syntactic sugar for a lack of bounds so don't need this.
142- || ( cx. is_lang_item ( clause_def_id, TraitSolverLangItem :: Sized )
143+ || ( polarity == PredicatePolarity :: Positive
144+ && cx. is_lang_item ( clause_def_id, TraitSolverLangItem :: Sized )
143145 && cx. is_lang_item ( goal_def_id, TraitSolverLangItem :: MetaSized ) )
144146 }
145147
146148 if let Some ( trait_clause) = assumption. as_trait_clause ( )
147149 && trait_clause. polarity ( ) == goal. predicate . polarity
148- && trait_def_id_matches ( ecx. cx ( ) , trait_clause. def_id ( ) , goal. predicate . def_id ( ) )
150+ && trait_def_id_matches (
151+ ecx. cx ( ) ,
152+ trait_clause. def_id ( ) ,
153+ goal. predicate . def_id ( ) ,
154+ goal. predicate . polarity ,
155+ )
149156 && DeepRejectCtxt :: relate_rigid_rigid ( ecx. cx ( ) ) . args_may_unify (
150157 goal. predicate . trait_ref . args ,
151158 trait_clause. skip_binder ( ) . trait_ref . args ,
@@ -168,6 +175,8 @@ where
168175 // PERF(sized-hierarchy): Sizedness supertraits aren't elaborated to improve perf, so
169176 // check for a `Sized` subtrait when looking for `MetaSized`. `PointeeSized` bounds
170177 // are syntactic sugar for a lack of bounds so don't need this.
178+ // We don't need to check polarity, `fast_reject_assumption` already rejected non-`Positive`
179+ // polarity `Sized` assumptions as matching non-`Positive` `MetaSized` goals.
171180 if ecx. cx ( ) . is_lang_item ( goal. predicate . def_id ( ) , TraitSolverLangItem :: MetaSized )
172181 && ecx. cx ( ) . is_lang_item ( trait_clause. def_id ( ) , TraitSolverLangItem :: Sized )
173182 {
0 commit comments