@@ -2957,9 +2957,20 @@ impl<'a> Parser<'a> {
29572957 this. is_keyword_ahead ( n, & [ kw:: SelfLower ] )
29582958 && this. look_ahead ( n + 1 , |t| t != & token:: PathSep )
29592959 } ;
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+ } ;
29602966 // Is `mut self` `n` tokens ahead?
29612967 let is_isolated_mut_self =
29622968 |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+ } ;
29632974 // Parse `self` or `self: TYPE`. We already know the current token is `self`.
29642975 let parse_self_possibly_typed = |this : & mut Self , m| {
29652976 let eself_ident = expect_self_ident ( this) ;
@@ -3019,6 +3030,20 @@ impl<'a> Parser<'a> {
30193030 self . bump ( ) ;
30203031 self . bump ( ) ;
30213032 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 )
30223047 } else if self . look_ahead ( 1 , |t| t. is_lifetime ( ) ) && is_isolated_self ( self , 2 ) {
30233048 // `&'lt self`
30243049 self . bump ( ) ;
@@ -3030,6 +3055,26 @@ impl<'a> Parser<'a> {
30303055 let lt = self . expect_lifetime ( ) ;
30313056 self . bump ( ) ;
30323057 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 )
30333078 } else {
30343079 // `¬_self`
30353080 return Ok ( None ) ;
0 commit comments