Skip to content

Commit 9b9ea77

Browse files
authored
Rollup merge of #117343 - Nadrieril:cleanup_check_match, r=davidtwco
Cleanup `rustc_mir_build/../check_match.rs` The file had become pretty unwieldy, with a fair amount of duplication. As a bonus, I discovered that we weren't running some pattern checks in if-let chains. I recommend looking commit-by-commit. The last commit is a whim, I think it makes more sense that way but I don't hold this opinion strongly.
2 parents f1b104f + 746197c commit 9b9ea77

28 files changed

+749
-627
lines changed

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+400-434
Large diffs are not rendered by default.

tests/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | let _b = || { match l1 { L1::A => () } };
55
| ^^ pattern `L1::B` not covered
66
|
77
note: `L1` defined here
8-
--> $DIR/non-exhaustive-match.rs:12:14
8+
--> $DIR/non-exhaustive-match.rs:12:6
99
|
1010
LL | enum L1 { A, B }
11-
| -- ^ not covered
11+
| ^^ - not covered
1212
= note: the matched value is of type `L1`
1313
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
1414
|

tests/ui/error-codes/E0004.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ LL | match x {
55
| ^ pattern `Terminator::HastaLaVistaBaby` not covered
66
|
77
note: `Terminator` defined here
8-
--> $DIR/E0004.rs:2:5
8+
--> $DIR/E0004.rs:1:6
99
|
1010
LL | enum Terminator {
11-
| ----------
11+
| ^^^^^^^^^^
1212
LL | HastaLaVistaBaby,
13-
| ^^^^^^^^^^^^^^^^ not covered
13+
| ---------------- not covered
1414
= note: the matched value is of type `Terminator`
1515
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
1616
|

tests/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ LL | match Foo::A {
134134
| ^^^^^^ pattern `Foo::C` not covered
135135
|
136136
note: `Foo` defined here
137-
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:16:9
137+
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:13:10
138138
|
139139
LL | enum Foo {
140-
| ---
140+
| ^^^
141141
...
142142
LL | C,
143-
| ^ not covered
143+
| - not covered
144144
= note: the matched value is of type `Foo`
145145
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
146146
|

tests/ui/match/match_non_exhaustive.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | match l { L::A => () };
55
| ^ pattern `L::B` not covered
66
|
77
note: `L` defined here
8-
--> $DIR/match_non_exhaustive.rs:10:13
8+
--> $DIR/match_non_exhaustive.rs:10:6
99
|
1010
LL | enum L { A, B }
11-
| - ^ not covered
11+
| ^ - not covered
1212
= note: the matched value is of type `L`
1313
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
1414
|

tests/ui/pattern/issue-94866.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | match Enum::A {
55
| ^^^^^^^ pattern `Enum::B` not covered
66
|
77
note: `Enum` defined here
8-
--> $DIR/issue-94866.rs:7:16
8+
--> $DIR/issue-94866.rs:7:6
99
|
1010
LL | enum Enum { A, B }
11-
| ---- ^ not covered
11+
| ^^^^ - not covered
1212
= note: the matched value is of type `Enum`
1313
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
1414
|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![feature(if_let_guard, let_chains)]
2+
3+
fn main() {
4+
let mut x = Some(String::new());
5+
let ref mut y @ ref mut z = x;
6+
//~^ ERROR: mutable more than once
7+
let Some(ref mut y @ ref mut z) = x else { return };
8+
//~^ ERROR: mutable more than once
9+
if let Some(ref mut y @ ref mut z) = x {}
10+
//~^ ERROR: mutable more than once
11+
if let Some(ref mut y @ ref mut z) = x && true {}
12+
//~^ ERROR: mutable more than once
13+
while let Some(ref mut y @ ref mut z) = x {}
14+
//~^ ERROR: mutable more than once
15+
while let Some(ref mut y @ ref mut z) = x && true {}
16+
//~^ ERROR: mutable more than once
17+
match x {
18+
ref mut y @ ref mut z => {} //~ ERROR: mutable more than once
19+
}
20+
match () {
21+
() if let Some(ref mut y @ ref mut z) = x => {} //~ ERROR: mutable more than once
22+
_ => {}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
error: cannot borrow value as mutable more than once at a time
2+
--> $DIR/conflicting_bindings.rs:5:9
3+
|
4+
LL | let ref mut y @ ref mut z = x;
5+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
6+
| |
7+
| value is mutably borrowed by `y` here
8+
9+
error: cannot borrow value as mutable more than once at a time
10+
--> $DIR/conflicting_bindings.rs:7:14
11+
|
12+
LL | let Some(ref mut y @ ref mut z) = x else { return };
13+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
14+
| |
15+
| value is mutably borrowed by `y` here
16+
17+
error: cannot borrow value as mutable more than once at a time
18+
--> $DIR/conflicting_bindings.rs:9:17
19+
|
20+
LL | if let Some(ref mut y @ ref mut z) = x {}
21+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
22+
| |
23+
| value is mutably borrowed by `y` here
24+
25+
error: cannot borrow value as mutable more than once at a time
26+
--> $DIR/conflicting_bindings.rs:11:17
27+
|
28+
LL | if let Some(ref mut y @ ref mut z) = x && true {}
29+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
30+
| |
31+
| value is mutably borrowed by `y` here
32+
33+
error: cannot borrow value as mutable more than once at a time
34+
--> $DIR/conflicting_bindings.rs:13:20
35+
|
36+
LL | while let Some(ref mut y @ ref mut z) = x {}
37+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
38+
| |
39+
| value is mutably borrowed by `y` here
40+
41+
error: cannot borrow value as mutable more than once at a time
42+
--> $DIR/conflicting_bindings.rs:15:20
43+
|
44+
LL | while let Some(ref mut y @ ref mut z) = x && true {}
45+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
46+
| |
47+
| value is mutably borrowed by `y` here
48+
49+
error: cannot borrow value as mutable more than once at a time
50+
--> $DIR/conflicting_bindings.rs:18:9
51+
|
52+
LL | ref mut y @ ref mut z => {}
53+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
54+
| |
55+
| value is mutably borrowed by `y` here
56+
57+
error: cannot borrow value as mutable more than once at a time
58+
--> $DIR/conflicting_bindings.rs:21:24
59+
|
60+
LL | () if let Some(ref mut y @ ref mut z) = x => {}
61+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
62+
| |
63+
| value is mutably borrowed by `y` here
64+
65+
error: aborting due to 8 previous errors
66+

tests/ui/pattern/usefulness/doc-hidden-non-exhaustive.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ LL | match HiddenEnum::A {
2323
| ^^^^^^^^^^^^^ pattern `HiddenEnum::B` not covered
2424
|
2525
note: `HiddenEnum` defined here
26-
--> $DIR/auxiliary/hidden.rs:3:5
26+
--> $DIR/auxiliary/hidden.rs:1:1
2727
|
2828
LL | pub enum HiddenEnum {
29-
| -------------------
29+
| ^^^^^^^^^^^^^^^^^^^
3030
LL | A,
3131
LL | B,
32-
| ^ not covered
32+
| - not covered
3333
= note: the matched value is of type `HiddenEnum`
3434
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
3535
|
@@ -44,13 +44,13 @@ LL | match HiddenEnum::A {
4444
| ^^^^^^^^^^^^^ patterns `HiddenEnum::B` and `_` not covered
4545
|
4646
note: `HiddenEnum` defined here
47-
--> $DIR/auxiliary/hidden.rs:3:5
47+
--> $DIR/auxiliary/hidden.rs:1:1
4848
|
4949
LL | pub enum HiddenEnum {
50-
| -------------------
50+
| ^^^^^^^^^^^^^^^^^^^
5151
LL | A,
5252
LL | B,
53-
| ^ not covered
53+
| - not covered
5454
= note: the matched value is of type `HiddenEnum`
5555
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
5656
|
@@ -83,13 +83,13 @@ LL | match InCrate::A {
8383
| ^^^^^^^^^^ pattern `InCrate::C` not covered
8484
|
8585
note: `InCrate` defined here
86-
--> $DIR/doc-hidden-non-exhaustive.rs:11:5
86+
--> $DIR/doc-hidden-non-exhaustive.rs:7:6
8787
|
8888
LL | enum InCrate {
89-
| -------
89+
| ^^^^^^^
9090
...
9191
LL | C,
92-
| ^ not covered
92+
| - not covered
9393
= note: the matched value is of type `InCrate`
9494
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
9595
|

0 commit comments

Comments
 (0)