@@ -357,7 +357,7 @@ impl Token {
357
357
358
358
/// Returns `true` if the token can appear at the start of an expression.
359
359
pub fn can_begin_expr ( & self ) -> bool {
360
- match self . kind {
360
+ match self . uninterpolate ( ) . kind {
361
361
Ident ( name, is_raw) =>
362
362
ident_can_begin_expr ( name, self . span , is_raw) , // value name or keyword
363
363
OpenDelim ( ..) | // tuple, array or block
@@ -375,12 +375,10 @@ impl Token {
375
375
Lifetime ( ..) | // labeled loop
376
376
Pound => true , // expression attributes
377
377
Interpolated ( ref nt) => match * * nt {
378
- NtIdent ( ident, is_raw) => ident_can_begin_expr ( ident. name , ident. span , is_raw) ,
379
378
NtLiteral ( ..) |
380
379
NtExpr ( ..) |
381
380
NtBlock ( ..) |
382
- NtPath ( ..) |
383
- NtLifetime ( ..) => true ,
381
+ NtPath ( ..) => true ,
384
382
_ => false ,
385
383
} ,
386
384
_ => false ,
@@ -389,7 +387,7 @@ impl Token {
389
387
390
388
/// Returns `true` if the token can appear at the start of a type.
391
389
pub fn can_begin_type ( & self ) -> bool {
392
- match self . kind {
390
+ match self . uninterpolate ( ) . kind {
393
391
Ident ( name, is_raw) =>
394
392
ident_can_begin_type ( name, self . span , is_raw) , // type name or keyword
395
393
OpenDelim ( Paren ) | // tuple
@@ -403,8 +401,7 @@ impl Token {
403
401
Lt | BinOp ( Shl ) | // associated path
404
402
ModSep => true , // global path
405
403
Interpolated ( ref nt) => match * * nt {
406
- NtIdent ( ident, is_raw) => ident_can_begin_type ( ident. name , ident. span , is_raw) ,
407
- NtTy ( ..) | NtPath ( ..) | NtLifetime ( ..) => true ,
404
+ NtTy ( ..) | NtPath ( ..) => true ,
408
405
_ => false ,
409
406
} ,
410
407
_ => false ,
@@ -445,11 +442,10 @@ impl Token {
445
442
///
446
443
/// Keep this in sync with `Lit::from_token`.
447
444
pub fn can_begin_literal_or_bool ( & self ) -> bool {
448
- match self . kind {
445
+ match self . uninterpolate ( ) . kind {
449
446
Literal ( ..) | BinOp ( Minus ) => true ,
450
447
Ident ( name, false ) if name. is_bool_lit ( ) => true ,
451
448
Interpolated ( ref nt) => match & * * nt {
452
- NtIdent ( ident, false ) if ident. name . is_bool_lit ( ) => true ,
453
449
NtExpr ( e) | NtLiteral ( e) => matches ! ( e. kind, ast:: ExprKind :: Lit ( _) ) ,
454
450
_ => false ,
455
451
} ,
@@ -475,24 +471,18 @@ impl Token {
475
471
476
472
/// Returns an identifier if this token is an identifier.
477
473
pub fn ident ( & self ) -> Option < ( ast:: Ident , /* is_raw */ bool ) > {
478
- match self . kind {
479
- Ident ( name, is_raw) => Some ( ( ast:: Ident :: new ( name, self . span ) , is_raw) ) ,
480
- Interpolated ( ref nt) => match * * nt {
481
- NtIdent ( ident, is_raw) => Some ( ( ident, is_raw) ) ,
482
- _ => None ,
483
- } ,
474
+ let token = self . uninterpolate ( ) ;
475
+ match token. kind {
476
+ Ident ( name, is_raw) => Some ( ( ast:: Ident :: new ( name, token. span ) , is_raw) ) ,
484
477
_ => None ,
485
478
}
486
479
}
487
480
488
481
/// Returns a lifetime identifier if this token is a lifetime.
489
482
pub fn lifetime ( & self ) -> Option < ast:: Ident > {
490
- match self . kind {
491
- Lifetime ( name) => Some ( ast:: Ident :: new ( name, self . span ) ) ,
492
- Interpolated ( ref nt) => match * * nt {
493
- NtLifetime ( ident) => Some ( ident) ,
494
- _ => None ,
495
- } ,
483
+ let token = self . uninterpolate ( ) ;
484
+ match token. kind {
485
+ Lifetime ( name) => Some ( ast:: Ident :: new ( name, token. span ) ) ,
496
486
_ => None ,
497
487
}
498
488
}
0 commit comments