From 98a5e9bf41b8665ac7ba798d480a9ddf76a3ebbe Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 26 Nov 2020 21:52:55 -0800 Subject: [PATCH] Parse const blocks in pattern position --- src/pat.rs | 14 ++++++++++++++ tests/repo/mod.rs | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/pat.rs b/src/pat.rs index 6ae17dd5d8..01a507c010 100644 --- a/src/pat.rs +++ b/src/pat.rs @@ -343,6 +343,8 @@ pub mod parsing { input.call(pat_slice).map(Pat::Slice) } else if lookahead.peek(Token![..]) && !input.peek(Token![...]) { pat_range_half_open(input, begin) + } else if lookahead.peek(Token![const]) { + input.call(pat_const).map(Pat::Verbatim) } else { Err(lookahead.error()) } @@ -690,6 +692,18 @@ pub mod parsing { }) } + fn pat_const(input: ParseStream) -> Result { + let begin = input.fork(); + input.parse::()?; + + let content; + braced!(content in input); + content.call(Attribute::parse_inner)?; + content.call(Block::parse_within)?; + + Ok(verbatim::between(begin, input)) + } + pub fn multi_pat(input: ParseStream) -> Result { multi_pat_impl(input, None) } diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs index 8b4445492f..b656838a72 100644 --- a/tests/repo/mod.rs +++ b/tests/repo/mod.rs @@ -12,9 +12,8 @@ const REVISION: &str = "9d78d1d02761b906038ba4d54c5f3427f920f5fb"; #[rustfmt::skip] static EXCLUDE: &[&str] = &[ - // TODO: const block in pattern position (#921) + // TODO: const block in range patterns (#921) "src/test/ui/inline-const/const-match-pat-range.rs", - "src/test/ui/inline-const/const-match-pat.rs", // Compile-fail expr parameter in const generic position: f::<1 + 2>() "src/test/ui/const-generics/closing-args-token.rs",