Skip to content

Commit d914ac0

Browse files
bors[bot]jrmuizel
andcommitted
Merge #744
744: mbe: Ensure repetition separator matches r=matklad a=jrmuizel Co-authored-by: Jeff Muizelaar <[email protected]>
2 parents 77a824c + a4b4732 commit d914ac0

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

crates/ra_mbe/src/lib.rs

+24
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,28 @@ impl_froms!(TokenTree: Leaf, Subtree);
256256
assert_expansion(&rules, "foo! { eggs Baz }", "struct Baz ;");
257257
}
258258

259+
#[test]
260+
fn test_match_group_pattern_by_separator_token() {
261+
let rules = create_rules(
262+
r#"
263+
macro_rules! foo {
264+
($ ($ i:ident),*) => ($ (
265+
mod $ i {}
266+
)*);
267+
($ ($ i:ident)#*) => ($ (
268+
fn $ i() {}
269+
)*);
270+
($ i:ident ,# $ j:ident) => (
271+
struct $ i;
272+
struct $ j;
273+
)
274+
}
275+
"#,
276+
);
277+
278+
assert_expansion(&rules, "foo! { foo, bar }", "mod foo {} mod bar {}");
279+
assert_expansion(&rules, "foo! { foo# bar }", "fn foo () {} fn bar () {}");
280+
assert_expansion(&rules, "foo! { Foo,# Bar }", "struct Foo ; struct Bar ;");
281+
}
282+
259283
}

crates/ra_mbe/src/mbe_expander.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,12 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Option<Bindings>
140140
}) => {
141141
while let Some(nested) = match_lhs(subtree, input) {
142142
res.push_nested(nested)?;
143-
if separator.is_some() && !input.is_eof() {
144-
input.eat_punct()?;
143+
if let Some(separator) = *separator {
144+
if !input.is_eof() {
145+
if input.eat_punct()?.char != separator {
146+
return None;
147+
}
148+
}
145149
}
146150
}
147151
}

0 commit comments

Comments
 (0)