@@ -2959,9 +2959,20 @@ impl<'a> Parser<'a> {
2959
2959
this. is_keyword_ahead ( n, & [ kw:: SelfLower ] )
2960
2960
&& this. look_ahead ( n + 1 , |t| t != & token:: PathSep )
2961
2961
} ;
2962
+ // Is `pin const self` `n` tokens ahead?
2963
+ let is_isolated_pin_const_self = |this : & Self , n| {
2964
+ this. look_ahead ( n, |token| token. is_ident_named ( sym:: pin) )
2965
+ && this. is_keyword_ahead ( n + 1 , & [ kw:: Const ] )
2966
+ && is_isolated_self ( this, n + 2 )
2967
+ } ;
2962
2968
// Is `mut self` `n` tokens ahead?
2963
2969
let is_isolated_mut_self =
2964
2970
|this : & Self , n| this. is_keyword_ahead ( n, & [ kw:: Mut ] ) && is_isolated_self ( this, n + 1 ) ;
2971
+ // Is `pin mut self` `n` tokens ahead?
2972
+ let is_isolated_pin_mut_self = |this : & Self , n| {
2973
+ this. look_ahead ( n, |token| token. is_ident_named ( sym:: pin) )
2974
+ && is_isolated_mut_self ( this, n + 1 )
2975
+ } ;
2965
2976
// Parse `self` or `self: TYPE`. We already know the current token is `self`.
2966
2977
let parse_self_possibly_typed = |this : & mut Self , m| {
2967
2978
let eself_ident = expect_self_ident ( this) ;
@@ -3021,6 +3032,20 @@ impl<'a> Parser<'a> {
3021
3032
self . bump ( ) ;
3022
3033
self . bump ( ) ;
3023
3034
SelfKind :: Region ( None , Mutability :: Mut )
3035
+ } else if is_isolated_pin_const_self ( self , 1 ) {
3036
+ // `&pin const self`
3037
+ self . bump ( ) ; // &
3038
+ self . psess . gated_spans . gate ( sym:: pin_ergonomics, self . token . span ) ;
3039
+ self . bump ( ) ; // pin
3040
+ self . bump ( ) ; // const
3041
+ SelfKind :: Pinned ( None , Mutability :: Not )
3042
+ } else if is_isolated_pin_mut_self ( self , 1 ) {
3043
+ // `&pin mut self`
3044
+ self . bump ( ) ; // &
3045
+ self . psess . gated_spans . gate ( sym:: pin_ergonomics, self . token . span ) ;
3046
+ self . bump ( ) ; // pin
3047
+ self . bump ( ) ; // mut
3048
+ SelfKind :: Pinned ( None , Mutability :: Mut )
3024
3049
} else if self . look_ahead ( 1 , |t| t. is_lifetime ( ) ) && is_isolated_self ( self , 2 ) {
3025
3050
// `&'lt self`
3026
3051
self . bump ( ) ;
@@ -3032,6 +3057,26 @@ impl<'a> Parser<'a> {
3032
3057
let lt = self . expect_lifetime ( ) ;
3033
3058
self . bump ( ) ;
3034
3059
SelfKind :: Region ( Some ( lt) , Mutability :: Mut )
3060
+ } else if self . look_ahead ( 1 , |t| t. is_lifetime ( ) )
3061
+ && is_isolated_pin_const_self ( self , 2 )
3062
+ {
3063
+ // `&'lt pin const self`
3064
+ self . bump ( ) ; // &
3065
+ let lt = self . expect_lifetime ( ) ;
3066
+ self . psess . gated_spans . gate ( sym:: pin_ergonomics, self . token . span ) ;
3067
+ self . bump ( ) ; // pin
3068
+ self . bump ( ) ; // const
3069
+ SelfKind :: Pinned ( Some ( lt) , Mutability :: Not )
3070
+ } else if self . look_ahead ( 1 , |t| t. is_lifetime ( ) )
3071
+ && is_isolated_pin_mut_self ( self , 2 )
3072
+ {
3073
+ // `&'lt pin mut self`
3074
+ self . bump ( ) ; // &
3075
+ let lt = self . expect_lifetime ( ) ;
3076
+ self . psess . gated_spans . gate ( sym:: pin_ergonomics, self . token . span ) ;
3077
+ self . bump ( ) ; // pin
3078
+ self . bump ( ) ; // mut
3079
+ SelfKind :: Pinned ( Some ( lt) , Mutability :: Mut )
3035
3080
} else {
3036
3081
// `¬_self`
3037
3082
return Ok ( None ) ;
0 commit comments