Skip to content

Commit

Permalink
Unrolled build for rust-lang#117343
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#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.
  • Loading branch information
rust-timer committed Nov 4, 2023
2 parents 3aaa0f5 + 746197c commit 0da9b32
Show file tree
Hide file tree
Showing 28 changed files with 749 additions and 627 deletions.
834 changes: 400 additions & 434 deletions compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ LL | let _b = || { match l1 { L1::A => () } };
| ^^ pattern `L1::B` not covered
|
note: `L1` defined here
--> $DIR/non-exhaustive-match.rs:12:14
--> $DIR/non-exhaustive-match.rs:12:6
|
LL | enum L1 { A, B }
| -- ^ not covered
| ^^ - not covered
= note: the matched value is of type `L1`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/error-codes/E0004.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ LL | match x {
| ^ pattern `Terminator::HastaLaVistaBaby` not covered
|
note: `Terminator` defined here
--> $DIR/E0004.rs:2:5
--> $DIR/E0004.rs:1:6
|
LL | enum Terminator {
| ----------
| ^^^^^^^^^^
LL | HastaLaVistaBaby,
| ^^^^^^^^^^^^^^^^ not covered
| ---------------- not covered
= note: the matched value is of type `Terminator`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ LL | match Foo::A {
| ^^^^^^ pattern `Foo::C` not covered
|
note: `Foo` defined here
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:16:9
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:13:10
|
LL | enum Foo {
| ---
| ^^^
...
LL | C,
| ^ not covered
| - not covered
= note: the matched value is of type `Foo`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/match/match_non_exhaustive.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ LL | match l { L::A => () };
| ^ pattern `L::B` not covered
|
note: `L` defined here
--> $DIR/match_non_exhaustive.rs:10:13
--> $DIR/match_non_exhaustive.rs:10:6
|
LL | enum L { A, B }
| - ^ not covered
| ^ - not covered
= note: the matched value is of type `L`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/pattern/issue-94866.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ LL | match Enum::A {
| ^^^^^^^ pattern `Enum::B` not covered
|
note: `Enum` defined here
--> $DIR/issue-94866.rs:7:16
--> $DIR/issue-94866.rs:7:6
|
LL | enum Enum { A, B }
| ---- ^ not covered
| ^^^^ - not covered
= note: the matched value is of type `Enum`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
Expand Down
24 changes: 24 additions & 0 deletions tests/ui/pattern/usefulness/conflicting_bindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#![feature(if_let_guard, let_chains)]

fn main() {
let mut x = Some(String::new());
let ref mut y @ ref mut z = x;
//~^ ERROR: mutable more than once
let Some(ref mut y @ ref mut z) = x else { return };
//~^ ERROR: mutable more than once
if let Some(ref mut y @ ref mut z) = x {}
//~^ ERROR: mutable more than once
if let Some(ref mut y @ ref mut z) = x && true {}
//~^ ERROR: mutable more than once
while let Some(ref mut y @ ref mut z) = x {}
//~^ ERROR: mutable more than once
while let Some(ref mut y @ ref mut z) = x && true {}
//~^ ERROR: mutable more than once
match x {
ref mut y @ ref mut z => {} //~ ERROR: mutable more than once
}
match () {
() if let Some(ref mut y @ ref mut z) = x => {} //~ ERROR: mutable more than once
_ => {}
}
}
66 changes: 66 additions & 0 deletions tests/ui/pattern/usefulness/conflicting_bindings.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
error: cannot borrow value as mutable more than once at a time
--> $DIR/conflicting_bindings.rs:5:9
|
LL | let ref mut y @ ref mut z = x;
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
| |
| value is mutably borrowed by `y` here

error: cannot borrow value as mutable more than once at a time
--> $DIR/conflicting_bindings.rs:7:14
|
LL | let Some(ref mut y @ ref mut z) = x else { return };
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
| |
| value is mutably borrowed by `y` here

error: cannot borrow value as mutable more than once at a time
--> $DIR/conflicting_bindings.rs:9:17
|
LL | if let Some(ref mut y @ ref mut z) = x {}
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
| |
| value is mutably borrowed by `y` here

error: cannot borrow value as mutable more than once at a time
--> $DIR/conflicting_bindings.rs:11:17
|
LL | if let Some(ref mut y @ ref mut z) = x && true {}
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
| |
| value is mutably borrowed by `y` here

error: cannot borrow value as mutable more than once at a time
--> $DIR/conflicting_bindings.rs:13:20
|
LL | while let Some(ref mut y @ ref mut z) = x {}
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
| |
| value is mutably borrowed by `y` here

error: cannot borrow value as mutable more than once at a time
--> $DIR/conflicting_bindings.rs:15:20
|
LL | while let Some(ref mut y @ ref mut z) = x && true {}
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
| |
| value is mutably borrowed by `y` here

error: cannot borrow value as mutable more than once at a time
--> $DIR/conflicting_bindings.rs:18:9
|
LL | ref mut y @ ref mut z => {}
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
| |
| value is mutably borrowed by `y` here

error: cannot borrow value as mutable more than once at a time
--> $DIR/conflicting_bindings.rs:21:24
|
LL | () if let Some(ref mut y @ ref mut z) = x => {}
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
| |
| value is mutably borrowed by `y` here

error: aborting due to 8 previous errors

18 changes: 9 additions & 9 deletions tests/ui/pattern/usefulness/doc-hidden-non-exhaustive.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ LL | match HiddenEnum::A {
| ^^^^^^^^^^^^^ pattern `HiddenEnum::B` not covered
|
note: `HiddenEnum` defined here
--> $DIR/auxiliary/hidden.rs:3:5
--> $DIR/auxiliary/hidden.rs:1:1
|
LL | pub enum HiddenEnum {
| -------------------
| ^^^^^^^^^^^^^^^^^^^
LL | A,
LL | B,
| ^ not covered
| - not covered
= note: the matched value is of type `HiddenEnum`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
Expand All @@ -44,13 +44,13 @@ LL | match HiddenEnum::A {
| ^^^^^^^^^^^^^ patterns `HiddenEnum::B` and `_` not covered
|
note: `HiddenEnum` defined here
--> $DIR/auxiliary/hidden.rs:3:5
--> $DIR/auxiliary/hidden.rs:1:1
|
LL | pub enum HiddenEnum {
| -------------------
| ^^^^^^^^^^^^^^^^^^^
LL | A,
LL | B,
| ^ not covered
| - not covered
= note: the matched value is of type `HiddenEnum`
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
|
Expand Down Expand Up @@ -83,13 +83,13 @@ LL | match InCrate::A {
| ^^^^^^^^^^ pattern `InCrate::C` not covered
|
note: `InCrate` defined here
--> $DIR/doc-hidden-non-exhaustive.rs:11:5
--> $DIR/doc-hidden-non-exhaustive.rs:7:6
|
LL | enum InCrate {
| -------
| ^^^^^^^
...
LL | C,
| ^ not covered
| - not covered
= note: the matched value is of type `InCrate`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
Expand Down
Loading

0 comments on commit 0da9b32

Please sign in to comment.