@@ -3,12 +3,9 @@ use std::fmt;
3
3
4
4
pub use BinOpToken :: * ;
5
5
pub use LitKind :: * ;
6
- pub use Nonterminal :: * ;
7
6
pub use NtExprKind :: * ;
8
7
pub use NtPatKind :: * ;
9
8
pub use TokenKind :: * ;
10
- use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
11
- use rustc_data_structures:: sync:: Lrc ;
12
9
use rustc_macros:: { Decodable , Encodable , HashStable_Generic } ;
13
10
use rustc_span:: edition:: Edition ;
14
11
#[ allow( clippy:: useless_attribute) ] // FIXME: following use of `hidden_glob_reexports` incorrectly triggers `useless_attribute` lint.
@@ -18,7 +15,6 @@ use rustc_span::symbol::{kw, sym};
18
15
use rustc_span:: { DUMMY_SP , ErrorGuaranteed , Span } ;
19
16
20
17
use crate :: ast;
21
- use crate :: ptr:: P ;
22
18
use crate :: util:: case:: Case ;
23
19
24
20
#[ derive( Clone , Copy , PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
@@ -52,8 +48,8 @@ pub enum InvisibleOrigin {
52
48
// `proc_macro::Delimiter::to_internal`, i.e. returned by a proc macro.
53
49
ProcMacro ,
54
50
55
- // Converted from `TokenKind::Interpolated ` in
56
- // `TokenStream::flatten_token`. Treated similarly to `ProcMacro`.
51
+ // Converted from `TokenKind::NtLifetime ` in `TokenStream::flatten_token`.
52
+ // Treated similarly to `ProcMacro`.
57
53
FlattenToken ,
58
54
}
59
55
@@ -349,9 +345,7 @@ impl From<IdentIsRaw> for bool {
349
345
}
350
346
}
351
347
352
- // SAFETY: due to the `Clone` impl below, all fields of all variants other than
353
- // `Interpolated` must impl `Copy`.
354
- #[ derive( PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
348
+ #[ derive( Clone , PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
355
349
pub enum TokenKind {
356
350
/* Expression-operator symbols. */
357
351
/// `=`
@@ -440,21 +434,6 @@ pub enum TokenKind {
440
434
/// the `lifetime` metavariable in the macro's RHS.
441
435
NtLifetime ( Ident , IdentIsRaw ) ,
442
436
443
- /// An embedded AST node, as produced by a macro. This only exists for
444
- /// historical reasons. We'd like to get rid of it, for multiple reasons.
445
- /// - It's conceptually very strange. Saying a token can contain an AST
446
- /// node is like saying, in natural language, that a word can contain a
447
- /// sentence.
448
- /// - It requires special handling in a bunch of places in the parser.
449
- /// - It prevents `Token` from implementing `Copy`.
450
- /// It adds complexity and likely slows things down. Please don't add new
451
- /// occurrences of this token kind!
452
- ///
453
- /// The span in the surrounding `Token` is that of the metavariable in the
454
- /// macro's RHS. The span within the Nonterminal is that of the fragment
455
- /// passed to the macro at the call site.
456
- Interpolated ( Lrc < Nonterminal > ) ,
457
-
458
437
/// A doc comment token.
459
438
/// `Symbol` is the doc comment's data excluding its "quotes" (`///`, `/**`, etc)
460
439
/// similarly to symbols in string literal tokens.
@@ -464,19 +443,6 @@ pub enum TokenKind {
464
443
Eof ,
465
444
}
466
445
467
- impl Clone for TokenKind {
468
- fn clone ( & self ) -> Self {
469
- // `TokenKind` would impl `Copy` if it weren't for `Interpolated`. So
470
- // for all other variants, this implementation of `clone` is just like
471
- // a copy. This is faster than the `derive(Clone)` version which has a
472
- // separate path for every variant.
473
- match self {
474
- Interpolated ( nt) => Interpolated ( nt. clone ( ) ) ,
475
- _ => unsafe { std:: ptr:: read ( self ) } ,
476
- }
477
- }
478
- }
479
-
480
446
#[ derive( Clone , PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
481
447
pub struct Token {
482
448
pub kind : TokenKind ,
@@ -571,7 +537,6 @@ impl Token {
571
537
pub fn uninterpolated_span ( & self ) -> Span {
572
538
match self . kind {
573
539
NtIdent ( ident, _) | NtLifetime ( ident, _) => ident. span ,
574
- Interpolated ( ref nt) => nt. use_span ( ) ,
575
540
_ => self . span ,
576
541
}
577
542
}
@@ -589,7 +554,7 @@ impl Token {
589
554
}
590
555
591
556
OpenDelim ( ..) | CloseDelim ( ..) | Literal ( ..) | DocComment ( ..) | Ident ( ..)
592
- | NtIdent ( ..) | Lifetime ( ..) | NtLifetime ( ..) | Interpolated ( .. ) | Eof => false ,
557
+ | NtIdent ( ..) | Lifetime ( ..) | NtLifetime ( ..) | Eof => false ,
593
558
}
594
559
}
595
560
@@ -620,7 +585,6 @@ impl Token {
620
585
PathSep | // global path
621
586
Lifetime ( ..) | // labeled loop
622
587
Pound => true , // expression attributes
623
- Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
624
588
OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
625
589
MetaVarKind :: Block |
626
590
MetaVarKind :: Expr { .. } |
@@ -693,7 +657,6 @@ impl Token {
693
657
match self . kind {
694
658
OpenDelim ( Delimiter :: Brace ) | Literal ( ..) | BinOp ( Minus ) => true ,
695
659
Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => true ,
696
- Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
697
660
OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
698
661
MetaVarKind :: Expr { .. } | MetaVarKind :: Block | MetaVarKind :: Literal ,
699
662
) ) ) => true ,
@@ -821,31 +784,20 @@ impl Token {
821
784
/// Is this a pre-parsed expression dropped into the token stream
822
785
/// (which happens while parsing the result of macro expansion)?
823
786
pub fn is_metavar_expr ( & self ) -> bool {
824
- #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
825
- if let Interpolated ( nt) = & self . kind
826
- && let NtBlock ( _) = & * * nt
827
- {
828
- true
829
- } else if matches ! (
787
+ matches ! (
830
788
self . is_metavar_seq( ) ,
831
- Some ( MetaVarKind :: Expr { .. } | MetaVarKind :: Literal | MetaVarKind :: Path )
832
- ) {
833
- true
834
- } else {
835
- false
836
- }
789
+ Some (
790
+ MetaVarKind :: Expr { .. }
791
+ | MetaVarKind :: Literal
792
+ | MetaVarKind :: Path
793
+ | MetaVarKind :: Block
794
+ )
795
+ )
837
796
}
838
797
839
- /// Is the token an interpolated block (`$b:block`)?
840
- pub fn is_whole_block ( & self ) -> bool {
841
- #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
842
- if let Interpolated ( nt) = & self . kind
843
- && let NtBlock ( ..) = & * * nt
844
- {
845
- return true ;
846
- }
847
-
848
- false
798
+ /// Are we at a block from a metavar (`$b:block`)?
799
+ pub fn is_metavar_block ( & self ) -> bool {
800
+ matches ! ( self . is_metavar_seq( ) , Some ( MetaVarKind :: Block ) )
849
801
}
850
802
851
803
/// Returns `true` if the token is either the `mut` or `const` keyword.
@@ -870,7 +822,8 @@ impl Token {
870
822
self . is_non_raw_ident_where ( |id| id. name == kw)
871
823
}
872
824
873
- /// Returns `true` if the token is a given keyword, `kw` or if `case` is `Insensitive` and this token is an identifier equal to `kw` ignoring the case.
825
+ /// Returns `true` if the token is a given keyword, `kw` or if `case` is `Insensitive` and this
826
+ /// token is an identifier equal to `kw` ignoring the case.
874
827
pub fn is_keyword_case ( & self , kw : Symbol , case : Case ) -> bool {
875
828
self . is_keyword ( kw)
876
829
|| ( case == Case :: Insensitive
@@ -991,7 +944,7 @@ impl Token {
991
944
Le | EqEq | Ne | Ge | AndAnd | OrOr | Tilde | BinOpEq ( ..) | At | DotDotDot
992
945
| DotDotEq | Comma | Semi | PathSep | RArrow | LArrow | FatArrow | Pound | Dollar
993
946
| Question | OpenDelim ( ..) | CloseDelim ( ..) | Literal ( ..) | Ident ( ..) | NtIdent ( ..)
994
- | Lifetime ( ..) | NtLifetime ( ..) | Interpolated ( .. ) | DocComment ( ..) | Eof => {
947
+ | Lifetime ( ..) | NtLifetime ( ..) | DocComment ( ..) | Eof => {
995
948
return None ;
996
949
}
997
950
} ;
@@ -1028,12 +981,6 @@ pub enum NtExprKind {
1028
981
Expr2021 { inferred : bool } ,
1029
982
}
1030
983
1031
- #[ derive( Clone , Encodable , Decodable ) ]
1032
- /// For interpolation during macro expansion.
1033
- pub enum Nonterminal {
1034
- NtBlock ( P < ast:: Block > ) ,
1035
- }
1036
-
1037
984
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Encodable , Decodable , Hash , HashStable_Generic ) ]
1038
985
pub enum NonterminalKind {
1039
986
Item ,
@@ -1117,47 +1064,6 @@ impl fmt::Display for NonterminalKind {
1117
1064
}
1118
1065
}
1119
1066
1120
- impl Nonterminal {
1121
- pub fn use_span ( & self ) -> Span {
1122
- match self {
1123
- NtBlock ( block) => block. span ,
1124
- }
1125
- }
1126
-
1127
- pub fn descr ( & self ) -> & ' static str {
1128
- match self {
1129
- NtBlock ( ..) => "block" ,
1130
- }
1131
- }
1132
- }
1133
-
1134
- impl PartialEq for Nonterminal {
1135
- fn eq ( & self , _rhs : & Self ) -> bool {
1136
- // FIXME: Assume that all nonterminals are not equal, we can't compare them
1137
- // correctly based on data from AST. This will prevent them from matching each other
1138
- // in macros. The comparison will become possible only when each nonterminal has an
1139
- // attached token stream from which it was parsed.
1140
- false
1141
- }
1142
- }
1143
-
1144
- impl fmt:: Debug for Nonterminal {
1145
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1146
- match * self {
1147
- NtBlock ( ..) => f. pad ( "NtBlock(..)" ) ,
1148
- }
1149
- }
1150
- }
1151
-
1152
- impl < CTX > HashStable < CTX > for Nonterminal
1153
- where
1154
- CTX : crate :: HashStableContext ,
1155
- {
1156
- fn hash_stable ( & self , _hcx : & mut CTX , _hasher : & mut StableHasher ) {
1157
- panic ! ( "interpolated tokens should not be present in the HIR" )
1158
- }
1159
- }
1160
-
1161
1067
// Some types are used a lot. Make sure they don't unintentionally get bigger.
1162
1068
#[ cfg( target_pointer_width = "64" ) ]
1163
1069
mod size_asserts {
@@ -1167,7 +1073,6 @@ mod size_asserts {
1167
1073
// tidy-alphabetical-start
1168
1074
static_assert_size ! ( Lit , 12 ) ;
1169
1075
static_assert_size ! ( LitKind , 2 ) ;
1170
- static_assert_size ! ( Nonterminal , 8 ) ;
1171
1076
static_assert_size ! ( Token , 24 ) ;
1172
1077
static_assert_size ! ( TokenKind , 16 ) ;
1173
1078
// tidy-alphabetical-end
0 commit comments