@@ -2941,6 +2941,32 @@ impl<'a> Parser<'a> {
2941
2941
} ;
2942
2942
Ok ( ( eself, eself_ident, eself_hi) )
2943
2943
} ;
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
+ } ;
2944
2970
// Recover for the grammar `*self`, `*const self`, and `*mut self`.
2945
2971
let recover_self_ptr = |this : & mut Self | {
2946
2972
this. dcx ( ) . emit_err ( errors:: SelfArgumentPointer { span : this. token . span } ) ;
@@ -2978,7 +3004,9 @@ impl<'a> Parser<'a> {
2978
3004
// `¬_self`
2979
3005
return Ok ( None ) ;
2980
3006
} ;
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)
2982
3010
}
2983
3011
// `*self`
2984
3012
token:: BinOp ( token:: Star ) if is_isolated_self ( self , 1 ) => {
0 commit comments