Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir_def/src/macro_expansion_tests/mbe/regression.rs')
-rw-r--r--crates/hir_def/src/macro_expansion_tests/mbe/regression.rs151
1 files changed, 151 insertions, 0 deletions
diff --git a/crates/hir_def/src/macro_expansion_tests/mbe/regression.rs b/crates/hir_def/src/macro_expansion_tests/mbe/regression.rs
index 5f650d458a..5e23ca88fa 100644
--- a/crates/hir_def/src/macro_expansion_tests/mbe/regression.rs
+++ b/crates/hir_def/src/macro_expansion_tests/mbe/regression.rs
@@ -728,3 +728,154 @@ impl <> Data for & 'amut G where G: Data {}
"##]],
);
}
+
+#[test]
+fn test_issue_2520() {
+ check(
+ r#"
+macro_rules! my_macro {
+ {
+ ( $(
+ $( [] $sname:ident : $stype:ty )?
+ $( [$expr:expr] $nname:ident : $ntype:ty )?
+ ),* )
+ } => {ok!(
+ Test {
+ $(
+ $( $sname, )?
+ )*
+ }
+ );};
+}
+
+my_macro! {
+ ([] p1: u32, [|_| S0K0] s: S0K0, [] k0: i32)
+}
+ "#,
+ expect![[r#"
+macro_rules! my_macro {
+ {
+ ( $(
+ $( [] $sname:ident : $stype:ty )?
+ $( [$expr:expr] $nname:ident : $ntype:ty )?
+ ),* )
+ } => {ok!(
+ Test {
+ $(
+ $( $sname, )?
+ )*
+ }
+ );};
+}
+
+ok!(Test {
+ p1, k0,
+}
+);
+ "#]],
+ );
+}
+
+#[test]
+fn test_repeat_bad_var() {
+ // FIXME: the second rule of the macro should be removed and an error about
+ // `$( $c )+` raised
+ check(
+ r#"
+macro_rules! foo {
+ ($( $b:ident )+) => { ok!($( $c )+); };
+ ($( $b:ident )+) => { ok!($( $b )+); }
+}
+
+foo!(b0 b1);
+"#,
+ expect![[r#"
+macro_rules! foo {
+ ($( $b:ident )+) => { ok!($( $c )+); };
+ ($( $b:ident )+) => { ok!($( $b )+); }
+}
+
+ok!(b0 b1);
+"#]],
+ );
+}
+
+#[test]
+fn test_issue_3861() {
+ // This is should (and does) produce a parse error. It used to infinite loop
+ // instead.
+ check(
+ r#"
+macro_rules! rgb_color {
+ ($p:expr, $t:ty) => {
+ pub fn new() {
+ let _ = 0 as $t << $p;
+ }
+ };
+}
+// +tree +errors
+rgb_color!(8 + 8, u32);
+"#,
+ expect![[r#"
+macro_rules! rgb_color {
+ ($p:expr, $t:ty) => {
+ pub fn new() {
+ let _ = 0 as $t << $p;
+ }
+ };
+}
+/* parse error: expected type */
+/* parse error: expected R_ANGLE */
+/* parse error: expected COMMA */
+/* parse error: expected R_ANGLE */
+/* parse error: expected SEMICOLON */
+pub fn new() {
+ let _ = 0as u32<<8+8;
+}
+
+"#]],
+ );
+}