1
1
pub use BinOpToken :: * ;
2
2
pub use LitKind :: * ;
3
- pub use Nonterminal :: * ;
4
3
pub use TokenKind :: * ;
5
4
6
5
use crate :: ast;
7
- use crate :: ptr:: P ;
8
6
use crate :: util:: case:: Case ;
9
7
10
- use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
11
- use rustc_data_structures:: sync:: Lrc ;
12
8
use rustc_macros:: { Decodable , Encodable , HashStable_Generic } ;
13
9
use rustc_span:: symbol:: { kw, sym} ;
14
10
#[ allow( clippy:: useless_attribute) ] // FIXME: following use of `hidden_glob_reexports` incorrectly triggers `useless_attribute` lint.
@@ -282,9 +278,7 @@ impl From<IdentIsRaw> for bool {
282
278
}
283
279
}
284
280
285
- // SAFETY: due to the `Clone` impl below, all fields of all variants other than
286
- // `Interpolated` must impl `Copy`.
287
- #[ derive( PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
281
+ #[ derive( Clone , PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
288
282
pub enum TokenKind {
289
283
/* Expression-operator symbols. */
290
284
/// `=`
@@ -373,21 +367,6 @@ pub enum TokenKind {
373
367
/// the `lifetime` metavariable in the macro's RHS.
374
368
NtLifetime ( Ident ) ,
375
369
376
- /// An embedded AST node, as produced by a macro. This only exists for
377
- /// historical reasons. We'd like to get rid of it, for multiple reasons.
378
- /// - It's conceptually very strange. Saying a token can contain an AST
379
- /// node is like saying, in natural language, that a word can contain a
380
- /// sentence.
381
- /// - It requires special handling in a bunch of places in the parser.
382
- /// - It prevents `Token` from implementing `Copy`.
383
- /// It adds complexity and likely slows things down. Please don't add new
384
- /// occurrences of this token kind!
385
- ///
386
- /// The span in the surrounding `Token` is that of the metavariable in the
387
- /// macro's RHS. The span within the Nonterminal is that of the fragment
388
- /// passed to the macro at the call site.
389
- Interpolated ( Lrc < Nonterminal > ) ,
390
-
391
370
/// A doc comment token.
392
371
/// `Symbol` is the doc comment's data excluding its "quotes" (`///`, `/**`, etc)
393
372
/// similarly to symbols in string literal tokens.
@@ -397,19 +376,6 @@ pub enum TokenKind {
397
376
Eof ,
398
377
}
399
378
400
- impl Clone for TokenKind {
401
- fn clone ( & self ) -> Self {
402
- // `TokenKind` would impl `Copy` if it weren't for `Interpolated`. So
403
- // for all other variants, this implementation of `clone` is just like
404
- // a copy. This is faster than the `derive(Clone)` version which has a
405
- // separate path for every variant.
406
- match self {
407
- Interpolated ( nt) => Interpolated ( nt. clone ( ) ) ,
408
- _ => unsafe { std:: ptr:: read ( self ) } ,
409
- }
410
- }
411
- }
412
-
413
379
#[ derive( Clone , PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
414
380
pub struct Token {
415
381
pub kind : TokenKind ,
@@ -496,7 +462,6 @@ impl Token {
496
462
pub fn uninterpolated_span ( & self ) -> Span {
497
463
match self . kind {
498
464
NtIdent ( ident, _) | NtLifetime ( ident) => ident. span ,
499
- Interpolated ( ref nt) => nt. use_span ( ) ,
500
465
_ => self . span ,
501
466
}
502
467
}
@@ -514,7 +479,7 @@ impl Token {
514
479
}
515
480
516
481
OpenDelim ( ..) | CloseDelim ( ..) | Literal ( ..) | DocComment ( ..) | Ident ( ..)
517
- | NtIdent ( ..) | Lifetime ( ..) | NtLifetime ( ..) | Interpolated ( .. ) | Eof => false ,
482
+ | NtIdent ( ..) | Lifetime ( ..) | NtLifetime ( ..) | Eof => false ,
518
483
}
519
484
}
520
485
@@ -542,7 +507,6 @@ impl Token {
542
507
PathSep | // global path
543
508
Lifetime ( ..) | // labeled loop
544
509
Pound => true , // expression attributes
545
- Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
546
510
OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
547
511
NonterminalKind :: Block |
548
512
NonterminalKind :: Expr |
@@ -569,7 +533,6 @@ impl Token {
569
533
| DotDot | DotDotDot | DotDotEq // ranges
570
534
| Lt | BinOp ( Shl ) // associated path
571
535
| PathSep => true , // global path
572
- Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
573
536
OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
574
537
NonterminalKind :: Block |
575
538
NonterminalKind :: PatParam { .. } |
@@ -610,7 +573,6 @@ impl Token {
610
573
pub fn can_begin_const_arg ( & self ) -> bool {
611
574
match self . kind {
612
575
OpenDelim ( Delimiter :: Brace ) => true ,
613
- Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
614
576
OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
615
577
NonterminalKind :: Expr | NonterminalKind :: Block | NonterminalKind :: Literal ,
616
578
) ) ) => true ,
@@ -733,31 +695,20 @@ impl Token {
733
695
/// That is, is this a pre-parsed expression dropped into the token stream
734
696
/// (which happens while parsing the result of macro expansion)?
735
697
pub fn is_metavar_expr ( & self ) -> bool {
736
- #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
737
- if let Interpolated ( nt) = & self . kind
738
- && let NtBlock ( _) = & * * nt
739
- {
740
- true
741
- } else if matches ! (
698
+ matches ! (
742
699
self . is_metavar_seq( ) ,
743
- Some ( NonterminalKind :: Expr | NonterminalKind :: Literal | NonterminalKind :: Path )
744
- ) {
745
- true
746
- } else {
747
- false
748
- }
700
+ Some (
701
+ NonterminalKind :: Expr
702
+ | NonterminalKind :: Literal
703
+ | NonterminalKind :: Path
704
+ | NonterminalKind :: Block
705
+ )
706
+ )
749
707
}
750
708
751
- /// Is the token an interpolated block (`$b:block`)?
752
- pub fn is_whole_block ( & self ) -> bool {
753
- #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
754
- if let Interpolated ( nt) = & self . kind
755
- && let NtBlock ( ..) = & * * nt
756
- {
757
- return true ;
758
- }
759
-
760
- false
709
+ /// Are we at a block from a metavar (`$b:block`)?
710
+ pub fn is_metavar_block ( & self ) -> bool {
711
+ matches ! ( self . is_metavar_seq( ) , Some ( NonterminalKind :: Block ) )
761
712
}
762
713
763
714
/// Returns `true` if the token is either the `mut` or `const` keyword.
@@ -782,7 +733,8 @@ impl Token {
782
733
self . is_non_raw_ident_where ( |id| id. name == kw)
783
734
}
784
735
785
- /// 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.
736
+ /// Returns `true` if the token is a given keyword, `kw` or if `case` is `Insensitive` and this
737
+ /// token is an identifier equal to `kw` ignoring the case.
786
738
pub fn is_keyword_case ( & self , kw : Symbol , case : Case ) -> bool {
787
739
self . is_keyword ( kw)
788
740
|| ( case == Case :: Insensitive
@@ -903,7 +855,7 @@ impl Token {
903
855
Le | EqEq | Ne | Ge | AndAnd | OrOr | Tilde | BinOpEq ( ..) | At | DotDotDot
904
856
| DotDotEq | Comma | Semi | PathSep | RArrow | LArrow | FatArrow | Pound | Dollar
905
857
| Question | OpenDelim ( ..) | CloseDelim ( ..) | Literal ( ..) | Ident ( ..) | NtIdent ( ..)
906
- | Lifetime ( ..) | NtLifetime ( ..) | Interpolated ( .. ) | DocComment ( ..) | Eof => {
858
+ | Lifetime ( ..) | NtLifetime ( ..) | DocComment ( ..) | Eof => {
907
859
return None ;
908
860
}
909
861
} ;
@@ -919,12 +871,6 @@ impl PartialEq<TokenKind> for Token {
919
871
}
920
872
}
921
873
922
- #[ derive( Clone , Encodable , Decodable ) ]
923
- /// For interpolation during macro expansion.
924
- pub enum Nonterminal {
925
- NtBlock ( P < ast:: Block > ) ,
926
- }
927
-
928
874
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Encodable , Decodable , Hash , HashStable_Generic ) ]
929
875
pub enum NonterminalKind {
930
876
Item ,
@@ -1003,47 +949,6 @@ impl fmt::Display for NonterminalKind {
1003
949
}
1004
950
}
1005
951
1006
- impl Nonterminal {
1007
- pub fn use_span ( & self ) -> Span {
1008
- match self {
1009
- NtBlock ( block) => block. span ,
1010
- }
1011
- }
1012
-
1013
- pub fn descr ( & self ) -> & ' static str {
1014
- match self {
1015
- NtBlock ( ..) => "block" ,
1016
- }
1017
- }
1018
- }
1019
-
1020
- impl PartialEq for Nonterminal {
1021
- fn eq ( & self , _rhs : & Self ) -> bool {
1022
- // FIXME: Assume that all nonterminals are not equal, we can't compare them
1023
- // correctly based on data from AST. This will prevent them from matching each other
1024
- // in macros. The comparison will become possible only when each nonterminal has an
1025
- // attached token stream from which it was parsed.
1026
- false
1027
- }
1028
- }
1029
-
1030
- impl fmt:: Debug for Nonterminal {
1031
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1032
- match * self {
1033
- NtBlock ( ..) => f. pad ( "NtBlock(..)" ) ,
1034
- }
1035
- }
1036
- }
1037
-
1038
- impl < CTX > HashStable < CTX > for Nonterminal
1039
- where
1040
- CTX : crate :: HashStableContext ,
1041
- {
1042
- fn hash_stable ( & self , _hcx : & mut CTX , _hasher : & mut StableHasher ) {
1043
- panic ! ( "interpolated tokens should not be present in the HIR" )
1044
- }
1045
- }
1046
-
1047
952
// Some types are used a lot. Make sure they don't unintentionally get bigger.
1048
953
#[ cfg( target_pointer_width = "64" ) ]
1049
954
mod size_asserts {
@@ -1052,7 +957,6 @@ mod size_asserts {
1052
957
// tidy-alphabetical-start
1053
958
static_assert_size ! ( Lit , 12 ) ;
1054
959
static_assert_size ! ( LitKind , 2 ) ;
1055
- static_assert_size ! ( Nonterminal , 8 ) ;
1056
960
static_assert_size ! ( Token , 24 ) ;
1057
961
static_assert_size ! ( TokenKind , 16 ) ;
1058
962
// tidy-alphabetical-end
0 commit comments