diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index 6f719acbfbe..2c8ad4429d8 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs @@ -256,4 +256,28 @@ fn $ i() {} assert_expansion(&rules, "foo! { eggs Baz }", "struct Baz ;"); } + #[test] + fn test_match_group_pattern_by_separator_token() { + let rules = create_rules( + r#" + macro_rules! foo { + ($ ($ i:ident),*) => ($ ( + mod $ i {} + )*); + ($ ($ i:ident)#*) => ($ ( + fn $ i() {} + )*); + ($ i:ident ,# $ j:ident) => ( + struct $ i; + struct $ j; + ) + } +"#, + ); + + assert_expansion(&rules, "foo! { foo, bar }", "mod foo {} mod bar {}"); + assert_expansion(&rules, "foo! { foo# bar }", "fn foo () {} fn bar () {}"); + assert_expansion(&rules, "foo! { Foo,# Bar }", "struct Foo ; struct Bar ;"); + } + } diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index 212e2ea92ff..04b5a403529 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs @@ -140,8 +140,12 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Option }) => { while let Some(nested) = match_lhs(subtree, input) { res.push_nested(nested)?; - if separator.is_some() && !input.is_eof() { - input.eat_punct()?; + if let Some(separator) = *separator { + if !input.is_eof() { + if input.eat_punct()?.char != separator { + return None; + } + } } } }