mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
mbe: Add support matching for matching idents
This commit is contained in:
parent
1997797adc
commit
0000f00787
2 changed files with 29 additions and 0 deletions
|
@ -232,4 +232,28 @@ impl_froms!(TokenTree: Leaf, Subtree);
|
||||||
assert_expansion(&rules, "foo! { bar = }", "fn bar () {}");
|
assert_expansion(&rules, "foo! { bar = }", "fn bar () {}");
|
||||||
assert_expansion(&rules, "foo! { Baz + }", "struct Baz ;");
|
assert_expansion(&rules, "foo! { Baz + }", "struct Baz ;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_fail_match_pattern_by_word_token() {
|
||||||
|
let rules = create_rules(
|
||||||
|
r#"
|
||||||
|
macro_rules! foo {
|
||||||
|
($ i:ident) => (
|
||||||
|
mod $ i {}
|
||||||
|
);
|
||||||
|
(spam $ i:ident) => (
|
||||||
|
fn $ i() {}
|
||||||
|
);
|
||||||
|
(eggs $ i:ident) => (
|
||||||
|
struct $ i;
|
||||||
|
)
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_expansion(&rules, "foo! { foo }", "mod foo {}");
|
||||||
|
assert_expansion(&rules, "foo! { spam bar }", "fn bar () {}");
|
||||||
|
assert_expansion(&rules, "foo! { eggs Baz }", "struct Baz ;");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,6 +126,11 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Option<Bindings>
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
crate::Leaf::Ident(ident) => {
|
||||||
|
if input.eat_ident()?.text != ident.text {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => return None,
|
_ => return None,
|
||||||
},
|
},
|
||||||
crate::TokenTree::Repeat(crate::Repeat {
|
crate::TokenTree::Repeat(crate::Repeat {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue