Closed
Description
match
ing a value of an empty enum is valid, however match
ing a reference to a value of an empty enum produces E0004: non-exhaustive patterns
.
I tried this code (playground link):
enum A {}
fn f(a: &A) -> usize {
match a {}
}
I expected to see this happen: The code should compile with no issue, and the function should never actually execute because A
has no variants and thus cannot be instantiated.
Instead, this happened:
error[E0004]: non-exhaustive patterns: type `&A` is non-empty
--> src/lib.rs:4:11
|
1 | enum A {}
| --------- `A` defined here
...
4 | match a {}
| ^
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `&A`
Meta
The bug exists on 1.47.0 and 1.49.0-nightly (2020-10-18 b1496c6) running on the playground. I first found this bug on 1.46.0.
rustc --version --verbose
:
rustc 1.46.0 (04488afe3 2020-08-24)
binary: rustc
commit-hash: 04488afe34512aa4c33566eb16d8c912a3ae04f9
commit-date: 2020-08-24
host: x86_64-pc-windows-msvc
release: 1.46.0
LLVM version: 10.0
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsRelating to exhaustiveness / usefulness checking of patternsCategory: An issue proposing an enhancement or a PR with one.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Relevant to the compiler team, which will review and decide on the PR/issue.