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

more descriptive warning for irrefutable while-let pattern #79716

Closed
ash2x3zb9cy opened this issue Dec 5, 2020 · 1 comment · Fixed by #79747
Closed

more descriptive warning for irrefutable while-let pattern #79716

ash2x3zb9cy opened this issue Dec 5, 2020 · 1 comment · Fixed by #79747
Assignees
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@ash2x3zb9cy
Copy link

Writing a while-let loop for e. g. an event loop triggers a compiler warning:

warning: irrefutable while-let pattern
  --> src/main.rs:34:5
   |
34 | /     while let e = crossterm::event::read()? {
35 | |         // code
36 | |     }
   | |_____^
   |
   = note: `#[warn(irrefutable_let_patterns)]` on by default

There's no error code, and no further information, so it isn't the easiest to investigate as a user.

In my case, I believe it's warning about potentially running an unintentionally infinite/indefinite loop, which in my case is intentional. So my guess would be that I am OK to #[allow] it - at a guess.

I would suggest that additional notes be added to this warning detailing why it's a potential problem

@ehuss
Copy link
Contributor

ehuss commented Dec 5, 2020

@ash2x3zb9cy FYI, there is an explanation of the warning at https://doc.rust-lang.org/nightly/rustc/lints/listing/warn-by-default.html#irrefutable-let-patterns. A loop is recommended instead of while let to make it clearer that it is an indefinite loop.

I think it would be nice to link to the lint documentation in the compiler output, but there is some uncertainty of how to best go about that.

@camelid camelid added the A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. label Dec 5, 2020
@camelid camelid self-assigned this Dec 5, 2020
@camelid camelid added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jan 12, 2021
@bors bors closed this as completed in 94ab407 Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants