@@ -665,6 +665,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
665
665
span : Span ,
666
666
binding_span : Option < Span > ,
667
667
constness : ty:: BoundConstness ,
668
+ polarity : ty:: ImplPolarity ,
668
669
bounds : & mut Bounds < ' tcx > ,
669
670
speculative : bool ,
670
671
trait_ref_span : Span ,
@@ -696,10 +697,20 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
696
697
ty:: Binder :: bind_with_vars ( tcx. mk_trait_ref ( trait_def_id, substs) , bound_vars) ;
697
698
698
699
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 ) ;
700
701
701
702
let mut dup_bindings = FxHashMap :: default ( ) ;
702
703
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
+
703
714
// Specify type to assert that error was already reported in `Err` case.
704
715
let _: Result < _ , ErrorGuaranteed > = self . add_predicates_for_ast_type_binding (
705
716
hir_id,
@@ -711,6 +722,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
711
722
binding_span. unwrap_or ( binding. span ) ,
712
723
constness,
713
724
only_self_bounds,
725
+ polarity,
714
726
) ;
715
727
// Okay to ignore `Err` because of `ErrorGuaranteed` (see above).
716
728
}
@@ -743,6 +755,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
743
755
trait_ref : & hir:: TraitRef < ' _ > ,
744
756
span : Span ,
745
757
constness : ty:: BoundConstness ,
758
+ polarity : ty:: ImplPolarity ,
746
759
self_ty : Ty < ' tcx > ,
747
760
bounds : & mut Bounds < ' tcx > ,
748
761
speculative : bool ,
@@ -764,6 +777,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
764
777
span,
765
778
binding_span,
766
779
constness,
780
+ polarity,
767
781
bounds,
768
782
speculative,
769
783
trait_ref_span,
@@ -799,6 +813,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
799
813
span,
800
814
binding_span,
801
815
constness,
816
+ ty:: ImplPolarity :: Positive ,
802
817
bounds,
803
818
speculative,
804
819
trait_ref_span,
@@ -961,16 +976,23 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
961
976
for ast_bound in ast_bounds {
962
977
match ast_bound {
963
978
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
+ }
967
989
hir:: TraitBoundModifier :: Maybe => continue ,
968
990
} ;
969
-
970
991
let _ = self . instantiate_poly_trait_ref (
971
992
& poly_trait_ref. trait_ref ,
972
993
poly_trait_ref. span ,
973
994
constness,
995
+ polarity,
974
996
param_ty,
975
997
bounds,
976
998
false ,
@@ -1088,6 +1110,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1088
1110
path_span : Span ,
1089
1111
constness : ty:: BoundConstness ,
1090
1112
only_self_bounds : OnlySelfBounds ,
1113
+ polarity : ty:: ImplPolarity ,
1091
1114
) -> Result < ( ) , ErrorGuaranteed > {
1092
1115
// Given something like `U: SomeTrait<T = X>`, we want to produce a
1093
1116
// predicate like `<U as SomeTrait>::T = X`. This is somewhat
@@ -1438,6 +1461,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1438
1461
& trait_bound. trait_ref ,
1439
1462
trait_bound. span ,
1440
1463
ty:: BoundConstness :: NotConst ,
1464
+ ty:: ImplPolarity :: Positive ,
1441
1465
dummy_self,
1442
1466
& mut bounds,
1443
1467
false ,
0 commit comments