@@ -111,7 +111,7 @@ impl Lit {
111
111
Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => Some ( Lit :: new ( Bool , name, None ) ) ,
112
112
Literal ( token_lit) => Some ( token_lit) ,
113
113
Interpolated ( ref nt)
114
- if let NtExpr ( expr) | NtLiteral ( expr) = & nt . 0
114
+ if let NtExpr ( expr) | NtLiteral ( expr) = & * * nt
115
115
&& let ast:: ExprKind :: Lit ( token_lit) = expr. kind =>
116
116
{
117
117
Some ( token_lit)
@@ -333,7 +333,11 @@ pub enum TokenKind {
333
333
/// - It prevents `Token` from implementing `Copy`.
334
334
/// It adds complexity and likely slows things down. Please don't add new
335
335
/// 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 > ) ,
337
341
338
342
/// A doc comment token.
339
343
/// `Symbol` is the doc comment's data excluding its "quotes" (`///`, `/**`, etc)
@@ -441,7 +445,7 @@ impl Token {
441
445
/// if they keep spans or perform edition checks.
442
446
pub fn uninterpolated_span ( & self ) -> Span {
443
447
match & self . kind {
444
- Interpolated ( nt) => nt. 0 . use_span ( ) ,
448
+ Interpolated ( nt) => nt. use_span ( ) ,
445
449
_ => self . span ,
446
450
}
447
451
}
@@ -486,7 +490,7 @@ impl Token {
486
490
PathSep | // global path
487
491
Lifetime ( ..) | // labeled loop
488
492
Pound => true , // expression attributes
489
- Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
493
+ Interpolated ( ref nt) => matches ! ( & * * nt , NtLiteral ( ..) |
490
494
NtExpr ( ..) |
491
495
NtBlock ( ..) |
492
496
NtPath ( ..) ) ,
@@ -510,7 +514,7 @@ impl Token {
510
514
| DotDot | DotDotDot | DotDotEq // ranges
511
515
| Lt | BinOp ( Shl ) // associated path
512
516
| PathSep => true , // global path
513
- Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
517
+ Interpolated ( ref nt) => matches ! ( & * * nt , NtLiteral ( ..) |
514
518
NtPat ( ..) |
515
519
NtBlock ( ..) |
516
520
NtPath ( ..) ) ,
@@ -533,7 +537,7 @@ impl Token {
533
537
Lifetime ( ..) | // lifetime bound in trait object
534
538
Lt | BinOp ( Shl ) | // associated path
535
539
PathSep => true , // global path
536
- Interpolated ( ref nt) => matches ! ( & nt . 0 , NtTy ( ..) | NtPath ( ..) ) ,
540
+ Interpolated ( ref nt) => matches ! ( & * * nt , NtTy ( ..) | NtPath ( ..) ) ,
537
541
// For anonymous structs or unions, which only appear in specific positions
538
542
// (type of struct fields or union fields), we don't consider them as regular types
539
543
_ => false ,
@@ -544,7 +548,7 @@ impl Token {
544
548
pub fn can_begin_const_arg ( & self ) -> bool {
545
549
match self . kind {
546
550
OpenDelim ( Delimiter :: Brace ) => true ,
547
- Interpolated ( ref nt) => matches ! ( & nt . 0 , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
551
+ Interpolated ( ref nt) => matches ! ( & * * nt , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
548
552
_ => self . can_begin_literal_maybe_minus ( ) ,
549
553
}
550
554
}
@@ -589,7 +593,7 @@ impl Token {
589
593
match self . uninterpolate ( ) . kind {
590
594
Literal ( ..) | BinOp ( Minus ) => true ,
591
595
Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => true ,
592
- Interpolated ( ref nt) => match & nt . 0 {
596
+ Interpolated ( ref nt) => match & * * nt {
593
597
NtLiteral ( _) => true ,
594
598
NtExpr ( e) => match & e. kind {
595
599
ast:: ExprKind :: Lit ( _) => true ,
@@ -610,7 +614,7 @@ impl Token {
610
614
/// otherwise returns the original token.
611
615
pub fn uninterpolate ( & self ) -> Cow < ' _ , Token > {
612
616
match & self . kind {
613
- Interpolated ( nt) => match & nt . 0 {
617
+ Interpolated ( nt) => match & * * nt {
614
618
NtIdent ( ident, is_raw) => {
615
619
Cow :: Owned ( Token :: new ( Ident ( ident. name , * is_raw) , ident. span ) )
616
620
}
@@ -627,7 +631,7 @@ impl Token {
627
631
// We avoid using `Token::uninterpolate` here because it's slow.
628
632
match & self . kind {
629
633
& Ident ( name, is_raw) => Some ( ( Ident :: new ( name, self . span ) , is_raw) ) ,
630
- Interpolated ( nt) => match & nt . 0 {
634
+ Interpolated ( nt) => match & * * nt {
631
635
NtIdent ( ident, is_raw) => Some ( ( * ident, * is_raw) ) ,
632
636
_ => None ,
633
637
} ,
@@ -641,7 +645,7 @@ impl Token {
641
645
// We avoid using `Token::uninterpolate` here because it's slow.
642
646
match & self . kind {
643
647
& Lifetime ( name) => Some ( Ident :: new ( name, self . span ) ) ,
644
- Interpolated ( nt) => match & nt . 0 {
648
+ Interpolated ( nt) => match & * * nt {
645
649
NtLifetime ( ident) => Some ( * ident) ,
646
650
_ => None ,
647
651
} ,
@@ -668,7 +672,7 @@ impl Token {
668
672
/// Returns `true` if the token is an interpolated path.
669
673
fn is_whole_path ( & self ) -> bool {
670
674
if let Interpolated ( nt) = & self . kind
671
- && let NtPath ( ..) = & nt . 0
675
+ && let NtPath ( ..) = & * * nt
672
676
{
673
677
return true ;
674
678
}
@@ -681,7 +685,7 @@ impl Token {
681
685
/// (which happens while parsing the result of macro expansion)?
682
686
pub fn is_whole_expr ( & self ) -> bool {
683
687
if let Interpolated ( nt) = & self . kind
684
- && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = & nt . 0
688
+ && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = & * * nt
685
689
{
686
690
return true ;
687
691
}
@@ -692,7 +696,7 @@ impl Token {
692
696
/// Is the token an interpolated block (`$b:block`)?
693
697
pub fn is_whole_block ( & self ) -> bool {
694
698
if let Interpolated ( nt) = & self . kind
695
- && let NtBlock ( ..) = & nt . 0
699
+ && let NtBlock ( ..) = & * * nt
696
700
{
697
701
return true ;
698
702
}
@@ -857,6 +861,7 @@ pub enum Nonterminal {
857
861
NtPat ( P < ast:: Pat > ) ,
858
862
NtExpr ( P < ast:: Expr > ) ,
859
863
NtTy ( P < ast:: Ty > ) ,
864
+ /// The span is for the identifier argument passed to the macro.
860
865
NtIdent ( Ident , IdentIsRaw ) ,
861
866
NtLifetime ( Ident ) ,
862
867
NtLiteral ( P < ast:: Expr > ) ,
0 commit comments