@@ -665,6 +665,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
665665 span : Span ,
666666 binding_span : Option < Span > ,
667667 constness : ty:: BoundConstness ,
668+ polarity : ty:: ImplPolarity ,
668669 bounds : & mut Bounds < ' tcx > ,
669670 speculative : bool ,
670671 trait_ref_span : Span ,
@@ -696,10 +697,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
696697 ty:: Binder :: bind_with_vars ( tcx. mk_trait_ref ( trait_def_id, substs) , bound_vars) ;
697698
698699 debug ! ( ?poly_trait_ref, ?assoc_bindings) ;
699- bounds. push_trait_bound ( tcx, poly_trait_ref, span, constness) ;
700+ bounds. push_trait_bound ( tcx, poly_trait_ref, span, constness, polarity ) ;
700701
701702 let mut dup_bindings = FxHashMap :: default ( ) ;
702703 for binding in & assoc_bindings {
704+ // TODO: negative polarity can't have associated type bindings!
705+
703706 // Specify type to assert that error was already reported in `Err` case.
704707 let _: Result < _ , ErrorGuaranteed > = self . add_predicates_for_ast_type_binding (
705708 hir_id,
@@ -711,6 +714,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
711714 binding_span. unwrap_or ( binding. span ) ,
712715 constness,
713716 only_self_bounds,
717+ polarity,
714718 ) ;
715719 // Okay to ignore `Err` because of `ErrorGuaranteed` (see above).
716720 }
@@ -743,6 +747,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
743747 trait_ref : & hir:: TraitRef < ' _ > ,
744748 span : Span ,
745749 constness : ty:: BoundConstness ,
750+ polarity : ty:: ImplPolarity ,
746751 self_ty : Ty < ' tcx > ,
747752 bounds : & mut Bounds < ' tcx > ,
748753 speculative : bool ,
@@ -764,6 +769,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
764769 span,
765770 binding_span,
766771 constness,
772+ polarity,
767773 bounds,
768774 speculative,
769775 trait_ref_span,
@@ -799,6 +805,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
799805 span,
800806 binding_span,
801807 constness,
808+ ty:: ImplPolarity :: Positive ,
802809 bounds,
803810 speculative,
804811 trait_ref_span,
@@ -961,16 +968,23 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
961968 for ast_bound in ast_bounds {
962969 match ast_bound {
963970 hir:: GenericBound :: Trait ( poly_trait_ref, modifier) => {
964- let constness = match modifier {
965- hir:: TraitBoundModifier :: MaybeConst => ty:: BoundConstness :: ConstIfConst ,
966- hir:: TraitBoundModifier :: None => ty:: BoundConstness :: NotConst ,
971+ let ( constness, polarity) = match modifier {
972+ hir:: TraitBoundModifier :: MaybeConst => {
973+ ( ty:: BoundConstness :: ConstIfConst , ty:: ImplPolarity :: Positive )
974+ }
975+ hir:: TraitBoundModifier :: None => {
976+ ( ty:: BoundConstness :: NotConst , ty:: ImplPolarity :: Positive )
977+ }
978+ hir:: TraitBoundModifier :: Negative => {
979+ ( ty:: BoundConstness :: NotConst , ty:: ImplPolarity :: Negative )
980+ }
967981 hir:: TraitBoundModifier :: Maybe => continue ,
968982 } ;
969-
970983 let _ = self . instantiate_poly_trait_ref (
971984 & poly_trait_ref. trait_ref ,
972985 poly_trait_ref. span ,
973986 constness,
987+ polarity,
974988 param_ty,
975989 bounds,
976990 false ,
@@ -1088,6 +1102,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10881102 path_span : Span ,
10891103 constness : ty:: BoundConstness ,
10901104 only_self_bounds : OnlySelfBounds ,
1105+ polarity : ty:: ImplPolarity ,
10911106 ) -> Result < ( ) , ErrorGuaranteed > {
10921107 // Given something like `U: SomeTrait<T = X>`, we want to produce a
10931108 // predicate like `<U as SomeTrait>::T = X`. This is somewhat
@@ -1438,6 +1453,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
14381453 & trait_bound. trait_ref ,
14391454 trait_bound. span ,
14401455 ty:: BoundConstness :: NotConst ,
1456+ ty:: ImplPolarity :: Positive ,
14411457 dummy_self,
14421458 & mut bounds,
14431459 false ,
0 commit comments