@@ -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)
@@ -388,7 +388,8 @@ impl TokenKind {
388
388
match * self {
389
389
Comma => Some ( vec ! [ Dot , Lt , Semi ] ) ,
390
390
Semi => Some ( vec ! [ Colon , Comma ] ) ,
391
- FatArrow => Some ( vec ! [ Eq , RArrow ] ) ,
391
+ Colon => Some ( vec ! [ Semi ] ) ,
392
+ FatArrow => Some ( vec ! [ Eq , RArrow , Ge , Gt ] ) ,
392
393
_ => None ,
393
394
}
394
395
}
@@ -421,7 +422,7 @@ impl Token {
421
422
/// if they keep spans or perform edition checks.
422
423
pub fn uninterpolated_span ( & self ) -> Span {
423
424
match & self . kind {
424
- Interpolated ( nt) => nt. span ( ) ,
425
+ Interpolated ( nt) => nt. 0 . use_span ( ) ,
425
426
_ => self . span ,
426
427
}
427
428
}
@@ -464,7 +465,7 @@ impl Token {
464
465
ModSep | // global path
465
466
Lifetime ( ..) | // labeled loop
466
467
Pound => true , // expression attributes
467
- Interpolated ( ref nt) => matches ! ( * * nt , NtLiteral ( ..) |
468
+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
468
469
NtExpr ( ..) |
469
470
NtBlock ( ..) |
470
471
NtPath ( ..) ) ,
@@ -488,7 +489,7 @@ impl Token {
488
489
| DotDot | DotDotDot | DotDotEq // ranges
489
490
| Lt | BinOp ( Shl ) // associated path
490
491
| ModSep => true , // global path
491
- Interpolated ( ref nt) => matches ! ( * * nt , NtLiteral ( ..) |
492
+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
492
493
NtPat ( ..) |
493
494
NtBlock ( ..) |
494
495
NtPath ( ..) ) ,
@@ -511,7 +512,7 @@ impl Token {
511
512
Lifetime ( ..) | // lifetime bound in trait object
512
513
Lt | BinOp ( Shl ) | // associated path
513
514
ModSep => true , // global path
514
- Interpolated ( ref nt) => matches ! ( * * nt , NtTy ( ..) | NtPath ( ..) ) ,
515
+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtTy ( ..) | NtPath ( ..) ) ,
515
516
// For anonymous structs or unions, which only appear in specific positions
516
517
// (type of struct fields or union fields), we don't consider them as regular types
517
518
_ => false ,
@@ -522,7 +523,7 @@ impl Token {
522
523
pub fn can_begin_const_arg ( & self ) -> bool {
523
524
match self . kind {
524
525
OpenDelim ( Delimiter :: Brace ) => true ,
525
- Interpolated ( ref nt) => matches ! ( * * nt , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
526
+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
526
527
_ => self . can_begin_literal_maybe_minus ( ) ,
527
528
}
528
529
}
@@ -576,7 +577,7 @@ impl Token {
576
577
match self . uninterpolate ( ) . kind {
577
578
Literal ( ..) | BinOp ( Minus ) => true ,
578
579
Ident ( name, false ) if name. is_bool_lit ( ) => true ,
579
- Interpolated ( ref nt) => match & * * nt {
580
+ Interpolated ( ref nt) => match & nt . 0 {
580
581
NtLiteral ( _) => true ,
581
582
NtExpr ( e) => match & e. kind {
582
583
ast:: ExprKind :: Lit ( _) => true ,
@@ -597,9 +598,9 @@ impl Token {
597
598
/// otherwise returns the original token.
598
599
pub fn uninterpolate ( & self ) -> Cow < ' _ , Token > {
599
600
match & self . kind {
600
- Interpolated ( nt) => match * * nt {
601
+ Interpolated ( nt) => match & nt . 0 {
601
602
NtIdent ( ident, is_raw) => {
602
- Cow :: Owned ( Token :: new ( Ident ( ident. name , is_raw) , ident. span ) )
603
+ Cow :: Owned ( Token :: new ( Ident ( ident. name , * is_raw) , ident. span ) )
603
604
}
604
605
NtLifetime ( ident) => Cow :: Owned ( Token :: new ( Lifetime ( ident. name ) , ident. span ) ) ,
605
606
_ => Cow :: Borrowed ( self ) ,
@@ -614,8 +615,8 @@ impl Token {
614
615
// We avoid using `Token::uninterpolate` here because it's slow.
615
616
match & self . kind {
616
617
& 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) ) ,
618
+ Interpolated ( nt) => match & nt . 0 {
619
+ NtIdent ( ident, is_raw) => Some ( ( * ident, * is_raw) ) ,
619
620
_ => None ,
620
621
} ,
621
622
_ => None ,
@@ -628,8 +629,8 @@ impl Token {
628
629
// We avoid using `Token::uninterpolate` here because it's slow.
629
630
match & self . kind {
630
631
& Lifetime ( name) => Some ( Ident :: new ( name, self . span ) ) ,
631
- Interpolated ( nt) => match * * nt {
632
- NtLifetime ( ident) => Some ( ident) ,
632
+ Interpolated ( nt) => match & nt . 0 {
633
+ NtLifetime ( ident) => Some ( * ident) ,
633
634
_ => None ,
634
635
} ,
635
636
_ => None ,
@@ -655,7 +656,7 @@ impl Token {
655
656
/// Returns `true` if the token is an interpolated path.
656
657
fn is_path ( & self ) -> bool {
657
658
if let Interpolated ( nt) = & self . kind
658
- && let NtPath ( ..) = * * nt
659
+ && let NtPath ( ..) = & nt . 0
659
660
{
660
661
return true ;
661
662
}
@@ -668,7 +669,7 @@ impl Token {
668
669
/// (which happens while parsing the result of macro expansion)?
669
670
pub fn is_whole_expr ( & self ) -> bool {
670
671
if let Interpolated ( nt) = & self . kind
671
- && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = * * nt
672
+ && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = & nt . 0
672
673
{
673
674
return true ;
674
675
}
@@ -679,7 +680,7 @@ impl Token {
679
680
/// Is the token an interpolated block (`$b:block`)?
680
681
pub fn is_whole_block ( & self ) -> bool {
681
682
if let Interpolated ( nt) = & self . kind
682
- && let NtBlock ( ..) = * * nt
683
+ && let NtBlock ( ..) = & nt . 0
683
684
{
684
685
return true ;
685
686
}
@@ -927,7 +928,7 @@ impl fmt::Display for NonterminalKind {
927
928
}
928
929
929
930
impl Nonterminal {
930
- pub fn span ( & self ) -> Span {
931
+ pub fn use_span ( & self ) -> Span {
931
932
match self {
932
933
NtItem ( item) => item. span ,
933
934
NtBlock ( block) => block. span ,
@@ -941,6 +942,23 @@ impl Nonterminal {
941
942
NtVis ( vis) => vis. span ,
942
943
}
943
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
+ }
944
962
}
945
963
946
964
impl PartialEq for Nonterminal {
0 commit comments