Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup rustc_mir_build/../check_match.rs #117343

Merged
merged 10 commits into from
Nov 4, 2023
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
Loading