@@ -111,7 +111,7 @@ impl Lit {
111111 Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => Some ( Lit :: new ( Bool , name, None ) ) ,
112112 Literal ( token_lit) => Some ( token_lit) ,
113113 Interpolated ( ref nt)
114- if let NtExpr ( expr) | NtLiteral ( expr) = & nt . 0
114+ if let NtExpr ( expr) | NtLiteral ( expr) = & * * nt
115115 && let ast:: ExprKind :: Lit ( token_lit) = expr. kind =>
116116 {
117117 Some ( token_lit)
@@ -333,7 +333,11 @@ pub enum TokenKind {
333333 /// - It prevents `Token` from implementing `Copy`.
334334 /// It adds complexity and likely slows things down. Please don't add new
335335 /// occurrences of this token kind!
336- Interpolated ( Lrc < ( Nonterminal , Span ) > ) ,
336+ ///
337+ /// The span in the surrounding `Token` is that of the metavariable in the
338+ /// macro's RHS. The span within the Nonterminal is that of the fragment
339+ /// passed to the macro at the call site.
340+ Interpolated ( Lrc < Nonterminal > ) ,
337341
338342 /// A doc comment token.
339343 /// `Symbol` is the doc comment's data excluding its "quotes" (`///`, `/**`, etc)
@@ -441,7 +445,7 @@ impl Token {
441445 /// if they keep spans or perform edition checks.
442446 pub fn uninterpolated_span ( & self ) -> Span {
443447 match & self . kind {
444- Interpolated ( nt) => nt. 0 . use_span ( ) ,
448+ Interpolated ( nt) => nt. use_span ( ) ,
445449 _ => self . span ,
446450 }
447451 }
@@ -486,7 +490,7 @@ impl Token {
486490 PathSep | // global path
487491 Lifetime ( ..) | // labeled loop
488492 Pound => true , // expression attributes
489- Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
493+ Interpolated ( ref nt) => matches ! ( & * * nt , NtLiteral ( ..) |
490494 NtExpr ( ..) |
491495 NtBlock ( ..) |
492496 NtPath ( ..) ) ,
@@ -510,7 +514,7 @@ impl Token {
510514 | DotDot | DotDotDot | DotDotEq // ranges
511515 | Lt | BinOp ( Shl ) // associated path
512516 | PathSep => true , // global path
513- Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
517+ Interpolated ( ref nt) => matches ! ( & * * nt , NtLiteral ( ..) |
514518 NtPat ( ..) |
515519 NtBlock ( ..) |
516520 NtPath ( ..) ) ,
@@ -533,7 +537,7 @@ impl Token {
533537 Lifetime ( ..) | // lifetime bound in trait object
534538 Lt | BinOp ( Shl ) | // associated path
535539 PathSep => true , // global path
536- Interpolated ( ref nt) => matches ! ( & nt . 0 , NtTy ( ..) | NtPath ( ..) ) ,
540+ Interpolated ( ref nt) => matches ! ( & * * nt , NtTy ( ..) | NtPath ( ..) ) ,
537541 // For anonymous structs or unions, which only appear in specific positions
538542 // (type of struct fields or union fields), we don't consider them as regular types
539543 _ => false ,
@@ -544,7 +548,7 @@ impl Token {
544548 pub fn can_begin_const_arg ( & self ) -> bool {
545549 match self . kind {
546550 OpenDelim ( Delimiter :: Brace ) => true ,
547- Interpolated ( ref nt) => matches ! ( & nt . 0 , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
551+ Interpolated ( ref nt) => matches ! ( & * * nt , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
548552 _ => self . can_begin_literal_maybe_minus ( ) ,
549553 }
550554 }
@@ -589,7 +593,7 @@ impl Token {
589593 match self . uninterpolate ( ) . kind {
590594 Literal ( ..) | BinOp ( Minus ) => true ,
591595 Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => true ,
592- Interpolated ( ref nt) => match & nt . 0 {
596+ Interpolated ( ref nt) => match & * * nt {
593597 NtLiteral ( _) => true ,
594598 NtExpr ( e) => match & e. kind {
595599 ast:: ExprKind :: Lit ( _) => true ,
@@ -610,7 +614,7 @@ impl Token {
610614 /// otherwise returns the original token.
611615 pub fn uninterpolate ( & self ) -> Cow < ' _ , Token > {
612616 match & self . kind {
613- Interpolated ( nt) => match & nt . 0 {
617+ Interpolated ( nt) => match & * * nt {
614618 NtIdent ( ident, is_raw) => {
615619 Cow :: Owned ( Token :: new ( Ident ( ident. name , * is_raw) , ident. span ) )
616620 }
@@ -627,7 +631,7 @@ impl Token {
627631 // We avoid using `Token::uninterpolate` here because it's slow.
628632 match & self . kind {
629633 & Ident ( name, is_raw) => Some ( ( Ident :: new ( name, self . span ) , is_raw) ) ,
630- Interpolated ( nt) => match & nt . 0 {
634+ Interpolated ( nt) => match & * * nt {
631635 NtIdent ( ident, is_raw) => Some ( ( * ident, * is_raw) ) ,
632636 _ => None ,
633637 } ,
@@ -641,7 +645,7 @@ impl Token {
641645 // We avoid using `Token::uninterpolate` here because it's slow.
642646 match & self . kind {
643647 & Lifetime ( name) => Some ( Ident :: new ( name, self . span ) ) ,
644- Interpolated ( nt) => match & nt . 0 {
648+ Interpolated ( nt) => match & * * nt {
645649 NtLifetime ( ident) => Some ( * ident) ,
646650 _ => None ,
647651 } ,
@@ -668,7 +672,7 @@ impl Token {
668672 /// Returns `true` if the token is an interpolated path.
669673 fn is_whole_path ( & self ) -> bool {
670674 if let Interpolated ( nt) = & self . kind
671- && let NtPath ( ..) = & nt . 0
675+ && let NtPath ( ..) = & * * nt
672676 {
673677 return true ;
674678 }
@@ -681,7 +685,7 @@ impl Token {
681685 /// (which happens while parsing the result of macro expansion)?
682686 pub fn is_whole_expr ( & self ) -> bool {
683687 if let Interpolated ( nt) = & self . kind
684- && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = & nt . 0
688+ && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = & * * nt
685689 {
686690 return true ;
687691 }
@@ -692,7 +696,7 @@ impl Token {
692696 /// Is the token an interpolated block (`$b:block`)?
693697 pub fn is_whole_block ( & self ) -> bool {
694698 if let Interpolated ( nt) = & self . kind
695- && let NtBlock ( ..) = & nt . 0
699+ && let NtBlock ( ..) = & * * nt
696700 {
697701 return true ;
698702 }
@@ -857,6 +861,7 @@ pub enum Nonterminal {
857861 NtPat ( P < ast:: Pat > ) ,
858862 NtExpr ( P < ast:: Expr > ) ,
859863 NtTy ( P < ast:: Ty > ) ,
864+ /// The span is for the identifier argument passed to the macro.
860865 NtIdent ( Ident , IdentIsRaw ) ,
861866 NtLifetime ( Ident ) ,
862867 NtLiteral ( P < ast:: Expr > ) ,
0 commit comments