Skip to content

more descriptive warning for irrefutable while-let pattern #79716

Closed

Description

@ash2x3zb9cy

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

Activity

  1. ehuss commented on Dec 5, 2020

    @ehuss
    Contributor

    @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.

  2. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    on Dec 5, 2020
  3. self-assigned this
    on Dec 5, 2020
  4. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    on Jan 12, 2021
  5. added a commit that references this issue on Feb 19, 2021
    94ab407
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions