diff --git a/crates/hir_def/src/macro_expansion_tests.rs b/crates/hir_def/src/macro_expansion_tests.rs index a899b2c1f3..96957471c8 100644 --- a/crates/hir_def/src/macro_expansion_tests.rs +++ b/crates/hir_def/src/macro_expansion_tests.rs @@ -103,7 +103,7 @@ fn pretty_print_macro_expansion(expn: SyntaxNode) -> String { _ if prev_kind.is_trivia() || curr_kind.is_trivia() => "", (T![=], _) | (_, T![=]) => " ", (_, T!['{']) => " ", - (T![;], _) => "\n", + (T![;] | T!['}'], _) => "\n", (IDENT | LIFETIME_IDENT, IDENT | LIFETIME_IDENT) => " ", (IDENT, _) if curr_kind.is_keyword() => " ", (_, IDENT) if prev_kind.is_keyword() => " ", diff --git a/crates/hir_def/src/macro_expansion_tests/mbe.rs b/crates/hir_def/src/macro_expansion_tests/mbe.rs index bb39dd4492..c57e9cd838 100644 --- a/crates/hir_def/src/macro_expansion_tests/mbe.rs +++ b/crates/hir_def/src/macro_expansion_tests/mbe.rs @@ -124,3 +124,38 @@ struct Baz; "#]], ); } + +#[test] +fn match_by_separator_token() { + check( + r#" +macro_rules! m { + ($ ($ i:ident),*) => ($ ( mod $ i {} )*); + ($ ($ i:ident)#*) => ($ ( fn $ i() {} )*); + ($ i:ident ,# $ j:ident) => ( struct $ i; struct $ j; ) +} + +m! { foo, bar } + +m! { foo# bar } + +m! { Foo,# Bar } +"#, + expect![[r##" +macro_rules! m { + ($ ($ i:ident),*) => ($ ( mod $ i {} )*); + ($ ($ i:ident)#*) => ($ ( fn $ i() {} )*); + ($ i:ident ,# $ j:ident) => ( struct $ i; struct $ j; ) +} + +mod foo {} +mod bar {} + +fn foo() {} +fn bar() {} + +struct Foo; +struct Bar; +"##]], + ); +} diff --git a/crates/mbe/src/tests/expand.rs b/crates/mbe/src/tests/expand.rs index 33bdcbf0f8..7becaa6658 100644 --- a/crates/mbe/src/tests/expand.rs +++ b/crates/mbe/src/tests/expand.rs @@ -209,29 +209,6 @@ fn test_expr_order() { ); } -#[test] -fn test_match_group_pattern_by_separator_token() { - parse_macro( - r#" - macro_rules! foo { - ($ ($ i:ident),*) => ($ ( - mod $ i {} - )*); - ($ ($ i:ident)#*) => ($ ( - fn $ i() {} - )*); - ($ i:ident ,# $ j:ident) => ( - struct $ i; - struct $ j; - ) - } -"#, - ) - .assert_expand_items("foo! { foo, bar }", "mod foo {} mod bar {}") - .assert_expand_items("foo! { foo# bar }", "fn foo () {} fn bar () {}") - .assert_expand_items("foo! { Foo,# Bar }", "struct Foo ; struct Bar ;"); -} - #[test] fn test_match_group_pattern_with_multiple_defs() { parse_macro(