@@ -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,20 @@ 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+ // Don't register additional associated type bounds for negative bounds,
705+ // since we should have emitten an error for them earlier, and they will
706+ // not be well-formed!
707+ if polarity == ty:: ImplPolarity :: Negative {
708+ self . tcx ( )
709+ . sess
710+ . delay_span_bug ( binding. span , "negative trait bounds should not have bindings" ) ;
711+ continue ;
712+ }
713+
703714 // Specify type to assert that error was already reported in `Err` case.
704715 let _: Result < _ , ErrorGuaranteed > = self . add_predicates_for_ast_type_binding (
705716 hir_id,
@@ -711,6 +722,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
711722 binding_span. unwrap_or ( binding. span ) ,
712723 constness,
713724 only_self_bounds,
725+ polarity,
714726 ) ;
715727 // Okay to ignore `Err` because of `ErrorGuaranteed` (see above).
716728 }
@@ -743,6 +755,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
743755 trait_ref : & hir:: TraitRef < ' _ > ,
744756 span : Span ,
745757 constness : ty:: BoundConstness ,
758+ polarity : ty:: ImplPolarity ,
746759 self_ty : Ty < ' tcx > ,
747760 bounds : & mut Bounds < ' tcx > ,
748761 speculative : bool ,
@@ -764,6 +777,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
764777 span,
765778 binding_span,
766779 constness,
780+ polarity,
767781 bounds,
768782 speculative,
769783 trait_ref_span,
@@ -799,6 +813,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
799813 span,
800814 binding_span,
801815 constness,
816+ ty:: ImplPolarity :: Positive ,
802817 bounds,
803818 speculative,
804819 trait_ref_span,
@@ -961,16 +976,23 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
961976 for ast_bound in ast_bounds {
962977 match ast_bound {
963978 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 ,
979+ let ( constness, polarity) = match modifier {
980+ hir:: TraitBoundModifier :: MaybeConst => {
981+ ( ty:: BoundConstness :: ConstIfConst , ty:: ImplPolarity :: Positive )
982+ }
983+ hir:: TraitBoundModifier :: None => {
984+ ( ty:: BoundConstness :: NotConst , ty:: ImplPolarity :: Positive )
985+ }
986+ hir:: TraitBoundModifier :: Negative => {
987+ ( ty:: BoundConstness :: NotConst , ty:: ImplPolarity :: Negative )
988+ }
967989 hir:: TraitBoundModifier :: Maybe => continue ,
968990 } ;
969-
970991 let _ = self . instantiate_poly_trait_ref (
971992 & poly_trait_ref. trait_ref ,
972993 poly_trait_ref. span ,
973994 constness,
995+ polarity,
974996 param_ty,
975997 bounds,
976998 false ,
@@ -1088,6 +1110,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10881110 path_span : Span ,
10891111 constness : ty:: BoundConstness ,
10901112 only_self_bounds : OnlySelfBounds ,
1113+ polarity : ty:: ImplPolarity ,
10911114 ) -> Result < ( ) , ErrorGuaranteed > {
10921115 // Given something like `U: SomeTrait<T = X>`, we want to produce a
10931116 // predicate like `<U as SomeTrait>::T = X`. This is somewhat
@@ -1438,6 +1461,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
14381461 & trait_bound. trait_ref ,
14391462 trait_bound. span ,
14401463 ty:: BoundConstness :: NotConst ,
1464+ ty:: ImplPolarity :: Positive ,
14411465 dummy_self,
14421466 & mut bounds,
14431467 false ,
0 commit comments