@@ -41,6 +41,20 @@ pub enum BinOpToken {
4141 Shr ,
4242}
4343
44+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , Encodable , Decodable , Hash , HashStable_Generic ) ]
45+ pub enum InvisibleOrigin {
46+ // From the expansion of a metavariable in a declarative macro.
47+ MetaVar ( NonterminalKind ) ,
48+
49+ // Converted from `proc_macro::Delimiter` in
50+ // `proc_macro::Delimiter::to_internal`, i.e. returned by a proc macro.
51+ ProcMacro ,
52+
53+ // Converted from `TokenKind::Interpolated` in
54+ // `TokenStream::flatten_token`. Treated similarly to `ProcMacro`.
55+ FlattenToken ,
56+ }
57+
4458/// Describes how a sequence of token trees is delimited.
4559/// Cannot use `proc_macro::Delimiter` directly because this
4660/// structure should implement some additional traits.
@@ -58,7 +72,22 @@ pub enum Delimiter {
5872 /// "macro variable" `$var`. It is important to preserve operator priorities in cases like
5973 /// `$var * 3` where `$var` is `1 + 2`.
6074 /// Invisible delimiters might not survive roundtrip of a token stream through a string.
61- Invisible ,
75+ Invisible ( InvisibleOrigin ) ,
76+ }
77+
78+ impl Delimiter {
79+ // Should the parser skip these delimiters? Only happens for certain kinds
80+ // of invisible delimiters. Ideally this function will eventually disappear
81+ // and no invisible delimiters will be skipped.
82+ #[ inline]
83+ pub fn skip ( & self ) -> bool {
84+ use InvisibleOrigin :: * ;
85+ match self {
86+ Delimiter :: Parenthesis | Delimiter :: Bracket | Delimiter :: Brace => false ,
87+ Delimiter :: Invisible ( MetaVar ( _) ) => false ,
88+ Delimiter :: Invisible ( FlattenToken | ProcMacro ) => true ,
89+ }
90+ }
6291}
6392
6493// Note that the suffix is *not* considered when deciding the `LitKind` in this
@@ -873,7 +902,7 @@ impl PartialEq<TokenKind> for Token {
873902 }
874903}
875904
876- #[ derive( Debug , Copy , Clone , PartialEq , Eq , Encodable , Decodable ) ]
905+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , Encodable , Decodable , Hash , HashStable_Generic ) ]
877906pub enum NtPatKind {
878907 // Matches or-patterns. Was written using `pat` in edition 2021 or later.
879908 PatWithOr ,
@@ -883,7 +912,7 @@ pub enum NtPatKind {
883912 PatParam { inferred : bool } ,
884913}
885914
886- #[ derive( Debug , Copy , Clone , PartialEq , Eq , Encodable , Decodable ) ]
915+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , Encodable , Decodable , Hash , HashStable_Generic ) ]
887916pub enum NtExprKind {
888917 // Matches expressions using the post-edition 2024. Was written using
889918 // `expr` in edition 2024 or later.
@@ -910,7 +939,7 @@ pub enum Nonterminal {
910939 NtVis ( P < ast:: Visibility > ) ,
911940}
912941
913- #[ derive( Debug , Copy , Clone , PartialEq , Encodable , Decodable ) ]
942+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , Encodable , Decodable , Hash , HashStable_Generic ) ]
914943pub enum NonterminalKind {
915944 Item ,
916945 Block ,
0 commit comments