Skip to content

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

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

Closed
joshtriplett opened this issue Jul 2, 2022 · 0 comments · Fixed by #9099
Closed

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

joshtriplett opened this issue Jul 2, 2022 · 0 comments · Fixed by #9099
Labels
A-lint Area: New lints

Comments

@joshtriplett
Copy link
Member

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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant