Skip to content

Commit 0000f00

Browse files
committed
mbe: Add support matching for matching idents
1 parent 1997797 commit 0000f00

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

crates/ra_mbe/src/lib.rs

+24
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,28 @@ impl_froms!(TokenTree: Leaf, Subtree);
232232
assert_expansion(&rules, "foo! { bar = }", "fn bar () {}");
233233
assert_expansion(&rules, "foo! { Baz + }", "struct Baz ;");
234234
}
235+
236+
#[test]
237+
fn test_fail_match_pattern_by_word_token() {
238+
let rules = create_rules(
239+
r#"
240+
macro_rules! foo {
241+
($ i:ident) => (
242+
mod $ i {}
243+
);
244+
(spam $ i:ident) => (
245+
fn $ i() {}
246+
);
247+
(eggs $ i:ident) => (
248+
struct $ i;
249+
)
250+
}
251+
"#,
252+
);
253+
254+
assert_expansion(&rules, "foo! { foo }", "mod foo {}");
255+
assert_expansion(&rules, "foo! { spam bar }", "fn bar () {}");
256+
assert_expansion(&rules, "foo! { eggs Baz }", "struct Baz ;");
257+
}
258+
235259
}

crates/ra_mbe/src/mbe_expander.rs

+5
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Option<Bindings>
126126
return None;
127127
}
128128
}
129+
crate::Leaf::Ident(ident) => {
130+
if input.eat_ident()?.text != ident.text {
131+
return None;
132+
}
133+
}
129134
_ => return None,
130135
},
131136
crate::TokenTree::Repeat(crate::Repeat {

0 commit comments

Comments
 (0)