@@ -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)
@@ -421,7 +421,7 @@ impl Token {
421
421
/// if they keep spans or perform edition checks.
422
422
pub fn uninterpolated_span ( & self ) -> Span {
423
423
match & self . kind {
424
- Interpolated ( nt) => nt. span ( ) ,
424
+ Interpolated ( nt) => nt. 0 . use_span ( ) ,
425
425
_ => self . span ,
426
426
}
427
427
}
@@ -464,7 +464,7 @@ impl Token {
464
464
ModSep | // global path
465
465
Lifetime ( ..) | // labeled loop
466
466
Pound => true , // expression attributes
467
- Interpolated ( ref nt) => matches ! ( * * nt , NtLiteral ( ..) |
467
+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
468
468
NtExpr ( ..) |
469
469
NtBlock ( ..) |
470
470
NtPath ( ..) ) ,
@@ -488,7 +488,7 @@ impl Token {
488
488
| DotDot | DotDotDot | DotDotEq // ranges
489
489
| Lt | BinOp ( Shl ) // associated path
490
490
| ModSep => true , // global path
491
- Interpolated ( ref nt) => matches ! ( * * nt , NtLiteral ( ..) |
491
+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
492
492
NtPat ( ..) |
493
493
NtBlock ( ..) |
494
494
NtPath ( ..) ) ,
@@ -511,7 +511,7 @@ impl Token {
511
511
Lifetime ( ..) | // lifetime bound in trait object
512
512
Lt | BinOp ( Shl ) | // associated path
513
513
ModSep => true , // global path
514
- Interpolated ( ref nt) => matches ! ( * * nt , NtTy ( ..) | NtPath ( ..) ) ,
514
+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtTy ( ..) | NtPath ( ..) ) ,
515
515
// For anonymous structs or unions, which only appear in specific positions
516
516
// (type of struct fields or union fields), we don't consider them as regular types
517
517
_ => false ,
@@ -522,7 +522,7 @@ impl Token {
522
522
pub fn can_begin_const_arg ( & self ) -> bool {
523
523
match self . kind {
524
524
OpenDelim ( Delimiter :: Brace ) => true ,
525
- Interpolated ( ref nt) => matches ! ( * * nt , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
525
+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
526
526
_ => self . can_begin_literal_maybe_minus ( ) ,
527
527
}
528
528
}
@@ -576,7 +576,7 @@ impl Token {
576
576
match self . uninterpolate ( ) . kind {
577
577
Literal ( ..) | BinOp ( Minus ) => true ,
578
578
Ident ( name, false ) if name. is_bool_lit ( ) => true ,
579
- Interpolated ( ref nt) => match & * * nt {
579
+ Interpolated ( ref nt) => match & nt . 0 {
580
580
NtLiteral ( _) => true ,
581
581
NtExpr ( e) => match & e. kind {
582
582
ast:: ExprKind :: Lit ( _) => true ,
@@ -597,9 +597,9 @@ impl Token {
597
597
/// otherwise returns the original token.
598
598
pub fn uninterpolate ( & self ) -> Cow < ' _ , Token > {
599
599
match & self . kind {
600
- Interpolated ( nt) => match * * nt {
600
+ Interpolated ( nt) => match & nt . 0 {
601
601
NtIdent ( ident, is_raw) => {
602
- Cow :: Owned ( Token :: new ( Ident ( ident. name , is_raw) , ident. span ) )
602
+ Cow :: Owned ( Token :: new ( Ident ( ident. name , * is_raw) , ident. span ) )
603
603
}
604
604
NtLifetime ( ident) => Cow :: Owned ( Token :: new ( Lifetime ( ident. name ) , ident. span ) ) ,
605
605
_ => Cow :: Borrowed ( self ) ,
@@ -614,8 +614,8 @@ impl Token {
614
614
// We avoid using `Token::uninterpolate` here because it's slow.
615
615
match & self . kind {
616
616
& Ident ( name, is_raw) => Some ( ( Ident :: new ( name, self . span ) , is_raw) ) ,
617
- Interpolated ( nt) => match * * nt {
618
- NtIdent ( ident, is_raw) => Some ( ( ident, is_raw) ) ,
617
+ Interpolated ( nt) => match & nt . 0 {
618
+ NtIdent ( ident, is_raw) => Some ( ( * ident, * is_raw) ) ,
619
619
_ => None ,
620
620
} ,
621
621
_ => None ,
@@ -628,8 +628,8 @@ impl Token {
628
628
// We avoid using `Token::uninterpolate` here because it's slow.
629
629
match & self . kind {
630
630
& Lifetime ( name) => Some ( Ident :: new ( name, self . span ) ) ,
631
- Interpolated ( nt) => match * * nt {
632
- NtLifetime ( ident) => Some ( ident) ,
631
+ Interpolated ( nt) => match & nt . 0 {
632
+ NtLifetime ( ident) => Some ( * ident) ,
633
633
_ => None ,
634
634
} ,
635
635
_ => None ,
@@ -654,9 +654,7 @@ impl Token {
654
654
655
655
/// Returns `true` if the token is an interpolated path.
656
656
fn is_path ( & self ) -> bool {
657
- if let Interpolated ( nt) = & self . kind
658
- && let NtPath ( ..) = * * nt
659
- {
657
+ if let Interpolated ( nt) = & self . kind && let NtPath ( ..) = & nt. 0 {
660
658
return true ;
661
659
}
662
660
@@ -668,7 +666,7 @@ impl Token {
668
666
/// (which happens while parsing the result of macro expansion)?
669
667
pub fn is_whole_expr ( & self ) -> bool {
670
668
if let Interpolated ( nt) = & self . kind
671
- && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = * * nt
669
+ && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = & nt . 0
672
670
{
673
671
return true ;
674
672
}
@@ -678,9 +676,7 @@ impl Token {
678
676
679
677
/// Is the token an interpolated block (`$b:block`)?
680
678
pub fn is_whole_block ( & self ) -> bool {
681
- if let Interpolated ( nt) = & self . kind
682
- && let NtBlock ( ..) = * * nt
683
- {
679
+ if let Interpolated ( nt) = & self . kind && let NtBlock ( ..) = & nt. 0 {
684
680
return true ;
685
681
}
686
682
@@ -927,7 +923,7 @@ impl fmt::Display for NonterminalKind {
927
923
}
928
924
929
925
impl Nonterminal {
930
- pub fn span ( & self ) -> Span {
926
+ pub fn use_span ( & self ) -> Span {
931
927
match self {
932
928
NtItem ( item) => item. span ,
933
929
NtBlock ( block) => block. span ,
@@ -941,6 +937,23 @@ impl Nonterminal {
941
937
NtVis ( vis) => vis. span ,
942
938
}
943
939
}
940
+
941
+ pub fn descr ( & self ) -> & ' static str {
942
+ match self {
943
+ NtItem ( ..) => "item" ,
944
+ NtBlock ( ..) => "block" ,
945
+ NtStmt ( ..) => "statement" ,
946
+ NtPat ( ..) => "pattern" ,
947
+ NtExpr ( ..) => "expression" ,
948
+ NtLiteral ( ..) => "literal" ,
949
+ NtTy ( ..) => "type" ,
950
+ NtIdent ( ..) => "identifier" ,
951
+ NtLifetime ( ..) => "lifetime" ,
952
+ NtMeta ( ..) => "attribute" ,
953
+ NtPath ( ..) => "path" ,
954
+ NtVis ( ..) => "visibility" ,
955
+ }
956
+ }
944
957
}
945
958
946
959
impl PartialEq for Nonterminal {
0 commit comments