-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Warn when match variables start with an uppercase letter #10304
Comments
This has been proposed numerous times. I think it's a great idea. I couldn't find another issue though I'm sure one or two exists -- or maybe not. Here is a generalization: generate a warning if you create a variable that has the same name as a variant of the enum being matched (note that this variant name may be lower case). I actually think it'd possibly make sense to have both warnings, but checking for variables with the same name as an (unimported) variant seems more targeted. |
I like this suggestion (I've got similar problem several times), but I feel uppercase check is lint job. We already have unused variable lint so it should emit an warning for |
Couldn't we just go full-haskell and enforce* locals are This would solve #7526 too. (* Possibly as lints on |
cc @chris-morgan who was discussing related issues in the chat room yesterday. (I.e. the problem where users get surprised that a catch-all |
Triage: still no lint, still same error message. |
Is this still an issue? I tried the repro from #13995 and I got this
|
I also believe this is fixed, thanks @wesleywiser! |
[never_loop] Fix rust-lang#10304 It is not sufficient to ignore break from a block inside the loop. Instructions after the break must be ignored, as they are unreachable. This is also true for all instructions in outer blocks and loops until the right block is reached. Fixes rust-lang#10304 --- changelog: FP: [`never_loop`]: No longer lints, for statements following break statements for outer blocks. [rust-lang#10311](rust-lang/rust-clippy#10311) <!-- changelog_checked-->
I had code like
and got
error: unreachable pattern
on the second pattern. I hadn't importedstd::rt::io::EndOfFile
sorustc
interpretedEndOfFile
as a variable rather than an enum constructor.Most Rust code follows the stylistic rule of capitalizing enum constructors and not capitalizing variables. So I think
rustc
should warn when binding a capitalized variable in amatch
— at least when it makes another pattern unreachable, but probably always.The text was updated successfully, but these errors were encountered: