1
1
pub use BinOpToken :: * ;
2
2
pub use LitKind :: * ;
3
3
pub use Nonterminal :: * ;
4
+ pub use NtExprKind :: * ;
5
+ pub use NtPatKind :: * ;
4
6
pub use TokenKind :: * ;
5
7
6
8
use crate :: ast;
@@ -871,6 +873,27 @@ impl PartialEq<TokenKind> for Token {
871
873
}
872
874
}
873
875
876
+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , Encodable , Decodable ) ]
877
+ pub enum NtPatKind {
878
+ // Matches or-patterns. Was written using `pat` in edition 2021 or later.
879
+ PatWithOr ,
880
+ // Doesn't match or-patterns.
881
+ // - `inferred`: was written using `pat` in edition 2015 or 2018.
882
+ // - `!inferred`: was written using `pat_param`.
883
+ PatParam { inferred : bool } ,
884
+ }
885
+
886
+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , Encodable , Decodable ) ]
887
+ pub enum NtExprKind {
888
+ // Matches expressions using the post-edition 2024. Was written using
889
+ // `expr` in edition 2024 or later.
890
+ Expr ,
891
+ // Matches expressions using the pre-edition 2024 rules.
892
+ // - `inferred`: was written using `expr` in edition 2021 or earlier.
893
+ // - `!inferred`: was written using `expr_2021`.
894
+ Expr2021 { inferred : bool } ,
895
+ }
896
+
874
897
#[ derive( Clone , Encodable , Decodable ) ]
875
898
/// For interpolation during macro expansion.
876
899
pub enum Nonterminal {
@@ -892,19 +915,8 @@ pub enum NonterminalKind {
892
915
Item ,
893
916
Block ,
894
917
Stmt ,
895
- PatParam {
896
- /// Keep track of whether the user used `:pat_param` or `:pat` and we inferred it from the
897
- /// edition of the span. This is used for diagnostics.
898
- inferred : bool ,
899
- } ,
900
- PatWithOr ,
901
- Expr ,
902
- /// Matches an expression using the rules from edition 2021 and earlier.
903
- Expr2021 {
904
- /// Keep track of whether the user used `:expr` or `:expr_2021` and we inferred it from the
905
- /// edition of the span. This is used for diagnostics AND feature gating.
906
- inferred : bool ,
907
- } ,
918
+ Pat ( NtPatKind ) ,
919
+ Expr ( NtExprKind ) ,
908
920
Ty ,
909
921
Ident ,
910
922
Lifetime ,
@@ -926,20 +938,22 @@ impl NonterminalKind {
926
938
sym:: item => NonterminalKind :: Item ,
927
939
sym:: block => NonterminalKind :: Block ,
928
940
sym:: stmt => NonterminalKind :: Stmt ,
929
- sym:: pat => match edition ( ) {
930
- Edition :: Edition2015 | Edition :: Edition2018 => {
931
- NonterminalKind :: PatParam { inferred : true }
941
+ sym:: pat => {
942
+ if edition ( ) . at_least_rust_2021 ( ) {
943
+ NonterminalKind :: Pat ( PatWithOr )
944
+ } else {
945
+ NonterminalKind :: Pat ( PatParam { inferred : true } )
932
946
}
933
- Edition :: Edition2021 | Edition :: Edition2024 => NonterminalKind :: PatWithOr ,
934
- } ,
935
- sym:: pat_param => NonterminalKind :: PatParam { inferred : false } ,
936
- sym:: expr => match edition ( ) {
937
- Edition :: Edition2015 | Edition :: Edition2018 | Edition :: Edition2021 => {
938
- NonterminalKind :: Expr2021 { inferred : true }
947
+ }
948
+ sym:: pat_param => NonterminalKind :: Pat ( PatParam { inferred : false } ) ,
949
+ sym:: expr => {
950
+ if edition ( ) . at_least_rust_2024 ( ) {
951
+ NonterminalKind :: Expr ( Expr )
952
+ } else {
953
+ NonterminalKind :: Expr ( Expr2021 { inferred : true } )
939
954
}
940
- Edition :: Edition2024 => NonterminalKind :: Expr ,
941
- } ,
942
- sym:: expr_2021 => NonterminalKind :: Expr2021 { inferred : false } ,
955
+ }
956
+ sym:: expr_2021 => NonterminalKind :: Expr ( Expr2021 { inferred : false } ) ,
943
957
sym:: ty => NonterminalKind :: Ty ,
944
958
sym:: ident => NonterminalKind :: Ident ,
945
959
sym:: lifetime => NonterminalKind :: Lifetime ,
@@ -951,15 +965,16 @@ impl NonterminalKind {
951
965
_ => return None ,
952
966
} )
953
967
}
968
+
954
969
fn symbol ( self ) -> Symbol {
955
970
match self {
956
971
NonterminalKind :: Item => sym:: item,
957
972
NonterminalKind :: Block => sym:: block,
958
973
NonterminalKind :: Stmt => sym:: stmt,
959
- NonterminalKind :: PatParam { inferred : false } => sym:: pat_param ,
960
- NonterminalKind :: PatParam { inferred : true } | NonterminalKind :: PatWithOr => sym:: pat ,
961
- NonterminalKind :: Expr | NonterminalKind :: Expr2021 { inferred : true } => sym:: expr,
962
- NonterminalKind :: Expr2021 { inferred : false } => sym:: expr_2021,
974
+ NonterminalKind :: Pat ( PatParam { inferred : true } | PatWithOr ) => sym:: pat ,
975
+ NonterminalKind :: Pat ( PatParam { inferred : false } ) => sym:: pat_param ,
976
+ NonterminalKind :: Expr ( Expr2021 { inferred : true } | Expr ) => sym:: expr,
977
+ NonterminalKind :: Expr ( Expr2021 { inferred : false } ) => sym:: expr_2021,
963
978
NonterminalKind :: Ty => sym:: ty,
964
979
NonterminalKind :: Ident => sym:: ident,
965
980
NonterminalKind :: Lifetime => sym:: lifetime,
0 commit comments