mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-03 13:37:37 +00:00
Fix match literal
This commit is contained in:
parent
3894eb77d8
commit
ad9d2012de
@ -281,7 +281,11 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result<Bindings,
|
|||||||
return Err(ExpandError::UnexpectedToken);
|
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 }) => {
|
crate::TokenTree::Repeat(crate::Repeat { subtree, kind, separator }) => {
|
||||||
// Dirty hack to make macro-expansion terminate.
|
// 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
|
// 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
|
// https://github.com/intellij-rust/intellij-rust/blob/c4e9feee4ad46e7953b1948c112533360b6087bb/src/test/kotlin/org/rust/lang/core/macros/RsMacroExpansionTest.kt
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user