From f942d10e8010918c677b40f821e504d87f057ead Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 20 Dec 2020 17:13:40 +0800 Subject: [PATCH] Use pattern_single instead of pattern in mbe pat --- crates/mbe/src/tests.rs | 12 ++++++++++++ crates/parser/src/grammar.rs | 2 +- crates/parser/src/lib.rs | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/mbe/src/tests.rs b/crates/mbe/src/tests.rs index f10e7a9b69..451fa1456a 100644 --- a/crates/mbe/src/tests.rs +++ b/crates/mbe/src/tests.rs @@ -1003,6 +1003,18 @@ fn test_underscore() { .assert_expand_items(r#"foo! { => }"#, r#"0"#); } +#[test] +fn test_vertical_bar_with_pat() { + parse_macro( + r#" + macro_rules! foo { + (| $pat:pat | ) => { 0 } + } + "#, + ) + .assert_expand_items(r#"foo! { | x | }"#, r#"0"#); +} + #[test] fn test_lifetime() { parse_macro( diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs index 1a078f6b4c..f08c8bab74 100644 --- a/crates/parser/src/grammar.rs +++ b/crates/parser/src/grammar.rs @@ -55,7 +55,7 @@ pub(crate) mod fragments { use super::*; pub(crate) use super::{ - expressions::block_expr, paths::type_path as path, patterns::pattern, types::type_, + expressions::block_expr, paths::type_path as path, patterns::pattern_single, types::type_, }; pub(crate) fn expr(p: &mut Parser) { diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index ab8e4c70e8..811e740f98 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -112,7 +112,7 @@ pub fn parse_fragment( FragmentKind::Path => grammar::fragments::path, FragmentKind::Expr => grammar::fragments::expr, FragmentKind::Type => grammar::fragments::type_, - FragmentKind::Pattern => grammar::fragments::pattern, + FragmentKind::Pattern => grammar::fragments::pattern_single, FragmentKind::Item => grammar::fragments::item, FragmentKind::Block => grammar::fragments::block_expr, FragmentKind::Visibility => grammar::fragments::opt_visibility,