Skip to content

unnecessary closure used with bool::then in field definition #9485

Closed
@xerenahmed

Description

@xerenahmed

Summary

....

Lint Name

unnecessary_lazy_evaluations

Reproducer

I tried this code:

// FromForm is from rocket (HTTP library)
#[derive(FromForm, Debug)]
pub struct CreateAlarm {
    pub label: String,
}

I saw this happen:

warning: unnecessary closure used with `bool::then`
  --> src/routes/alarm/create.rs:10:16
   |
10 |     pub label: String,
   |                ^^^^^^ help: use `then_some(..)` instead: `then_some(label)`
   |
   = note: `#[warn(clippy::unnecessary_lazy_evaluations)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations

I expected to see this happen: nothing

Version

rustc 1.65.0-nightly (29e4a9ee0 2022-08-10)
binary: rustc
commit-hash: 29e4a9ee0253cd39e552a77f51f11f9a5f1c41e6
commit-date: 2022-08-10
host: aarch64-apple-darwin
release: 1.65.0-nightly
LLVM version: 14.0.6

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions