Open
Description
Summary
Clippy suggests code that does not compile.
Lint Name
option_if_let_else
Reproducer
I tried this code:
fn fp(a: Option<impl Any + 'static>) -> Option<Box<dyn Any>> {
match a {
Some(a) => Some(Box::from(a)),
None => None,
}
}
I saw this happen:
Clippy suggests
fn fp(a: Option<impl Any + 'static>) -> Option<Box<dyn Any>> {
a.map_or_else(|| None, |a| Some(Box::from(a)))
}
which does not compile:
note: expected enum `std::option::Option<std::boxed::Box<(dyn std::any::Any + 'static)>>`
found enum `std::option::Option<std::boxed::Box<impl Any + 'static>>`
I expected to see this happen:
Suggestion compiles, or no suggestion.
Version
rustc 1.85.1 (4eb161250 2025-03-15)
binary: rustc
commit-hash: 4eb161250e340c8f48f66e2b929ef4a5bed7c181
commit-date: 2025-03-15
host: x86_64-unknown-linux-gnu
release: 1.85.1
LLVM version: 19.1.7
Additional Labels
@rustbot label +I-suggestion-causes-error