Closed
Description
Summary
I've encountered a small issue when clippy generates a help message.
I'm using unwrap_or_else
and it hint's me to use unwrap_or
providing again unwrap_or
as instead example ( instead of my unwrap_or_else
).
I'm happy to work on fixing this if it's not a duplicate / or taken in work by someone else.
Reproducer
I tried this code:
let channel_name = package
.channel
.strip_prefix(channel_config.channel_alias.as_str())
.unwrap_or_else(|| package.channel.as_str())
.trim_end_matches('/');
I expected to see this happen:
warning: unnecessary closure used to substitute value for `Option::None`
--> src/cli/search.rs:412:28
|
412 | let channel_name = package
| ____________________________^
413 | | .channel
414 | | .strip_prefix(channel_config.channel_alias.as_str())
415 | | .unwrap_or_else(|| package.channel.as_str())
| |______________------------------------------------------^
| |
| help: use `unwrap_or(package.channel.as_str())` instead: `unwrap_or_else(|| package.channel.as_str())`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations
= note: `#[warn(clippy::unnecessary_lazy_evaluations)]` on by default
Instead, this happened:
warning: unnecessary closure used to substitute value for `Option::None`
--> src/cli/search.rs:412:28
|
412 | let channel_name = package
| ____________________________^
413 | | .channel
414 | | .strip_prefix(channel_config.channel_alias.as_str())
415 | | .unwrap_or_else(|| package.channel.as_str())
| |______________------------------------------------------^
| |
| help: use `unwrap_or(..)` instead: `unwrap_or(package.channel.as_str())`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations
= note: `#[warn(clippy::unnecessary_lazy_evaluations)]` on by default
Version
rustc 1.80.0 (051478957 2024-07-21)
binary: rustc
commit-hash: 051478957371ee0084a7c0913941d2a8c4757bb9
commit-date: 2024-07-21
host: aarch64-apple-darwin
release: 1.80.0
LLVM version: 18.1.7
Additional Labels
No response