@@ -2959,9 +2959,20 @@ impl<'a> Parser<'a> {
29592959 this. is_keyword_ahead ( n, & [ kw:: SelfLower ] )
29602960 && this. look_ahead ( n + 1 , |t| t != & token:: PathSep )
29612961 } ;
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+ } ;
29622968 // Is `mut self` `n` tokens ahead?
29632969 let is_isolated_mut_self =
29642970 |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+ } ;
29652976 // Parse `self` or `self: TYPE`. We already know the current token is `self`.
29662977 let parse_self_possibly_typed = |this : & mut Self , m| {
29672978 let eself_ident = expect_self_ident ( this) ;
@@ -3021,6 +3032,20 @@ impl<'a> Parser<'a> {
30213032 self . bump ( ) ;
30223033 self . bump ( ) ;
30233034 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 )
30243049 } else if self . look_ahead ( 1 , |t| t. is_lifetime ( ) ) && is_isolated_self ( self , 2 ) {
30253050 // `&'lt self`
30263051 self . bump ( ) ;
@@ -3032,6 +3057,26 @@ impl<'a> Parser<'a> {
30323057 let lt = self . expect_lifetime ( ) ;
30333058 self . bump ( ) ;
30343059 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 )
30353080 } else {
30363081 // `¬_self`
30373082 return Ok ( None ) ;
0 commit comments