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

Create 0000-unreachable-patterns-error.md #2058

Closed
wants to merge 1 commit into from
Closed
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
62 changes: 62 additions & 0 deletions text/0000-unreachable-patterns-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
- Feature Name: Make unreachable patterns error, not warning
- Start Date: 2017-07-06
- RFC PR: (leave this empty)
- Rust Issue: (leave this empty)

# Summary
[summary]: #summary

At now compiler accept such nonsense:

```rust
let x = 1;
match x {
y => {}
z => {}
_ => {}
}
```

`rustc` generate warnings, not errors about the same patterns,
but this is 100% error of developer, so let's show this as error.

# Motivation
[motivation]: #motivation

Novice in `rustc` can try to use `match` with variables,
not literals, like this:

```rust
let x = calculate();
let y = 2;
let z = 3;
match x {
y => {}
z => {}
_ => {}
}
```

this code compiles and run and sometimes warning about unused
variables (`y`, `z`) comes first before warning about unreachable pattern,
what makes unclear what is going on.

So to simplify for novice `match` usage, let's make unreachable pattern is error,
not warning.

Also not novice may made typo, for example miss `z if x == z` in some of "match arms",
so error clear show typo.


# How We Teach This
[how-we-teach-this]: #how-we-teach-this

I suppose that this behaviour expected from `match`.
Compiler/language is strict enough to not allow miss some branch,
so obviously expected that it not allow duplicate branches.

# Drawbacks
[drawbacks]: #drawbacks

Some buggy code will be not accepted by compiler.