diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-12-28 12:26:55 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-28 12:26:55 +0000 |
commit | 99ec2f623d4446bcc0befe17a98db9c7062b8009 (patch) | |
tree | 280da6ea56a904e43b4edc57974e29d55daffcb8 /crates/mbe/src/tests.rs | |
parent | 86f947c1fb61c17140653f43e5f6e3e5c0ed057d (diff) | |
parent | b5c29af02a88d0354ae1cbdabb41d481132f476e (diff) |
Merge #7059
7059: Special case $_ in meta var instead of treat it as ident in mbe r=lnicola a=edwin0cheng
In #6929, we treat '_' as an ident but rustc is only allow it in some special places (e.g. meta var in mbe , type, pat etc).
This PR rollback that and we only make '$_' works in meta var matching.
Fixes #7056
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/mbe/src/tests.rs')
-rw-r--r-- | crates/mbe/src/tests.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/crates/mbe/src/tests.rs b/crates/mbe/src/tests.rs index 6cd0ed205..9958a33a0 100644 --- a/crates/mbe/src/tests.rs +++ b/crates/mbe/src/tests.rs | |||
@@ -1020,6 +1020,42 @@ fn test_underscore() { | |||
1020 | } | 1020 | } |
1021 | 1021 | ||
1022 | #[test] | 1022 | #[test] |
1023 | fn test_underscore_not_greedily() { | ||
1024 | parse_macro( | ||
1025 | r#" | ||
1026 | macro_rules! q { | ||
1027 | ($($a:ident)* _) => {0}; | ||
1028 | } | ||
1029 | "#, | ||
1030 | ) | ||
1031 | // `_` overlaps with `$a:ident` but rustc matches it under the `_` token | ||
1032 | .assert_expand_items(r#"q![a b c d _]"#, r#"0"#); | ||
1033 | |||
1034 | parse_macro( | ||
1035 | r#" | ||
1036 | macro_rules! q { | ||
1037 | ($($a:expr => $b:ident)* _ => $c:expr) => {0}; | ||
1038 | } | ||
1039 | "#, | ||
1040 | ) | ||
1041 | // `_ => ou` overlaps with `$a:expr => $b:ident` but rustc matches it under `_ => $c:expr` | ||
1042 | .assert_expand_items(r#"q![a => b c => d _ => ou]"#, r#"0"#); | ||
1043 | } | ||
1044 | |||
1045 | #[test] | ||
1046 | fn test_underscore_as_type() { | ||
1047 | parse_macro( | ||
1048 | r#" | ||
1049 | macro_rules! q { | ||
1050 | ($a:ty) => {0}; | ||
1051 | } | ||
1052 | "#, | ||
1053 | ) | ||
1054 | // Underscore is a type | ||
1055 | .assert_expand_items(r#"q![_]"#, r#"0"#); | ||
1056 | } | ||
1057 | |||
1058 | #[test] | ||
1023 | fn test_vertical_bar_with_pat() { | 1059 | fn test_vertical_bar_with_pat() { |
1024 | parse_macro( | 1060 | parse_macro( |
1025 | r#" | 1061 | r#" |