Open mqudsi opened 6 months ago
In this case, clippy should have actually suggested replacing .map(|l| l.as_ref())
with .copied()
, which is clearer, doesn't trigger any other clippy lints, and is actually better for the optimizer (though this option is not necessarily always available).
Summary
Normally,
&&T
will automatically and silently behave like&T
and usingfoo.map(|t| t.as_ref())
is unneeded. However theuseless_asref
lint has a false positive in the case where types need to line up, e.g. the return types ofif
andelse
, the arms ofmatch
brackets, or in this case,Option<T>
and the result ofOption::unwrap_or(...)
.Lint Name
useless_asref
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen:
The
useless_asref
lint is incorrect here since without the call rustc (1.80.0-nightly
) will complain about mismatched types:Version
Additional Labels
@rustbot label +I-suggestion-causes-error