-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Improve pattern-checking error message with variable that resembles an enum variant #4612
Comments
The problem here is subtle. BarFoo gets treated as the name for any value, meaning that the subsequent statements actually are unreachable (and they are just treated as names for any value as well). |
This isn't a bug: like @jdm said, because there's no enum variant named There's really no way around this, but I guess we could add some extra logic to the pattern-matching checking that detects this kind of situation and prints out extra diagnostics along with "unreachable pattern" (like, "...because variable pattern |
Oh, you're right this is fully correct behavior. I guess the compiler should then warn, if:
|
I think having #3070 (and making it enabled by default) would effectively solve this problem, and in a much easier way. |
I don't like the idea of just letting lint solve the problem (though I think we should have the lint pass too) since lint happens after match checking. Reading the error messages, it would still be confusing to read the "unreachable pattern" error; you might try to figure out what the error means without continuing to the rest of the errors. I think the error message should be self-contained. |
I agree with your point regarding not having too many error messages. However, there is no reason that lint-style checks have to be done in the lint pass. They could just as easily be done in the exhaustiveness checker. I think we want to do a lint-style check regardless in order to catch things like this:
I was thinking that another useful lint rule would be something like this: if there is ever a variable binding "foo" whose type is an enum E that includes a variant named "foo" (which clearly is not in scope), report a warning. |
Oh, well if it's a lint check that's not actually part of the lint module, then I guess we're basically agreeing :-) |
I think so. All I really mean is that we don't have to complicate the exhaustiveness checker by having it figure out why some branch is dead, it can instead just look at at the capitalized variable names and give a warning about those. |
I think #3070 captures the work that needs to be done here. |
Add --no-deps option to avoid running on path dependencies in workspaces Since rust-lang/cargo#8758 has hit nightly, this allows us to address the second bullet point and [the concern related to `--fix`](rust-lang/cargo#8143 (comment)) in the [RUSTC_WORKSPACE_WRAPPER tracking issue](rust-lang/cargo#8143). As a reminder stabilizing that env var will solve rust-lang#4612 (Clippy not running after `cargo check` in stable) and would allow to stabilize the `--fix` option in Clippy. changelog: Add `--no-deps` option to avoid running on path dependencies in workspaces Fixes rust-lang#3025
Stabilize workspace wrapper. This fixes it so that `cargo clippy` doesn't share the same cache artifacts as `cargo check`. The Cargo side was stabilized a while ago (rust-lang/cargo#8976), so this should be ready to go. I'm not aware of any blockers or concerns. Closes rust-lang#4612 --- changelog: `cargo clippy` no longer shares the same build cache as `cargo check`.
This code:
should fail to compile because it can't resolve the enum variants in the match statement.
But currently it outputs this error message instead:
Which is curious because it doesn't complaint about the first item in the match statement, and because it somehow confuses 'Don't know what it is' with 'Can't reach it'.
The text was updated successfully, but these errors were encountered: