mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 17:28:09 +00:00
Fix match literal
This commit is contained in:
parent
3894eb77d8
commit
ad9d2012de
2 changed files with 19 additions and 1 deletions
|
@ -281,7 +281,11 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result<Bindings,
|
|||
return Err(ExpandError::UnexpectedToken);
|
||||
}
|
||||
}
|
||||
_ => return Err(ExpandError::UnexpectedToken),
|
||||
crate::Leaf::Literal(literal) => {
|
||||
if input.eat_literal().map(|i| &i.text) != Some(&literal.text) {
|
||||
return Err(ExpandError::UnexpectedToken);
|
||||
}
|
||||
}
|
||||
},
|
||||
crate::TokenTree::Repeat(crate::Repeat { subtree, kind, separator }) => {
|
||||
// Dirty hack to make macro-expansion terminate.
|
||||
|
|
|
@ -575,6 +575,20 @@ fn test_tt_to_stmts() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_match_literal() {
|
||||
let rules = create_rules(
|
||||
r#"
|
||||
macro_rules! foo {
|
||||
('(') => {
|
||||
fn foo() {}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
assert_expansion(MacroKind::Items, &rules, "foo! ['(']", "fn foo () {}");
|
||||
}
|
||||
|
||||
// The following tests are port from intellij-rust directly
|
||||
// https://github.com/intellij-rust/intellij-rust/blob/c4e9feee4ad46e7953b1948c112533360b6087bb/src/test/kotlin/org/rust/lang/core/macros/RsMacroExpansionTest.kt
|
||||
|
||||
|
|
Loading…
Reference in a new issue