@@ -2,7 +2,7 @@ use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign};
22use super :: { Parser , Restrictions , TokenType } ;
33use crate :: maybe_whole;
44use rustc_ast:: ptr:: P ;
5- use rustc_ast:: token:: { self , Delimiter , Token } ;
5+ use rustc_ast:: token:: { self , Delimiter , Token , TokenKind } ;
66use rustc_ast:: {
77 self as ast, AngleBracketedArg , AngleBracketedArgs , AnonConst , AssocConstraint ,
88 AssocConstraintKind , BlockCheckMode , GenericArg , GenericArgs , Generics , ParenthesizedArgs ,
@@ -96,7 +96,7 @@ impl<'a> Parser<'a> {
9696 /// ^ help: use double colon
9797 /// ```
9898 fn recover_colon_before_qpath_proj ( & mut self ) -> bool {
99- if self . token . kind != token :: Colon
99+ if ! self . check_noexpect ( & TokenKind :: Colon )
100100 || self . look_ahead ( 1 , |t| !t. is_ident ( ) || t. is_reserved_ident ( ) )
101101 {
102102 return false ;
@@ -478,7 +478,7 @@ impl<'a> Parser<'a> {
478478 while let Some ( arg) = self . parse_angle_arg ( ty_generics) ? {
479479 args. push ( arg) ;
480480 if !self . eat ( & token:: Comma ) {
481- if self . token . kind == token :: Semi
481+ if self . check_noexpect ( & TokenKind :: Semi )
482482 && self . look_ahead ( 1 , |t| t. is_ident ( ) || t. is_lifetime ( ) )
483483 {
484484 // Add `>` to the list of expected tokens.
@@ -517,7 +517,11 @@ impl<'a> Parser<'a> {
517517 let arg = self . parse_generic_arg ( ty_generics) ?;
518518 match arg {
519519 Some ( arg) => {
520- if self . check ( & token:: Colon ) | self . check ( & token:: Eq ) {
520+ // we are using noexpect here because we first want to find out if either `=` or `:`
521+ // is present and then use that info to push the other token onto the tokens list
522+ let separated =
523+ self . check_noexpect ( & token:: Colon ) || self . check_noexpect ( & token:: Eq ) ;
524+ if separated && ( self . check ( & token:: Colon ) | self . check ( & token:: Eq ) ) {
521525 let arg_span = arg. span ( ) ;
522526 let ( binder, ident, gen_args) = match self . get_ident_from_generic_arg ( & arg) {
523527 Ok ( ident_gen_args) => ident_gen_args,
@@ -553,6 +557,14 @@ impl<'a> Parser<'a> {
553557 AssocConstraint { id : ast:: DUMMY_NODE_ID , ident, gen_args, kind, span } ;
554558 Ok ( Some ( AngleBracketedArg :: Constraint ( constraint) ) )
555559 } else {
560+ // we only want to suggest `:` and `=` in contexts where the previous token
561+ // is an ident and the current token or the next token is an ident
562+ if self . prev_token . is_ident ( )
563+ && ( self . token . is_ident ( ) || self . look_ahead ( 1 , |token| token. is_ident ( ) ) )
564+ {
565+ self . check ( & token:: Colon ) ;
566+ self . check ( & token:: Eq ) ;
567+ }
556568 Ok ( Some ( AngleBracketedArg :: Arg ( arg) ) )
557569 }
558570 }
0 commit comments