@@ -2774,6 +2774,33 @@ impl<'a> Parser<'a> {
27742774 } ;
27752775 Ok ( ( eself, eself_ident, eself_hi) )
27762776 } ;
2777+ let expect_self_ident_not_typed =
2778+ |this : & mut Self , modifier : & SelfKind , modifier_span : Span | {
2779+ let eself_ident = expect_self_ident ( this) ;
2780+
2781+ // Recover `: Type` after a qualified self
2782+ if this. may_recover ( ) && this. check_noexpect ( & token:: Colon ) {
2783+ this. bump ( ) ;
2784+ let snap = this. create_snapshot_for_diagnostic ( ) ;
2785+ match this. parse_ty ( ) {
2786+ Ok ( ty) => {
2787+ this. dcx ( ) . emit_err ( errors:: IncorrectTypeOnSelf {
2788+ span : ty. span ,
2789+ move_self_modifier : errors:: MoveSelfModifier {
2790+ removal_span : modifier_span,
2791+ insertion_span : ty. span . shrink_to_lo ( ) ,
2792+ modifier : modifier. as_suggestion ( ) ,
2793+ } ,
2794+ } ) ;
2795+ }
2796+ Err ( diag) => {
2797+ diag. cancel ( ) ;
2798+ this. restore_snapshot ( snap) ;
2799+ }
2800+ }
2801+ }
2802+ eself_ident
2803+ } ;
27772804 // Recover for the grammar `*self`, `*const self`, and `*mut self`.
27782805 let recover_self_ptr = |this : & mut Self | {
27792806 this. dcx ( ) . emit_err ( errors:: SelfArgumentPointer { span : this. token . span } ) ;
@@ -2787,6 +2814,7 @@ impl<'a> Parser<'a> {
27872814 let eself_lo = self . token . span ;
27882815 let ( eself, eself_ident, eself_hi) = match self . token . uninterpolate ( ) . kind {
27892816 token:: BinOp ( token:: And ) => {
2817+ let lo = self . token . span ;
27902818 let eself = if is_isolated_self ( self , 1 ) {
27912819 // `&self`
27922820 self . bump ( ) ;
@@ -2811,7 +2839,9 @@ impl<'a> Parser<'a> {
28112839 // `¬_self`
28122840 return Ok ( None ) ;
28132841 } ;
2814- ( eself, expect_self_ident ( self ) , self . prev_token . span )
2842+ let hi = self . token . span ;
2843+ let self_ident = expect_self_ident_not_typed ( self , & eself, lo. until ( hi) ) ;
2844+ ( eself, self_ident, hi)
28152845 }
28162846 // `*self`
28172847 token:: BinOp ( token:: Star ) if is_isolated_self ( self , 1 ) => {
0 commit comments