@@ -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 ,
@@ -655,7 +655,7 @@ impl Token {
655
655
/// Returns `true` if the token is an interpolated path.
656
656
fn is_path ( & self ) -> bool {
657
657
if let Interpolated ( nt) = & self . kind
658
- && let NtPath ( ..) = * * nt
658
+ && let NtPath ( ..) = & nt . 0
659
659
{
660
660
return true ;
661
661
}
@@ -668,7 +668,7 @@ impl Token {
668
668
/// (which happens while parsing the result of macro expansion)?
669
669
pub fn is_whole_expr ( & self ) -> bool {
670
670
if let Interpolated ( nt) = & self . kind
671
- && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = * * nt
671
+ && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = & nt . 0
672
672
{
673
673
return true ;
674
674
}
@@ -679,7 +679,7 @@ impl Token {
679
679
/// Is the token an interpolated block (`$b:block`)?
680
680
pub fn is_whole_block ( & self ) -> bool {
681
681
if let Interpolated ( nt) = & self . kind
682
- && let NtBlock ( ..) = * * nt
682
+ && let NtBlock ( ..) = & nt . 0
683
683
{
684
684
return true ;
685
685
}
@@ -927,7 +927,7 @@ impl fmt::Display for NonterminalKind {
927
927
}
928
928
929
929
impl Nonterminal {
930
- pub fn span ( & self ) -> Span {
930
+ pub fn use_span ( & self ) -> Span {
931
931
match self {
932
932
NtItem ( item) => item. span ,
933
933
NtBlock ( block) => block. span ,
@@ -941,6 +941,23 @@ impl Nonterminal {
941
941
NtVis ( vis) => vis. span ,
942
942
}
943
943
}
944
+
945
+ pub fn descr ( & self ) -> & ' static str {
946
+ match self {
947
+ NtItem ( ..) => "item" ,
948
+ NtBlock ( ..) => "block" ,
949
+ NtStmt ( ..) => "statement" ,
950
+ NtPat ( ..) => "pattern" ,
951
+ NtExpr ( ..) => "expression" ,
952
+ NtLiteral ( ..) => "literal" ,
953
+ NtTy ( ..) => "type" ,
954
+ NtIdent ( ..) => "identifier" ,
955
+ NtLifetime ( ..) => "lifetime" ,
956
+ NtMeta ( ..) => "attribute" ,
957
+ NtPath ( ..) => "path" ,
958
+ NtVis ( ..) => "visibility" ,
959
+ }
960
+ }
944
961
}
945
962
946
963
impl PartialEq for Nonterminal {
0 commit comments