@@ -112,7 +112,7 @@ impl Lit {
112
112
}
113
113
Literal ( token_lit) => Some ( token_lit) ,
114
114
Interpolated ( ref nt)
115
- if let NtExpr ( expr, _ ) | NtLiteral ( expr, _ ) = & * * nt
115
+ if let NtExpr ( expr) | NtLiteral ( expr) = & nt . 0
116
116
&& let ast:: ExprKind :: Lit ( token_lit) = expr. kind =>
117
117
{
118
118
Some ( token_lit)
@@ -289,7 +289,7 @@ pub enum TokenKind {
289
289
/// - It prevents `Token` from implementing `Copy`.
290
290
/// It adds complexity and likely slows things down. Please don't add new
291
291
/// occurrences of this token kind!
292
- Interpolated ( Lrc < Nonterminal > ) ,
292
+ Interpolated ( Lrc < ( Nonterminal , Span ) > ) ,
293
293
294
294
/// A doc comment token.
295
295
/// `Symbol` is the doc comment's data excluding its "quotes" (`///`, `/**`, etc)
@@ -395,7 +395,7 @@ impl Token {
395
395
/// if they keep spans or perform edition checks.
396
396
pub fn uninterpolated_span ( & self ) -> Span {
397
397
match & self . kind {
398
- Interpolated ( nt) => nt. use_span ( ) ,
398
+ Interpolated ( nt) => nt. 0 . use_span ( ) ,
399
399
_ => self . span ,
400
400
}
401
401
}
@@ -438,7 +438,7 @@ impl Token {
438
438
ModSep | // global path
439
439
Lifetime ( ..) | // labeled loop
440
440
Pound => true , // expression attributes
441
- Interpolated ( ref nt) => matches ! ( * * nt , NtLiteral ( ..) |
441
+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
442
442
NtExpr ( ..) |
443
443
NtBlock ( ..) |
444
444
NtPath ( ..) ) ,
@@ -462,7 +462,7 @@ impl Token {
462
462
| DotDot | DotDotDot | DotDotEq // ranges
463
463
| Lt | BinOp ( Shl ) // associated path
464
464
| ModSep => true , // global path
465
- Interpolated ( ref nt) => matches ! ( * * nt , NtLiteral ( ..) |
465
+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
466
466
NtPat ( ..) |
467
467
NtBlock ( ..) |
468
468
NtPath ( ..) ) ,
@@ -485,7 +485,7 @@ impl Token {
485
485
Lifetime ( ..) | // lifetime bound in trait object
486
486
Lt | BinOp ( Shl ) | // associated path
487
487
ModSep => true , // global path
488
- Interpolated ( ref nt) => matches ! ( * * nt , NtTy ( ..) | NtPath ( ..) ) ,
488
+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtTy ( ..) | NtPath ( ..) ) ,
489
489
// For anonymous structs or unions, which only appear in specific positions
490
490
// (type of struct fields or union fields), we don't consider them as regular types
491
491
_ => false ,
@@ -496,7 +496,7 @@ impl Token {
496
496
pub fn can_begin_const_arg ( & self ) -> bool {
497
497
match self . kind {
498
498
OpenDelim ( Delimiter :: Brace ) => true ,
499
- Interpolated ( ref nt) => matches ! ( * * nt , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
499
+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
500
500
_ => self . can_begin_literal_maybe_minus ( ) ,
501
501
}
502
502
}
@@ -550,9 +550,9 @@ impl Token {
550
550
match self . uninterpolate ( ) . kind {
551
551
Literal ( ..) | BinOp ( Minus ) => true ,
552
552
Ident ( name, false ) if name. is_bool_lit ( ) => true ,
553
- Interpolated ( ref nt) => match & * * nt {
553
+ Interpolated ( ref nt) => match & nt . 0 {
554
554
NtLiteral ( ..) => true ,
555
- NtExpr ( e, _ ) => match & e. kind {
555
+ NtExpr ( e) => match & e. kind {
556
556
ast:: ExprKind :: Lit ( _) => true ,
557
557
ast:: ExprKind :: Unary ( ast:: UnOp :: Neg , e) => {
558
558
matches ! ( & e. kind, ast:: ExprKind :: Lit ( _) )
@@ -571,11 +571,11 @@ impl Token {
571
571
/// otherwise returns the original token.
572
572
pub fn uninterpolate ( & self ) -> Cow < ' _ , Token > {
573
573
match & self . kind {
574
- Interpolated ( nt) => match * * nt {
575
- NtIdent ( ident, is_raw, _ ) => {
576
- Cow :: Owned ( Token :: new ( Ident ( ident. name , is_raw) , ident. span ) )
574
+ Interpolated ( nt) => match & nt . 0 {
575
+ NtIdent ( ident, is_raw) => {
576
+ Cow :: Owned ( Token :: new ( Ident ( ident. name , * is_raw) , ident. span ) )
577
577
}
578
- NtLifetime ( ident, _ ) => Cow :: Owned ( Token :: new ( Lifetime ( ident. name ) , ident. span ) ) ,
578
+ NtLifetime ( ident) => Cow :: Owned ( Token :: new ( Lifetime ( ident. name ) , ident. span ) ) ,
579
579
_ => Cow :: Borrowed ( self ) ,
580
580
} ,
581
581
_ => Cow :: Borrowed ( self ) ,
@@ -588,8 +588,8 @@ impl Token {
588
588
// We avoid using `Token::uninterpolate` here because it's slow.
589
589
match & self . kind {
590
590
& Ident ( name, is_raw) => Some ( ( Ident :: new ( name, self . span ) , is_raw) ) ,
591
- Interpolated ( nt) => match * * nt {
592
- NtIdent ( ident, is_raw, _ ) => Some ( ( ident, is_raw) ) ,
591
+ Interpolated ( nt) => match & nt . 0 {
592
+ NtIdent ( ident, is_raw) => Some ( ( * ident, * is_raw) ) ,
593
593
_ => None ,
594
594
} ,
595
595
_ => None ,
@@ -602,8 +602,8 @@ impl Token {
602
602
// We avoid using `Token::uninterpolate` here because it's slow.
603
603
match & self . kind {
604
604
& Lifetime ( name) => Some ( Ident :: new ( name, self . span ) ) ,
605
- Interpolated ( nt) => match * * nt {
606
- NtLifetime ( ident, _ ) => Some ( ident) ,
605
+ Interpolated ( nt) => match & nt . 0 {
606
+ NtLifetime ( ident) => Some ( * ident) ,
607
607
_ => None ,
608
608
} ,
609
609
_ => None ,
@@ -628,7 +628,7 @@ impl Token {
628
628
629
629
/// Returns `true` if the token is an interpolated path.
630
630
fn is_path ( & self ) -> bool {
631
- if let Interpolated ( nt) = & self . kind && let NtPath ( ..) = * * nt {
631
+ if let Interpolated ( nt) = & self . kind && let NtPath ( ..) = & nt . 0 {
632
632
return true ;
633
633
}
634
634
@@ -640,7 +640,7 @@ impl Token {
640
640
/// (which happens while parsing the result of macro expansion)?
641
641
pub fn is_whole_expr ( & self ) -> bool {
642
642
if let Interpolated ( nt) = & self . kind
643
- && let NtExpr ( ..) | NtLiteral ( ..) | NtPath ( ..) | NtBlock ( ..) = * * nt
643
+ && let NtExpr ( ..) | NtLiteral ( ..) | NtPath ( ..) | NtBlock ( ..) = & nt . 0
644
644
{
645
645
return true ;
646
646
}
@@ -650,7 +650,7 @@ impl Token {
650
650
651
651
/// Is the token an interpolated block (`$b:block`)?
652
652
pub fn is_whole_block ( & self ) -> bool {
653
- if let Interpolated ( nt) = & self . kind && let NtBlock ( ..) = * * nt {
653
+ if let Interpolated ( nt) = & self . kind && let NtBlock ( ..) = & nt . 0 {
654
654
return true ;
655
655
}
656
656
@@ -803,19 +803,19 @@ impl PartialEq<TokenKind> for Token {
803
803
#[ derive( Clone , Encodable , Decodable ) ]
804
804
/// For interpolation during macro expansion.
805
805
pub enum Nonterminal {
806
- NtItem ( P < ast:: Item > , Span ) ,
807
- NtBlock ( P < ast:: Block > , Span ) ,
808
- NtStmt ( P < ast:: Stmt > , Span ) ,
809
- NtPat ( P < ast:: Pat > , Span ) ,
810
- NtExpr ( P < ast:: Expr > , Span ) ,
811
- NtTy ( P < ast:: Ty > , Span ) ,
812
- NtIdent ( Ident , /* is_raw */ bool , Span ) ,
813
- NtLifetime ( Ident , Span ) ,
814
- NtLiteral ( P < ast:: Expr > , Span ) ,
806
+ NtItem ( P < ast:: Item > ) ,
807
+ NtBlock ( P < ast:: Block > ) ,
808
+ NtStmt ( P < ast:: Stmt > ) ,
809
+ NtPat ( P < ast:: Pat > ) ,
810
+ NtExpr ( P < ast:: Expr > ) ,
811
+ NtTy ( P < ast:: Ty > ) ,
812
+ NtIdent ( Ident , /* is_raw */ bool ) ,
813
+ NtLifetime ( Ident ) ,
814
+ NtLiteral ( P < ast:: Expr > ) ,
815
815
/// Stuff inside brackets for attributes
816
- NtMeta ( P < ast:: AttrItem > , Span ) ,
817
- NtPath ( P < ast:: Path > , Span ) ,
818
- NtVis ( P < ast:: Visibility > , Span ) ,
816
+ NtMeta ( P < ast:: AttrItem > ) ,
817
+ NtPath ( P < ast:: Path > ) ,
818
+ NtVis ( P < ast:: Visibility > ) ,
819
819
}
820
820
821
821
#[ derive( Debug , Copy , Clone , PartialEq , Encodable , Decodable ) ]
@@ -899,33 +899,16 @@ impl fmt::Display for NonterminalKind {
899
899
impl Nonterminal {
900
900
pub fn use_span ( & self ) -> Span {
901
901
match self {
902
- NtItem ( item, _) => item. span ,
903
- NtBlock ( block, _) => block. span ,
904
- NtStmt ( stmt, _) => stmt. span ,
905
- NtPat ( pat, _) => pat. span ,
906
- NtExpr ( expr, _) | NtLiteral ( expr, _) => expr. span ,
907
- NtTy ( ty, _) => ty. span ,
908
- NtIdent ( ident, _, _) | NtLifetime ( ident, _) => ident. span ,
909
- NtMeta ( attr_item, _) => attr_item. span ( ) ,
910
- NtPath ( path, _) => path. span ,
911
- NtVis ( vis, _) => vis. span ,
912
- }
913
- }
914
-
915
- pub fn def_span ( & self ) -> Span {
916
- match self {
917
- NtItem ( _, span)
918
- | NtBlock ( _, span)
919
- | NtStmt ( _, span)
920
- | NtPat ( _, span)
921
- | NtExpr ( _, span)
922
- | NtLiteral ( _, span)
923
- | NtTy ( _, span)
924
- | NtIdent ( _, _, span)
925
- | NtLifetime ( _, span)
926
- | NtMeta ( _, span)
927
- | NtPath ( _, span)
928
- | NtVis ( _, span) => * span,
902
+ NtItem ( item) => item. span ,
903
+ NtBlock ( block) => block. span ,
904
+ NtStmt ( stmt) => stmt. span ,
905
+ NtPat ( pat) => pat. span ,
906
+ NtExpr ( expr) | NtLiteral ( expr) => expr. span ,
907
+ NtTy ( ty) => ty. span ,
908
+ NtIdent ( ident, _) | NtLifetime ( ident) => ident. span ,
909
+ NtMeta ( attr_item) => attr_item. span ( ) ,
910
+ NtPath ( path) => path. span ,
911
+ NtVis ( vis) => vis. span ,
929
912
}
930
913
}
931
914
@@ -950,10 +933,10 @@ impl Nonterminal {
950
933
impl PartialEq for Nonterminal {
951
934
fn eq ( & self , rhs : & Self ) -> bool {
952
935
match ( self , rhs) {
953
- ( NtIdent ( ident_lhs, is_raw_lhs, _ ) , NtIdent ( ident_rhs, is_raw_rhs, _ ) ) => {
936
+ ( NtIdent ( ident_lhs, is_raw_lhs) , NtIdent ( ident_rhs, is_raw_rhs) ) => {
954
937
ident_lhs == ident_rhs && is_raw_lhs == is_raw_rhs
955
938
}
956
- ( NtLifetime ( ident_lhs, _ ) , NtLifetime ( ident_rhs, _ ) ) => ident_lhs == ident_rhs,
939
+ ( NtLifetime ( ident_lhs) , NtLifetime ( ident_rhs) ) => ident_lhs == ident_rhs,
957
940
// FIXME: Assume that all "complex" nonterminal are not equal, we can't compare them
958
941
// correctly based on data from AST. This will prevent them from matching each other
959
942
// in macros. The comparison will become possible only when each nonterminal has an
@@ -999,7 +982,7 @@ mod size_asserts {
999
982
// tidy-alphabetical-start
1000
983
static_assert_size ! ( Lit , 12 ) ;
1001
984
static_assert_size ! ( LitKind , 2 ) ;
1002
- static_assert_size ! ( Nonterminal , 24 ) ;
985
+ static_assert_size ! ( Nonterminal , 16 ) ;
1003
986
static_assert_size ! ( Token , 24 ) ;
1004
987
static_assert_size ! ( TokenKind , 16 ) ;
1005
988
// tidy-alphabetical-end
0 commit comments