diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-12-12 17:40:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-12 17:40:56 +0100 |
| commit | d661974017d2099efd128127843c27db3601fbaf (patch) | |
| tree | 4a794d4dd131e09f856bbfd840eec000463ad764 /compiler/rustc_parse | |
| parent | 9ed12f8d7ad67de8597e7ae758375bc281fa5356 (diff) | |
| parent | 19e0c984d3ff44c6e273ddae2f327e8ad8726fae (diff) | |
| download | rust-d661974017d2099efd128127843c27db3601fbaf.tar.gz rust-d661974017d2099efd128127843c27db3601fbaf.zip | |
Rollup merge of #118868 - Nadrieril:correctly-gate-never_patterns-parsing, r=petrochenkov
Correctly gate the parsing of match arms without body
https://github.com/rust-lang/rust/pull/118527 accidentally allowed the following to parse on stable:
```rust
match Some(0) {
None => { foo(); }
#[cfg(FALSE)]
Some(_)
}
```
This fixes that oversight. The way I choose which error to emit is the best I could think of, I'm open if you know a better way.
r? `@petrochenkov` since you're the one who noticed
Diffstat (limited to 'compiler/rustc_parse')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 3c0627526be..5b0011e9f70 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -2918,7 +2918,15 @@ impl<'a> Parser<'a> { let mut result = if !is_fat_arrow && !is_almost_fat_arrow { // A pattern without a body, allowed for never patterns. arm_body = None; - this.expect_one_of(&[token::Comma], &[token::CloseDelim(Delimiter::Brace)]) + this.expect_one_of(&[token::Comma], &[token::CloseDelim(Delimiter::Brace)]).map( + |x| { + // Don't gate twice + if !pat.contains_never_pattern() { + this.sess.gated_spans.gate(sym::never_patterns, pat.span); + } + x + }, + ) } else { if let Err(mut err) = this.expect(&token::FatArrow) { // We might have a `=>` -> `=` or `->` typo (issue #89396). |
