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

Don't warn empty branches unreachable for now #129103

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/rustc_pattern_analysis/src/usefulness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,11 @@ impl<Cx: PatCx> PlaceInfo<Cx> {
self.is_scrutinee && matches!(ctors_for_ty, ConstructorSet::NoConstructors);
// Whether empty patterns are counted as useful or not. We only warn an empty arm unreachable if
// it is guaranteed unreachable by the opsem (i.e. if the place is `known_valid`).
let empty_arms_are_unreachable = self.validity.is_known_valid();
// We don't want to warn empty patterns as unreachable by default just yet. We will in a
// later version of rust or under a different lint name, see
// https://github.com/rust-lang/rust/pull/129103.
let empty_arms_are_unreachable = self.validity.is_known_valid()
&& (is_toplevel_exception || cx.is_exhaustive_patterns_feature_on());
// Whether empty patterns can be omitted for exhaustiveness. We ignore place validity in the
// toplevel exception and `exhaustive_patterns` cases for backwards compatibility.
let can_omit_empty_arms = self.validity.is_known_valid()
Expand Down
188 changes: 1 addition & 187 deletions tests/ui/pattern/usefulness/empty-types.never_pats.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,6 @@ LL + _ => todo!(),
LL + }
|

error: unreachable pattern
--> $DIR/empty-types.rs:70:9
|
LL | (_, _) => {}
| ^^^^^^ matches no values because `(u32, !)` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:76:9
|
LL | _ => {}
| ^ matches no values because `(!, !)` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:79:9
|
LL | (_, _) => {}
| ^^^^^^ matches no values because `(!, !)` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:83:9
|
Expand Down Expand Up @@ -94,22 +70,6 @@ LL + Ok(_) => todo!(),
LL + }
|

error: unreachable pattern
--> $DIR/empty-types.rs:94:9
|
LL | Err(_) => {}
| ^^^^^^ matches no values because `!` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:99:9
|
LL | Err(_) => {}
| ^^^^^^ matches no values because `!` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error[E0004]: non-exhaustive patterns: `Ok(1_u32..=u32::MAX)` not covered
--> $DIR/empty-types.rs:96:11
|
Expand Down Expand Up @@ -156,54 +116,6 @@ help: you might want to use `let else` to handle the variant that isn't matched
LL | let Ok(_x) = &res_u32_never else { todo!() };
| ++++++++++++++++

error: unreachable pattern
--> $DIR/empty-types.rs:112:9
|
LL | _ => {}
| ^ matches no values because `Result<!, !>` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:115:9
|
LL | Ok(_) => {}
| ^^^^^ matches no values because `Result<!, !>` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:118:9
|
LL | Ok(_) => {}
| ^^^^^ matches no values because `Result<!, !>` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:119:9
|
LL | _ => {}
| ^ matches no values because `Result<!, !>` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:122:9
|
LL | Ok(_) => {}
| ^^^^^ matches no values because `Result<!, !>` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:123:9
|
LL | Err(_) => {}
| ^^^^^^ matches no values because `Result<!, !>` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:132:13
|
Expand All @@ -220,22 +132,6 @@ LL | _ if false => {}
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:143:13
|
LL | Some(_) => {}
| ^^^^^^^ matches no values because `Void` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:147:13
|
LL | None => {}
| ---- matches all the relevant values
LL | _ => {}
| ^ no value can reach this

error[E0004]: non-exhaustive patterns: `Some(!)` not covered
--> $DIR/empty-types.rs:156:15
|
Expand Down Expand Up @@ -303,30 +199,6 @@ LL | _ => {}
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:284:9
|
LL | (_, _) => {}
| ^^^^^^ matches no values because `(!, !)` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:287:9
|
LL | Ok(_) => {}
| ^^^^^ matches no values because `Result<!, !>` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:288:9
|
LL | Err(_) => {}
| ^^^^^^ matches no values because `Result<!, !>` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error[E0005]: refutable pattern in local binding
--> $DIR/empty-types.rs:297:13
|
Expand Down Expand Up @@ -474,30 +346,6 @@ LL + _ => todo!(),
LL + }
|

error: unreachable pattern
--> $DIR/empty-types.rs:368:9
|
LL | _ => {}
| ^ matches no values because `[!; 3]` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:371:9
|
LL | [_, _, _] => {}
| ^^^^^^^^^ matches no values because `[!; 3]` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:374:9
|
LL | [_, ..] => {}
| ^^^^^^^ matches no values because `[!; 3]` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error[E0004]: non-exhaustive patterns: type `[!; 0]` is non-empty
--> $DIR/empty-types.rs:388:11
|
Expand Down Expand Up @@ -534,40 +382,6 @@ LL ~ [..] if false => {},
LL + [] => todo!()
|

error: unreachable pattern
--> $DIR/empty-types.rs:416:9
|
LL | Some(_) => {}
| ^^^^^^^ matches no values because `!` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:421:9
|
LL | Some(_a) => {}
| ^^^^^^^^ matches no values because `!` is uninhabited
|
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types

error: unreachable pattern
--> $DIR/empty-types.rs:426:9
|
LL | None => {}
| ---- matches all the relevant values
LL | // !useful, !reachable
LL | _ => {}
| ^ no value can reach this

error: unreachable pattern
--> $DIR/empty-types.rs:431:9
|
LL | None => {}
| ---- matches all the relevant values
LL | // !useful, !reachable
LL | _a => {}
| ^^ no value can reach this

error[E0004]: non-exhaustive patterns: `&Some(!)` not covered
--> $DIR/empty-types.rs:451:11
|
Expand Down Expand Up @@ -744,7 +558,7 @@ LL ~ None => {},
LL + Some(!)
|

error: aborting due to 65 previous errors; 1 warning emitted
error: aborting due to 42 previous errors; 1 warning emitted

Some errors have detailed explanations: E0004, E0005.
For more information about an error, try `rustc --explain E0004`.
Loading
Loading