aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_mbe/src/mbe_expander.rs6
-rw-r--r--crates/ra_mbe/src/tests.rs14
2 files changed, 19 insertions, 1 deletions
diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs
index 3a4dbb5f5..7fff8deff 100644
--- a/crates/ra_mbe/src/mbe_expander.rs
+++ b/crates/ra_mbe/src/mbe_expander.rs
@@ -281,7 +281,11 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result<Bindings,
281 return Err(ExpandError::UnexpectedToken); 281 return Err(ExpandError::UnexpectedToken);
282 } 282 }
283 } 283 }
284 _ => return Err(ExpandError::UnexpectedToken), 284 crate::Leaf::Literal(literal) => {
285 if input.eat_literal().map(|i| &i.text) != Some(&literal.text) {
286 return Err(ExpandError::UnexpectedToken);
287 }
288 }
285 }, 289 },
286 crate::TokenTree::Repeat(crate::Repeat { subtree, kind, separator }) => { 290 crate::TokenTree::Repeat(crate::Repeat { subtree, kind, separator }) => {
287 // Dirty hack to make macro-expansion terminate. 291 // Dirty hack to make macro-expansion terminate.
diff --git a/crates/ra_mbe/src/tests.rs b/crates/ra_mbe/src/tests.rs
index 004faf77e..e3a5ceecf 100644
--- a/crates/ra_mbe/src/tests.rs
+++ b/crates/ra_mbe/src/tests.rs
@@ -575,6 +575,20 @@ fn test_tt_to_stmts() {
575 ); 575 );
576} 576}
577 577
578#[test]
579fn test_match_literal() {
580 let rules = create_rules(
581 r#"
582 macro_rules! foo {
583 ('(') => {
584 fn foo() {}
585 }
586 }
587"#,
588 );
589 assert_expansion(MacroKind::Items, &rules, "foo! ['(']", "fn foo () {}");
590}
591
578// The following tests are port from intellij-rust directly 592// The following tests are port from intellij-rust directly
579// https://github.com/intellij-rust/intellij-rust/blob/c4e9feee4ad46e7953b1948c112533360b6087bb/src/test/kotlin/org/rust/lang/core/macros/RsMacroExpansionTest.kt 593// https://github.com/intellij-rust/intellij-rust/blob/c4e9feee4ad46e7953b1948c112533360b6087bb/src/test/kotlin/org/rust/lang/core/macros/RsMacroExpansionTest.kt
580 594