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

"Unreachable pattern" warning could be an error #47811

Closed
Badel2 opened this issue Jan 27, 2018 · 2 comments
Closed

"Unreachable pattern" warning could be an error #47811

Badel2 opened this issue Jan 27, 2018 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@Badel2
Copy link
Contributor

Badel2 commented Jan 27, 2018

Why is "unreachable pattern" a warning and not an error? I found some discussion in the PR: #19115 but that was in 2014.

I'm specially concerned about the following use case: Playground

pub enum Bit {
    L,
    H,
}

fn from(x: Bit) -> u8 {
    match x {
        L => 0,
        H => 1,
    }
}

That code throws 8 warnings at me, but I would prefer it to not compile. I also found a similar problem in stackoverflow. I think it's important to make this a clear error so beginners don't get confused.

@TimNN TimNN added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints labels Jan 30, 2018
@scottmcm
Copy link
Member

scottmcm commented Jan 31, 2018

Hmm, it looks like warning[E0170]: pattern binding `L` is named the same as one of the variants of the type `Bit` isn't a lint so one can't even choose to deny it?

Generally, as I understand it, Rust doesn't make things like unreachable code an error by default because sometimes they happen intentionally while in the middle of writing something, and the warning is sufficient as a brain nudge. I'd personally be good with making the "binding is the same as a variant" lint deny-by-default, though, since that's almost certainly a brain fart.

@Badel2
Copy link
Contributor Author

Badel2 commented Mar 25, 2018

I'm closing this since you can just #![deny(unreachable_patterns)], however making the "binding is the same as a variant" lint deny-by-default looks like a good idea, maybe we can do it on the next edition?

@Badel2 Badel2 closed this as completed Mar 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

3 participants