Skip to content

bool::then with trivial body should use bool::then_some #9097

Closed
@joshtriplett

Description

@joshtriplett

What it does

With bool::then_some stabilized in Rust 1.62, uses of bool::then with a closure consisting of a simple body without side effects should become bool::then_some.

This should be part of the existing unnecessary_lazy_evaluations.

Lint Name

unnecessary_lazy_evaluations

Category

style

Advantage

No response

Drawbacks

No response

Example

fn f(cond: bool) -> Option<u64> {
    cond.then(|| 42)
}

Could be written as:

fn f(cond: bool) -> Option<u64> {
    cond.then_some(42)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions