@@ -2941,6 +2941,32 @@ impl<'a> Parser<'a> {
29412941 } ;
29422942 Ok ( ( eself, eself_ident, eself_hi) )
29432943 } ;
2944+ let expect_self_ident_not_typed =
2945+ |this : & mut Self , modifier : & SelfKind , modifier_span : Span | {
2946+ let eself_ident = expect_self_ident ( this) ;
2947+
2948+ // Recover `: Type` after a qualified self
2949+ if this. may_recover ( ) && this. eat_noexpect ( & token:: Colon ) {
2950+ let snap = this. create_snapshot_for_diagnostic ( ) ;
2951+ match this. parse_ty ( ) {
2952+ Ok ( ty) => {
2953+ this. dcx ( ) . emit_err ( errors:: IncorrectTypeOnSelf {
2954+ span : ty. span ,
2955+ move_self_modifier : errors:: MoveSelfModifier {
2956+ removal_span : modifier_span,
2957+ insertion_span : ty. span . shrink_to_lo ( ) ,
2958+ modifier : modifier. to_ref_suggestion ( ) ,
2959+ } ,
2960+ } ) ;
2961+ }
2962+ Err ( diag) => {
2963+ diag. cancel ( ) ;
2964+ this. restore_snapshot ( snap) ;
2965+ }
2966+ }
2967+ }
2968+ eself_ident
2969+ } ;
29442970 // Recover for the grammar `*self`, `*const self`, and `*mut self`.
29452971 let recover_self_ptr = |this : & mut Self | {
29462972 this. dcx ( ) . emit_err ( errors:: SelfArgumentPointer { span : this. token . span } ) ;
@@ -2978,7 +3004,9 @@ impl<'a> Parser<'a> {
29783004 // `¬_self`
29793005 return Ok ( None ) ;
29803006 } ;
2981- ( eself, expect_self_ident ( self ) , self . prev_token . span )
3007+ let hi = self . token . span ;
3008+ let self_ident = expect_self_ident_not_typed ( self , & eself, eself_lo. until ( hi) ) ;
3009+ ( eself, self_ident, hi)
29823010 }
29833011 // `*self`
29843012 token:: BinOp ( token:: Star ) if is_isolated_self ( self , 1 ) => {
0 commit comments