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