@@ -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,12 @@ 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
+ // TODO: negative polarity can't have associated type bindings!
705
+
703
706
// Specify type to assert that error was already reported in `Err` case.
704
707
let _: Result < _ , ErrorGuaranteed > = self . add_predicates_for_ast_type_binding (
705
708
hir_id,
@@ -711,6 +714,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
711
714
binding_span. unwrap_or ( binding. span ) ,
712
715
constness,
713
716
only_self_bounds,
717
+ polarity,
714
718
) ;
715
719
// Okay to ignore `Err` because of `ErrorGuaranteed` (see above).
716
720
}
@@ -743,6 +747,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
743
747
trait_ref : & hir:: TraitRef < ' _ > ,
744
748
span : Span ,
745
749
constness : ty:: BoundConstness ,
750
+ polarity : ty:: ImplPolarity ,
746
751
self_ty : Ty < ' tcx > ,
747
752
bounds : & mut Bounds < ' tcx > ,
748
753
speculative : bool ,
@@ -764,6 +769,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
764
769
span,
765
770
binding_span,
766
771
constness,
772
+ polarity,
767
773
bounds,
768
774
speculative,
769
775
trait_ref_span,
@@ -799,6 +805,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
799
805
span,
800
806
binding_span,
801
807
constness,
808
+ ty:: ImplPolarity :: Positive ,
802
809
bounds,
803
810
speculative,
804
811
trait_ref_span,
@@ -961,16 +968,23 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
961
968
for ast_bound in ast_bounds {
962
969
match ast_bound {
963
970
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
+ }
967
981
hir:: TraitBoundModifier :: Maybe => continue ,
968
982
} ;
969
-
970
983
let _ = self . instantiate_poly_trait_ref (
971
984
& poly_trait_ref. trait_ref ,
972
985
poly_trait_ref. span ,
973
986
constness,
987
+ polarity,
974
988
param_ty,
975
989
bounds,
976
990
false ,
@@ -1088,6 +1102,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1088
1102
path_span : Span ,
1089
1103
constness : ty:: BoundConstness ,
1090
1104
only_self_bounds : OnlySelfBounds ,
1105
+ polarity : ty:: ImplPolarity ,
1091
1106
) -> Result < ( ) , ErrorGuaranteed > {
1092
1107
// Given something like `U: SomeTrait<T = X>`, we want to produce a
1093
1108
// predicate like `<U as SomeTrait>::T = X`. This is somewhat
@@ -1438,6 +1453,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1438
1453
& trait_bound. trait_ref ,
1439
1454
trait_bound. span ,
1440
1455
ty:: BoundConstness :: NotConst ,
1456
+ ty:: ImplPolarity :: Positive ,
1441
1457
dummy_self,
1442
1458
& mut bounds,
1443
1459
false ,
0 commit comments