@@ -753,18 +753,13 @@ impl<'a> Parser<'a> {
753
753
}
754
754
let kind = if self . eat ( exp ! ( Colon ) ) {
755
755
AssocItemConstraintKind :: Bound { bounds : self . parse_generic_bounds ( ) ? }
756
- } else if self . eat ( exp ! ( Eq ) ) {
757
- self . parse_assoc_equality_term (
758
- ident,
759
- gen_args. as_ref ( ) ,
760
- self . prev_token . span ,
761
- ) ?
756
+ } else if self . check ( exp ! ( Eq ) ) {
757
+ self . parse_assoc_equality_term ( ident, gen_args. as_ref ( ) ) ?
762
758
} else {
763
759
unreachable ! ( ) ;
764
760
} ;
765
761
766
762
let span = lo. to ( self . prev_token . span ) ;
767
-
768
763
let constraint =
769
764
AssocItemConstraint { id : ast:: DUMMY_NODE_ID , ident, gen_args, kind, span } ;
770
765
Ok ( Some ( AngleBracketedArg :: Constraint ( constraint) ) )
@@ -792,8 +787,10 @@ impl<'a> Parser<'a> {
792
787
& mut self ,
793
788
ident : Ident ,
794
789
gen_args : Option < & GenericArgs > ,
795
- eq : Span ,
796
790
) -> PResult < ' a , AssocItemConstraintKind > {
791
+ let prev_token_span = self . prev_token . span ;
792
+ let eq_span = self . token . span ;
793
+ self . expect ( exp ! ( Eq ) ) ?;
797
794
let arg = self . parse_generic_arg ( None ) ?;
798
795
let span = ident. span . to ( self . prev_token . span ) ;
799
796
let term = match arg {
@@ -814,20 +811,20 @@ impl<'a> Parser<'a> {
814
811
self . mk_ty ( lt. ident . span , ast:: TyKind :: Err ( guar) ) . into ( )
815
812
}
816
813
None => {
817
- let after_eq = eq . shrink_to_hi ( ) ;
814
+ let after_eq = eq_span . shrink_to_hi ( ) ;
818
815
let before_next = self . token . span . shrink_to_lo ( ) ;
819
816
let mut err = self
820
817
. dcx ( )
821
818
. struct_span_err ( after_eq. to ( before_next) , "missing type to the right of `=`" ) ;
822
819
if matches ! ( self . token. kind, token:: Comma | token:: Gt ) {
823
820
err. span_suggestion (
824
- self . psess . source_map ( ) . next_point ( eq ) . to ( before_next) ,
821
+ self . psess . source_map ( ) . next_point ( eq_span ) . to ( before_next) ,
825
822
"to constrain the associated type, add a type after `=`" ,
826
823
" TheType" ,
827
824
Applicability :: HasPlaceholders ,
828
825
) ;
829
826
err. span_suggestion (
830
- eq . to ( before_next) ,
827
+ prev_token_span . shrink_to_hi ( ) . to ( before_next) ,
831
828
format ! ( "remove the `=` if `{ident}` is a type" ) ,
832
829
"" ,
833
830
Applicability :: MaybeIncorrect ,
0 commit comments