match: an enum with no variants has no values, so a match needs no arm for it
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 22/100
Research direction
Reproduce the Never example from the issue and find where the E3020 "does not cover" error is emitted in the exhaustiveness check for match. Read how a variant's payload type is examined, then add an "uninhabited type" test covering an empty enum, a struct or tuple with such a field, and an enum whose variants all hold such types. Done when the example compiles and references to empty types still require an arm, as the issue specifies. The layout question tied to #2327 should be checked separately.
Written by the indexing model from the issue text.
Description
An enum with no variants has no values. Vx accepts the declaration, but match does not use the fact:
import core::result;
enum Never {}
fn parse() -> Result<i32, Never> {
return Result<i32, Never>::Ok(3);
}
fn main() -> i32 {
return match parse() { Result<i32, Never>::Ok(v) => { v - 3 } };
}
Error[E3020] at never.vx:10:12: this `match` does not cover Err; add an arm for each, or a `_` arm
No program can make the Err value, so the arm is code that cannot run.
The change
In the exhaustiveness check of match, a variant is covered when its payload has a type with no values. A type has no values when it is:
- an enum with no variants, or
- a struct or tuple with a field of such a type, or
- an enum whose variants each hold such a type.
Rust made the same change in 1.82 (min_exhaustive_patterns). Stable Rust writes Result<T, Infallible>, and Infallible is an empty enum.
Leave out for now:
- A
coretype such asInfallible. Add it when a library API needs an error type that cannot occur. - A value of such a type behind a reference or a pointer. Rust still asks for the arm there, because unsafe code can make such a reference.
Questions
- Whether a function may take a parameter of such a type, and whether the call can then be removed. Rust allows the parameter.
- The layout: #2327 gives a zero-size type its rules. An enum with no variants is zero-size too, but no value of it exists. Check that #2327's rules (Z6: never by value across an ABI) do not need a special case.
Part of #3391.
- Dominant language
- Rust
- Stars
- 35
- Forks
- 5
- Avg merge
- 12h 26m
- Merged PRs (30d)
- 799
Getting set up
We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vx-lang/Vx
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
bug testing
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
`pub struct` gives "Expected 'fn' after 'pub'": the error should say that a struct needs no `pub`Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
bug devex
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
longbridge/gpui-kit#4031 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
neuralmagic/crucible#465 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
compiler P3
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
HerringtonDarkholme/hd-lang#2162 ·
Maintainers usually reply within 1 day
-
embedded SQL: pin correlated-guard behaviour when a closed variable is reassigned inside a branchOpenpriority: low
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
jonathanong/no-mistakes#3627 ·
Maintainers usually reply within 1 day