@@ -1197,15 +1197,12 @@ impl<'a> Parser<'a> {
1197
1197
/// Evaluates the closure with restrictions in place.
1198
1198
///
1199
1199
/// Afters the closure is evaluated, restrictions are reset.
1200
- fn with_res < F , T > ( & mut self , r : Restrictions , f : F ) -> T
1201
- where F : FnOnce ( & mut Self ) -> T
1202
- {
1200
+ fn with_res < T > ( & mut self , res : Restrictions , f : impl FnOnce ( & mut Self ) -> T ) -> T {
1203
1201
let old = self . restrictions ;
1204
- self . restrictions = r ;
1205
- let r = f ( self ) ;
1202
+ self . restrictions = res ;
1203
+ let res = f ( self ) ;
1206
1204
self . restrictions = old;
1207
- return r;
1208
-
1205
+ res
1209
1206
}
1210
1207
1211
1208
fn parse_fn_params (
@@ -1275,6 +1272,11 @@ impl<'a> Parser<'a> {
1275
1272
&& self . look_ahead ( n + 1 , |t| t != & token:: ModSep )
1276
1273
}
1277
1274
1275
+ fn is_isolated_mut_self ( & self , n : usize ) -> bool {
1276
+ self . is_keyword_ahead ( n, & [ kw:: Mut ] )
1277
+ && self . is_isolated_self ( n + 1 )
1278
+ }
1279
+
1278
1280
fn expect_self_ident ( & mut self ) -> Ident {
1279
1281
match self . token . kind {
1280
1282
// Preserve hygienic context.
@@ -1320,34 +1322,31 @@ impl<'a> Parser<'a> {
1320
1322
let eself_lo = self . token . span ;
1321
1323
let ( eself, eself_ident, eself_hi) = match self . token . kind {
1322
1324
token:: BinOp ( token:: And ) => {
1323
- // `&self`
1324
- // `&mut self`
1325
- // `&'lt self`
1326
- // `&'lt mut self`
1327
- // `¬_self`
1328
- ( if self . is_isolated_self ( 1 ) {
1325
+ let eself = if self . is_isolated_self ( 1 ) {
1326
+ // `&self`
1329
1327
self . bump ( ) ;
1330
1328
SelfKind :: Region ( None , Mutability :: Immutable )
1331
- } else if self . is_keyword_ahead ( 1 , & [ kw :: Mut ] ) &&
1332
- self . is_isolated_self ( 2 ) {
1329
+ } else if self . is_isolated_mut_self ( 1 ) {
1330
+ // `&mut self`
1333
1331
self . bump ( ) ;
1334
1332
self . bump ( ) ;
1335
1333
SelfKind :: Region ( None , Mutability :: Mutable )
1336
- } else if self . look_ahead ( 1 , |t| t. is_lifetime ( ) ) &&
1337
- self . is_isolated_self ( 2 ) {
1334
+ } else if self . look_ahead ( 1 , |t| t. is_lifetime ( ) ) && self . is_isolated_self ( 2 ) {
1335
+ // `&'lt self`
1338
1336
self . bump ( ) ;
1339
1337
let lt = self . expect_lifetime ( ) ;
1340
1338
SelfKind :: Region ( Some ( lt) , Mutability :: Immutable )
1341
- } else if self . look_ahead ( 1 , |t| t. is_lifetime ( ) ) &&
1342
- self . is_keyword_ahead ( 2 , & [ kw:: Mut ] ) &&
1343
- self . is_isolated_self ( 3 ) {
1339
+ } else if self . look_ahead ( 1 , |t| t. is_lifetime ( ) ) && self . is_isolated_mut_self ( 2 ) {
1340
+ // `&'lt mut self`
1344
1341
self . bump ( ) ;
1345
1342
let lt = self . expect_lifetime ( ) ;
1346
1343
self . bump ( ) ;
1347
1344
SelfKind :: Region ( Some ( lt) , Mutability :: Mutable )
1348
1345
} else {
1346
+ // `¬_self`
1349
1347
return Ok ( None ) ;
1350
- } , self . expect_self_ident ( ) , self . prev_span )
1348
+ } ;
1349
+ ( eself, self . expect_self_ident ( ) , self . prev_span )
1351
1350
}
1352
1351
// `*self`
1353
1352
token:: BinOp ( token:: Star ) if self . is_isolated_self ( 1 ) => {
@@ -1368,7 +1367,7 @@ impl<'a> Parser<'a> {
1368
1367
self . parse_self_possibly_typed ( Mutability :: Immutable ) ?
1369
1368
}
1370
1369
// `mut self` and `mut self: TYPE`
1371
- token:: Ident ( ..) if self . token . is_keyword ( kw :: Mut ) && self . is_isolated_self ( 1 ) => {
1370
+ token:: Ident ( ..) if self . is_isolated_mut_self ( 0 ) => {
1372
1371
self . bump ( ) ;
1373
1372
self . parse_self_possibly_typed ( Mutability :: Mutable ) ?
1374
1373
}
0 commit comments