@@ -357,7 +357,7 @@ impl Token {
357357
358358 /// Returns `true` if the token can appear at the start of an expression.
359359 pub fn can_begin_expr ( & self ) -> bool {
360- match self . kind {
360+ match self . uninterpolate ( ) . kind {
361361 Ident ( name, is_raw) =>
362362 ident_can_begin_expr ( name, self . span , is_raw) , // value name or keyword
363363 OpenDelim ( ..) | // tuple, array or block
@@ -375,12 +375,10 @@ impl Token {
375375 Lifetime ( ..) | // labeled loop
376376 Pound => true , // expression attributes
377377 Interpolated ( ref nt) => match * * nt {
378- NtIdent ( ident, is_raw) => ident_can_begin_expr ( ident. name , ident. span , is_raw) ,
379378 NtLiteral ( ..) |
380379 NtExpr ( ..) |
381380 NtBlock ( ..) |
382- NtPath ( ..) |
383- NtLifetime ( ..) => true ,
381+ NtPath ( ..) => true ,
384382 _ => false ,
385383 } ,
386384 _ => false ,
@@ -389,7 +387,7 @@ impl Token {
389387
390388 /// Returns `true` if the token can appear at the start of a type.
391389 pub fn can_begin_type ( & self ) -> bool {
392- match self . kind {
390+ match self . uninterpolate ( ) . kind {
393391 Ident ( name, is_raw) =>
394392 ident_can_begin_type ( name, self . span , is_raw) , // type name or keyword
395393 OpenDelim ( Paren ) | // tuple
@@ -403,8 +401,7 @@ impl Token {
403401 Lt | BinOp ( Shl ) | // associated path
404402 ModSep => true , // global path
405403 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 ,
408405 _ => false ,
409406 } ,
410407 _ => false ,
@@ -445,11 +442,10 @@ impl Token {
445442 ///
446443 /// Keep this in sync with `Lit::from_token`.
447444 pub fn can_begin_literal_or_bool ( & self ) -> bool {
448- match self . kind {
445+ match self . uninterpolate ( ) . kind {
449446 Literal ( ..) | BinOp ( Minus ) => true ,
450447 Ident ( name, false ) if name. is_bool_lit ( ) => true ,
451448 Interpolated ( ref nt) => match & * * nt {
452- NtIdent ( ident, false ) if ident. name . is_bool_lit ( ) => true ,
453449 NtExpr ( e) | NtLiteral ( e) => matches ! ( e. kind, ast:: ExprKind :: Lit ( _) ) ,
454450 _ => false ,
455451 } ,
@@ -475,24 +471,18 @@ impl Token {
475471
476472 /// Returns an identifier if this token is an identifier.
477473 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) ) ,
484477 _ => None ,
485478 }
486479 }
487480
488481 /// Returns a lifetime identifier if this token is a lifetime.
489482 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 ) ) ,
496486 _ => None ,
497487 }
498488 }
0 commit comments