Skip to content

Commit

Permalink
Parse const blocks in pattern position
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 27, 2020
1 parent 80cbd3f commit 98a5e9b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -690,6 +692,18 @@ pub mod parsing {
})
}

fn pat_const(input: ParseStream) -> Result<TokenStream> {
let begin = input.fork();
input.parse::<Token![const]>()?;

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<Pat> {
multi_pat_impl(input, None)
}
Expand Down
3 changes: 1 addition & 2 deletions tests/repo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 98a5e9b

Please sign in to comment.