Closed
Description
Summary
Since unwrap_or_default
is not a const method, it should not be suggested in constant context. As it is, the lint gives a suggestion that would fail to compile.
Lint Name
manual_unwrap_or_default
Reproducer
I tried this code:
pub const fn foo(a: Option<bool>) -> bool {
match a {
Some(s) => s,
None => false,
}
}
I saw this happen:
Checking playground v0.1.0 (/tmp/playground)
warning: match can be simplified with `.unwrap_or_default()`
--> src/lib.rs:2:5
|
2 | / match a {
3 | | Some(s) => s,
4 | | None => false,
5 | | }
| |_____^ help: replace it with: `a.unwrap_or_default()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or_default
= note: `#[warn(clippy::manual_unwrap_or_default)]` on by default
warning: `playground` (lib) generated 1 warning (run `cargo clippy --fix --lib -p playground` to apply 1 suggestion)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s
I expected to see this happen:
No warning.
Version
rustc 1.79.0-nightly (5f2c7d2bf 2024-03-25)
binary: rustc
commit-hash: 5f2c7d2bfd46cad00352ab7cd66242077e2e518c
commit-date: 2024-03-25
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2
Additional Labels
@rustbot label +I-suggestion-causes-error