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