@@ -110,7 +110,7 @@ impl Lit {
110
110
Ident ( name, false ) if name. is_bool_lit ( ) => Some ( Lit :: new ( Bool , name, None ) ) ,
111
111
Literal ( token_lit) => Some ( token_lit) ,
112
112
Interpolated ( ref nt)
113
- if let NtExpr ( expr) | NtLiteral ( expr) = & * * nt
113
+ if let NtExpr ( expr) | NtLiteral ( expr) = & nt . 0
114
114
&& let ast:: ExprKind :: Lit ( token_lit) = expr. kind =>
115
115
{
116
116
Some ( token_lit)
@@ -314,7 +314,7 @@ pub enum TokenKind {
314
314
/// - It prevents `Token` from implementing `Copy`.
315
315
/// It adds complexity and likely slows things down. Please don't add new
316
316
/// occurrences of this token kind!
317
- Interpolated ( Lrc < Nonterminal > ) ,
317
+ Interpolated ( Lrc < ( Nonterminal , Span ) > ) ,
318
318
319
319
/// A doc comment token.
320
320
/// `Symbol` is the doc comment's data excluding its "quotes" (`///`, `/**`, etc)
@@ -422,7 +422,7 @@ impl Token {
422
422
/// if they keep spans or perform edition checks.
423
423
pub fn uninterpolated_span ( & self ) -> Span {
424
424
match & self . kind {
425
- Interpolated ( nt) => nt. span ( ) ,
425
+ Interpolated ( nt) => nt. 0 . use_span ( ) ,
426
426
_ => self . span ,
427
427
}
428
428
}
@@ -465,7 +465,7 @@ impl Token {
465
465
ModSep | // global path
466
466
Lifetime ( ..) | // labeled loop
467
467
Pound => true , // expression attributes
468
- Interpolated ( ref nt) => matches ! ( * * nt , NtLiteral ( ..) |
468
+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
469
469
NtExpr ( ..) |
470
470
NtBlock ( ..) |
471
471
NtPath ( ..) ) ,
@@ -489,7 +489,7 @@ impl Token {
489
489
| DotDot | DotDotDot | DotDotEq // ranges
490
490
| Lt | BinOp ( Shl ) // associated path
491
491
| ModSep => true , // global path
492
- Interpolated ( ref nt) => matches ! ( * * nt , NtLiteral ( ..) |
492
+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
493
493
NtPat ( ..) |
494
494
NtBlock ( ..) |
495
495
NtPath ( ..) ) ,
@@ -512,7 +512,7 @@ impl Token {
512
512
Lifetime ( ..) | // lifetime bound in trait object
513
513
Lt | BinOp ( Shl ) | // associated path
514
514
ModSep => true , // global path
515
- Interpolated ( ref nt) => matches ! ( * * nt , NtTy ( ..) | NtPath ( ..) ) ,
515
+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtTy ( ..) | NtPath ( ..) ) ,
516
516
// For anonymous structs or unions, which only appear in specific positions
517
517
// (type of struct fields or union fields), we don't consider them as regular types
518
518
_ => false ,
@@ -523,7 +523,7 @@ impl Token {
523
523
pub fn can_begin_const_arg ( & self ) -> bool {
524
524
match self . kind {
525
525
OpenDelim ( Delimiter :: Brace ) => true ,
526
- Interpolated ( ref nt) => matches ! ( * * nt , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
526
+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
527
527
_ => self . can_begin_literal_maybe_minus ( ) ,
528
528
}
529
529
}
@@ -577,7 +577,7 @@ impl Token {
577
577
match self . uninterpolate ( ) . kind {
578
578
Literal ( ..) | BinOp ( Minus ) => true ,
579
579
Ident ( name, false ) if name. is_bool_lit ( ) => true ,
580
- Interpolated ( ref nt) => match & * * nt {
580
+ Interpolated ( ref nt) => match & nt . 0 {
581
581
NtLiteral ( _) => true ,
582
582
NtExpr ( e) => match & e. kind {
583
583
ast:: ExprKind :: Lit ( _) => true ,
@@ -598,9 +598,9 @@ impl Token {
598
598
/// otherwise returns the original token.
599
599
pub fn uninterpolate ( & self ) -> Cow < ' _ , Token > {
600
600
match & self . kind {
601
- Interpolated ( nt) => match * * nt {
601
+ Interpolated ( nt) => match & nt . 0 {
602
602
NtIdent ( ident, is_raw) => {
603
- Cow :: Owned ( Token :: new ( Ident ( ident. name , is_raw) , ident. span ) )
603
+ Cow :: Owned ( Token :: new ( Ident ( ident. name , * is_raw) , ident. span ) )
604
604
}
605
605
NtLifetime ( ident) => Cow :: Owned ( Token :: new ( Lifetime ( ident. name ) , ident. span ) ) ,
606
606
_ => Cow :: Borrowed ( self ) ,
@@ -615,8 +615,8 @@ impl Token {
615
615
// We avoid using `Token::uninterpolate` here because it's slow.
616
616
match & self . kind {
617
617
& Ident ( name, is_raw) => Some ( ( Ident :: new ( name, self . span ) , is_raw) ) ,
618
- Interpolated ( nt) => match * * nt {
619
- NtIdent ( ident, is_raw) => Some ( ( ident, is_raw) ) ,
618
+ Interpolated ( nt) => match & nt . 0 {
619
+ NtIdent ( ident, is_raw) => Some ( ( * ident, * is_raw) ) ,
620
620
_ => None ,
621
621
} ,
622
622
_ => None ,
@@ -629,8 +629,8 @@ impl Token {
629
629
// We avoid using `Token::uninterpolate` here because it's slow.
630
630
match & self . kind {
631
631
& Lifetime ( name) => Some ( Ident :: new ( name, self . span ) ) ,
632
- Interpolated ( nt) => match * * nt {
633
- NtLifetime ( ident) => Some ( ident) ,
632
+ Interpolated ( nt) => match & nt . 0 {
633
+ NtLifetime ( ident) => Some ( * ident) ,
634
634
_ => None ,
635
635
} ,
636
636
_ => None ,
@@ -656,7 +656,7 @@ impl Token {
656
656
/// Returns `true` if the token is an interpolated path.
657
657
fn is_path ( & self ) -> bool {
658
658
if let Interpolated ( nt) = & self . kind
659
- && let NtPath ( ..) = * * nt
659
+ && let NtPath ( ..) = & nt . 0
660
660
{
661
661
return true ;
662
662
}
@@ -669,7 +669,7 @@ impl Token {
669
669
/// (which happens while parsing the result of macro expansion)?
670
670
pub fn is_whole_expr ( & self ) -> bool {
671
671
if let Interpolated ( nt) = & self . kind
672
- && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = * * nt
672
+ && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = & nt . 0
673
673
{
674
674
return true ;
675
675
}
@@ -680,7 +680,7 @@ impl Token {
680
680
/// Is the token an interpolated block (`$b:block`)?
681
681
pub fn is_whole_block ( & self ) -> bool {
682
682
if let Interpolated ( nt) = & self . kind
683
- && let NtBlock ( ..) = * * nt
683
+ && let NtBlock ( ..) = & nt . 0
684
684
{
685
685
return true ;
686
686
}
@@ -928,7 +928,7 @@ impl fmt::Display for NonterminalKind {
928
928
}
929
929
930
930
impl Nonterminal {
931
- pub fn span ( & self ) -> Span {
931
+ pub fn use_span ( & self ) -> Span {
932
932
match self {
933
933
NtItem ( item) => item. span ,
934
934
NtBlock ( block) => block. span ,
@@ -942,6 +942,23 @@ impl Nonterminal {
942
942
NtVis ( vis) => vis. span ,
943
943
}
944
944
}
945
+
946
+ pub fn descr ( & self ) -> & ' static str {
947
+ match self {
948
+ NtItem ( ..) => "item" ,
949
+ NtBlock ( ..) => "block" ,
950
+ NtStmt ( ..) => "statement" ,
951
+ NtPat ( ..) => "pattern" ,
952
+ NtExpr ( ..) => "expression" ,
953
+ NtLiteral ( ..) => "literal" ,
954
+ NtTy ( ..) => "type" ,
955
+ NtIdent ( ..) => "identifier" ,
956
+ NtLifetime ( ..) => "lifetime" ,
957
+ NtMeta ( ..) => "attribute" ,
958
+ NtPath ( ..) => "path" ,
959
+ NtVis ( ..) => "visibility" ,
960
+ }
961
+ }
945
962
}
946
963
947
964
impl PartialEq for Nonterminal {
0 commit comments