1
1
pub use BinOpToken :: * ;
2
2
pub use LitKind :: * ;
3
- pub use Nonterminal :: * ;
4
3
pub use NtExprKind :: * ;
5
4
pub use NtPatKind :: * ;
6
5
pub use TokenKind :: * ;
7
6
8
7
use crate :: ast;
9
- use crate :: ptr:: P ;
10
8
use crate :: util:: case:: Case ;
11
9
12
- use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
13
- use rustc_data_structures:: sync:: Lrc ;
14
10
use rustc_macros:: { Decodable , Encodable , HashStable_Generic } ;
15
11
use rustc_span:: symbol:: { kw, sym} ;
16
12
#[ allow( clippy:: useless_attribute) ] // FIXME: following use of `hidden_glob_reexports` incorrectly triggers `useless_attribute` lint.
@@ -285,9 +281,7 @@ impl From<IdentIsRaw> for bool {
285
281
}
286
282
}
287
283
288
- // SAFETY: due to the `Clone` impl below, all fields of all variants other than
289
- // `Interpolated` must impl `Copy`.
290
- #[ derive( PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
284
+ #[ derive( Clone , PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
291
285
pub enum TokenKind {
292
286
/* Expression-operator symbols. */
293
287
/// `=`
@@ -376,21 +370,6 @@ pub enum TokenKind {
376
370
/// the `lifetime` metavariable in the macro's RHS.
377
371
NtLifetime ( Ident ) ,
378
372
379
- /// An embedded AST node, as produced by a macro. This only exists for
380
- /// historical reasons. We'd like to get rid of it, for multiple reasons.
381
- /// - It's conceptually very strange. Saying a token can contain an AST
382
- /// node is like saying, in natural language, that a word can contain a
383
- /// sentence.
384
- /// - It requires special handling in a bunch of places in the parser.
385
- /// - It prevents `Token` from implementing `Copy`.
386
- /// It adds complexity and likely slows things down. Please don't add new
387
- /// occurrences of this token kind!
388
- ///
389
- /// The span in the surrounding `Token` is that of the metavariable in the
390
- /// macro's RHS. The span within the Nonterminal is that of the fragment
391
- /// passed to the macro at the call site.
392
- Interpolated ( Lrc < Nonterminal > ) ,
393
-
394
373
/// A doc comment token.
395
374
/// `Symbol` is the doc comment's data excluding its "quotes" (`///`, `/**`, etc)
396
375
/// similarly to symbols in string literal tokens.
@@ -400,19 +379,6 @@ pub enum TokenKind {
400
379
Eof ,
401
380
}
402
381
403
- impl Clone for TokenKind {
404
- fn clone ( & self ) -> Self {
405
- // `TokenKind` would impl `Copy` if it weren't for `Interpolated`. So
406
- // for all other variants, this implementation of `clone` is just like
407
- // a copy. This is faster than the `derive(Clone)` version which has a
408
- // separate path for every variant.
409
- match self {
410
- Interpolated ( nt) => Interpolated ( nt. clone ( ) ) ,
411
- _ => unsafe { std:: ptr:: read ( self ) } ,
412
- }
413
- }
414
- }
415
-
416
382
#[ derive( Clone , PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
417
383
pub struct Token {
418
384
pub kind : TokenKind ,
@@ -499,7 +465,6 @@ impl Token {
499
465
pub fn uninterpolated_span ( & self ) -> Span {
500
466
match self . kind {
501
467
NtIdent ( ident, _) | NtLifetime ( ident) => ident. span ,
502
- Interpolated ( ref nt) => nt. use_span ( ) ,
503
468
_ => self . span ,
504
469
}
505
470
}
@@ -517,7 +482,7 @@ impl Token {
517
482
}
518
483
519
484
OpenDelim ( ..) | CloseDelim ( ..) | Literal ( ..) | DocComment ( ..) | Ident ( ..)
520
- | NtIdent ( ..) | Lifetime ( ..) | NtLifetime ( ..) | Interpolated ( .. ) | Eof => false ,
485
+ | NtIdent ( ..) | Lifetime ( ..) | NtLifetime ( ..) | Eof => false ,
521
486
}
522
487
}
523
488
@@ -545,7 +510,6 @@ impl Token {
545
510
PathSep | // global path
546
511
Lifetime ( ..) | // labeled loop
547
512
Pound => true , // expression attributes
548
- Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
549
513
OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
550
514
NonterminalKind :: Block |
551
515
NonterminalKind :: Expr ( _) |
@@ -572,7 +536,6 @@ impl Token {
572
536
| DotDot | DotDotDot | DotDotEq // ranges
573
537
| Lt | BinOp ( Shl ) // associated path
574
538
| PathSep => true , // global path
575
- Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
576
539
OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
577
540
NonterminalKind :: Block |
578
541
NonterminalKind :: Pat ( _) |
@@ -613,7 +576,6 @@ impl Token {
613
576
match self . kind {
614
577
OpenDelim ( Delimiter :: Brace ) | Literal ( ..) | BinOp ( Minus ) => true ,
615
578
Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => true ,
616
- Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
617
579
OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
618
580
NonterminalKind :: Expr ( _) | NonterminalKind :: Block | NonterminalKind :: Literal ,
619
581
) ) ) => true ,
@@ -757,31 +719,20 @@ impl Token {
757
719
/// That is, is this a pre-parsed expression dropped into the token stream
758
720
/// (which happens while parsing the result of macro expansion)?
759
721
pub fn is_metavar_expr ( & self ) -> bool {
760
- #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
761
- if let Interpolated ( nt) = & self . kind
762
- && let NtBlock ( _) = & * * nt
763
- {
764
- true
765
- } else if matches ! (
722
+ matches ! (
766
723
self . is_metavar_seq( ) ,
767
- Some ( NonterminalKind :: Expr ( _) | NonterminalKind :: Literal | NonterminalKind :: Path )
768
- ) {
769
- true
770
- } else {
771
- false
772
- }
724
+ Some (
725
+ NonterminalKind :: Expr ( _)
726
+ | NonterminalKind :: Literal
727
+ | NonterminalKind :: Path
728
+ | NonterminalKind :: Block
729
+ )
730
+ )
773
731
}
774
732
775
- /// Is the token an interpolated block (`$b:block`)?
776
- pub fn is_whole_block ( & self ) -> bool {
777
- #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
778
- if let Interpolated ( nt) = & self . kind
779
- && let NtBlock ( ..) = & * * nt
780
- {
781
- return true ;
782
- }
783
-
784
- false
733
+ /// Are we at a block from a metavar (`$b:block`)?
734
+ pub fn is_metavar_block ( & self ) -> bool {
735
+ matches ! ( self . is_metavar_seq( ) , Some ( NonterminalKind :: Block ) )
785
736
}
786
737
787
738
/// Returns `true` if the token is either the `mut` or `const` keyword.
@@ -806,7 +757,8 @@ impl Token {
806
757
self . is_non_raw_ident_where ( |id| id. name == kw)
807
758
}
808
759
809
- /// 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.
760
+ /// Returns `true` if the token is a given keyword, `kw` or if `case` is `Insensitive` and this
761
+ /// token is an identifier equal to `kw` ignoring the case.
810
762
pub fn is_keyword_case ( & self , kw : Symbol , case : Case ) -> bool {
811
763
self . is_keyword ( kw)
812
764
|| ( case == Case :: Insensitive
@@ -927,7 +879,7 @@ impl Token {
927
879
Le | EqEq | Ne | Ge | AndAnd | OrOr | Tilde | BinOpEq ( ..) | At | DotDotDot
928
880
| DotDotEq | Comma | Semi | PathSep | RArrow | LArrow | FatArrow | Pound | Dollar
929
881
| Question | OpenDelim ( ..) | CloseDelim ( ..) | Literal ( ..) | Ident ( ..) | NtIdent ( ..)
930
- | Lifetime ( ..) | NtLifetime ( ..) | Interpolated ( .. ) | DocComment ( ..) | Eof => {
882
+ | Lifetime ( ..) | NtLifetime ( ..) | DocComment ( ..) | Eof => {
931
883
return None ;
932
884
}
933
885
} ;
@@ -964,12 +916,6 @@ pub enum NtExprKind {
964
916
Expr2021 { inferred : bool } ,
965
917
}
966
918
967
- #[ derive( Clone , Encodable , Decodable ) ]
968
- /// For interpolation during macro expansion.
969
- pub enum Nonterminal {
970
- NtBlock ( P < ast:: Block > ) ,
971
- }
972
-
973
919
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Encodable , Decodable , Hash , HashStable_Generic ) ]
974
920
pub enum NonterminalKind {
975
921
Item ,
@@ -1053,47 +999,6 @@ impl fmt::Display for NonterminalKind {
1053
999
}
1054
1000
}
1055
1001
1056
- impl Nonterminal {
1057
- pub fn use_span ( & self ) -> Span {
1058
- match self {
1059
- NtBlock ( block) => block. span ,
1060
- }
1061
- }
1062
-
1063
- pub fn descr ( & self ) -> & ' static str {
1064
- match self {
1065
- NtBlock ( ..) => "block" ,
1066
- }
1067
- }
1068
- }
1069
-
1070
- impl PartialEq for Nonterminal {
1071
- fn eq ( & self , _rhs : & Self ) -> bool {
1072
- // FIXME: Assume that all nonterminals are not equal, we can't compare them
1073
- // correctly based on data from AST. This will prevent them from matching each other
1074
- // in macros. The comparison will become possible only when each nonterminal has an
1075
- // attached token stream from which it was parsed.
1076
- false
1077
- }
1078
- }
1079
-
1080
- impl fmt:: Debug for Nonterminal {
1081
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1082
- match * self {
1083
- NtBlock ( ..) => f. pad ( "NtBlock(..)" ) ,
1084
- }
1085
- }
1086
- }
1087
-
1088
- impl < CTX > HashStable < CTX > for Nonterminal
1089
- where
1090
- CTX : crate :: HashStableContext ,
1091
- {
1092
- fn hash_stable ( & self , _hcx : & mut CTX , _hasher : & mut StableHasher ) {
1093
- panic ! ( "interpolated tokens should not be present in the HIR" )
1094
- }
1095
- }
1096
-
1097
1002
// Some types are used a lot. Make sure they don't unintentionally get bigger.
1098
1003
#[ cfg( target_pointer_width = "64" ) ]
1099
1004
mod size_asserts {
@@ -1102,7 +1007,6 @@ mod size_asserts {
1102
1007
// tidy-alphabetical-start
1103
1008
static_assert_size ! ( Lit , 12 ) ;
1104
1009
static_assert_size ! ( LitKind , 2 ) ;
1105
- static_assert_size ! ( Nonterminal , 8 ) ;
1106
1010
static_assert_size ! ( Token , 24 ) ;
1107
1011
static_assert_size ! ( TokenKind , 16 ) ;
1108
1012
// tidy-alphabetical-end
0 commit comments