Skip to content

Commit f34c020

Browse files
authored
Unrolled build for rust-lang#119380
Rollup merge of rust-lang#119380 - ShE3py:match-never-pat, r=petrochenkov Don't suggest writing a bodyless arm if the pattern can never be a never pattern rust-lang#118527 enabled arms to be bodyless for never patterns ; this PR removes the `,` and `}` suggestions for patterns that could never be never patterns.
2 parents f4d794e + 7d6cd6b commit f34c020

12 files changed

+32
-26
lines changed

compiler/rustc_parse/src/parser/expr.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2937,7 +2937,13 @@ impl<'a> Parser<'a> {
29372937
let is_almost_fat_arrow = TokenKind::FatArrow
29382938
.similar_tokens()
29392939
.is_some_and(|similar_tokens| similar_tokens.contains(&this.token.kind));
2940-
let mut result = if !is_fat_arrow && !is_almost_fat_arrow {
2940+
2941+
// this avoids the compiler saying that a `,` or `}` was expected even though
2942+
// the pattern isn't a never pattern (and thus an arm body is required)
2943+
let armless = (!is_fat_arrow && !is_almost_fat_arrow && pat.could_be_never_pattern())
2944+
|| matches!(this.token.kind, token::Comma | token::CloseDelim(Delimiter::Brace));
2945+
2946+
let mut result = if armless {
29412947
// A pattern without a body, allowed for never patterns.
29422948
arm_body = None;
29432949
this.expect_one_of(&[token::Comma], &[token::CloseDelim(Delimiter::Brace)]).map(

tests/ui/half-open-range-patterns/range_pat_interactions1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717
}
1818
match x as i32 {
1919
0..5+1 => errors_only.push(x),
20-
//~^ error: expected one of `,`, `=>`, `if`, `|`, or `}`, found `+`
20+
//~^ error: expected one of `=>`, `if`, or `|`, found `+`
2121
1 | -3..0 => first_or.push(x),
2222
y @ (0..5 | 6) => or_two.push(y),
2323
y @ 0..const { 5 + 1 } => assert_eq!(y, 5),

tests/ui/half-open-range-patterns/range_pat_interactions1.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: expected one of `,`, `=>`, `if`, `|`, or `}`, found `+`
1+
error: expected one of `=>`, `if`, or `|`, found `+`
22
--> $DIR/range_pat_interactions1.rs:19:17
33
|
44
LL | 0..5+1 => errors_only.push(x),
5-
| ^ expected one of `,`, `=>`, `if`, `|`, or `}`
5+
| ^ expected one of `=>`, `if`, or `|`
66

77
error[E0408]: variable `n` is not bound in all patterns
88
--> $DIR/range_pat_interactions1.rs:10:25

tests/ui/half-open-range-patterns/range_pat_interactions2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() {
99
match x as i32 {
1010
0..=(5+1) => errors_only.push(x),
1111
//~^ error: inclusive range with no end
12-
//~| error: expected one of `,`, `=>`, `if`, `|`, or `}`, found `(`
12+
//~| error: expected one of `=>`, `if`, or `|`, found `(`
1313
1 | -3..0 => first_or.push(x),
1414
y @ (0..5 | 6) => or_two.push(y),
1515
y @ 0..const { 5 + 1 } => assert_eq!(y, 5),

tests/ui/half-open-range-patterns/range_pat_interactions2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ LL | 0..=(5+1) => errors_only.push(x),
66
|
77
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
88

9-
error: expected one of `,`, `=>`, `if`, `|`, or `}`, found `(`
9+
error: expected one of `=>`, `if`, or `|`, found `(`
1010
--> $DIR/range_pat_interactions2.rs:10:17
1111
|
1212
LL | 0..=(5+1) => errors_only.push(x),
13-
| ^ expected one of `,`, `=>`, `if`, `|`, or `}`
13+
| ^ expected one of `=>`, `if`, or `|`
1414

1515
error: aborting due to 2 previous errors
1616

tests/ui/parser/attribute/attr-stmt-expr-attr-bad.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ fn main() {}
8484

8585
#[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] 10 => () } }
8686
//~^ ERROR inclusive range with no end
87-
//~| ERROR expected one of `,`, `=>`, `if`, `|`, or `}`, found `#`
87+
//~| ERROR expected one of `=>`, `if`, or `|`, found `#`
8888
#[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] -10 => () } }
8989
//~^ ERROR inclusive range with no end
90-
//~| ERROR expected one of `,`, `=>`, `if`, `|`, or `}`, found `#`
90+
//~| ERROR expected one of `=>`, `if`, or `|`, found `#`
9191
#[cfg(FALSE)] fn e() { match 0 { 0..=-#[attr] 10 => () } }
9292
//~^ ERROR unexpected token: `#`
9393
#[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] FOO => () } }
9494
//~^ ERROR inclusive range with no end
95-
//~| ERROR expected one of `,`, `=>`, `if`, `|`, or `}`, found `#`
95+
//~| ERROR expected one of `=>`, `if`, or `|`, found `#`
9696

9797
#[cfg(FALSE)] fn e() { let _ = x.#![attr]foo(); }
9898
//~^ ERROR unexpected token: `#`

tests/ui/parser/attribute/attr-stmt-expr-attr-bad.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,11 @@ LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] 10 => () } }
365365
|
366366
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
367367

368-
error: expected one of `,`, `=>`, `if`, `|`, or `}`, found `#`
368+
error: expected one of `=>`, `if`, or `|`, found `#`
369369
--> $DIR/attr-stmt-expr-attr-bad.rs:85:38
370370
|
371371
LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] 10 => () } }
372-
| ^ expected one of `,`, `=>`, `if`, `|`, or `}`
372+
| ^ expected one of `=>`, `if`, or `|`
373373

374374
error[E0586]: inclusive range with no end
375375
--> $DIR/attr-stmt-expr-attr-bad.rs:88:35
@@ -379,11 +379,11 @@ LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] -10 => () } }
379379
|
380380
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
381381

382-
error: expected one of `,`, `=>`, `if`, `|`, or `}`, found `#`
382+
error: expected one of `=>`, `if`, or `|`, found `#`
383383
--> $DIR/attr-stmt-expr-attr-bad.rs:88:38
384384
|
385385
LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] -10 => () } }
386-
| ^ expected one of `,`, `=>`, `if`, `|`, or `}`
386+
| ^ expected one of `=>`, `if`, or `|`
387387

388388
error: unexpected token: `#`
389389
--> $DIR/attr-stmt-expr-attr-bad.rs:91:39
@@ -399,11 +399,11 @@ LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] FOO => () } }
399399
|
400400
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
401401

402-
error: expected one of `,`, `=>`, `if`, `|`, or `}`, found `#`
402+
error: expected one of `=>`, `if`, or `|`, found `#`
403403
--> $DIR/attr-stmt-expr-attr-bad.rs:93:38
404404
|
405405
LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] FOO => () } }
406-
| ^ expected one of `,`, `=>`, `if`, `|`, or `}`
406+
| ^ expected one of `=>`, `if`, or `|`
407407

408408
error: unexpected token: `#`
409409
--> $DIR/attr-stmt-expr-attr-bad.rs:97:34

tests/ui/parser/issues/issue-24375.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ static tmp : [&'static str; 2] = ["hello", "he"];
33
fn main() {
44
let z = "hello";
55
match z {
6-
tmp[0] => {} //~ ERROR expected one of `,`, `=>`, `@`, `if`, `|`, or `}`, found `[`
6+
tmp[0] => {} //~ ERROR expected one of `=>`, `@`, `if`, or `|`, found `[`
77
_ => {}
88
}
99
}
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: expected one of `,`, `=>`, `@`, `if`, `|`, or `}`, found `[`
1+
error: expected one of `=>`, `@`, `if`, or `|`, found `[`
22
--> $DIR/issue-24375.rs:6:12
33
|
44
LL | tmp[0] => {}
5-
| ^ expected one of `,`, `=>`, `@`, `if`, `|`, or `}`
5+
| ^ expected one of `=>`, `@`, `if`, or `|`
66

77
error: aborting due to 1 previous error
88

tests/ui/parser/match-arm-without-body.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: expected one of `,`, `=>`, `if`, `|`, or `}`, found reserved identifier `_`
1+
error: expected one of `=>`, `if`, or `|`, found reserved identifier `_`
22
--> $DIR/match-arm-without-body.rs:13:9
33
|
44
LL | Some(_)
5-
| - expected one of `,`, `=>`, `if`, `|`, or `}`
5+
| - expected one of `=>`, `if`, or `|`
66
LL | _ => {}
77
| ^ unexpected token
88

@@ -44,11 +44,11 @@ LL +
4444
LL ~ _ => {}
4545
|
4646

47-
error: expected one of `,`, `.`, `=>`, `?`, `}`, or an operator, found reserved identifier `_`
47+
error: expected one of `.`, `=>`, `?`, or an operator, found reserved identifier `_`
4848
--> $DIR/match-arm-without-body.rs:36:9
4949
|
5050
LL | Some(_) if true
51-
| - expected one of `,`, `.`, `=>`, `?`, `}`, or an operator
51+
| - expected one of `.`, `=>`, `?`, or an operator
5252
LL | _ => {}
5353
| ^ unexpected token
5454

tests/ui/parser/pat-lt-bracket-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fn main() {
22
match 42 {
33
x < 7 => (),
4-
//~^ error: expected one of `,`, `=>`, `@`, `if`, `|`, or `}`, found `<`
4+
//~^ error: expected one of `=>`, `@`, `if`, or `|`, found `<`
55
_ => ()
66
}
77
}
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: expected one of `,`, `=>`, `@`, `if`, `|`, or `}`, found `<`
1+
error: expected one of `=>`, `@`, `if`, or `|`, found `<`
22
--> $DIR/pat-lt-bracket-1.rs:3:7
33
|
44
LL | x < 7 => (),
5-
| ^ expected one of `,`, `=>`, `@`, `if`, `|`, or `}`
5+
| ^ expected one of `=>`, `@`, `if`, or `|`
66

77
error: aborting due to 1 previous error
88

0 commit comments

Comments
 (0)