rust-lang / rust-lang/rust-clippy
False positive `useless_asref` on `Result`
Open
@mikhailofff is already working on this.
Since Feb 14, 2026.
C-bug
I-false-positive
I-suggestion-causes-error
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
When .as_ref().map(Clone::clone) is used on Result<T, E>, clippy says that it's a useless as_ref and suggests replacing .as_ref().map(...) with .clone() (which changes the expression type from Result<T, &E> to Result<T, E>). I think rather it should complain about .map(Clone::clone) and suggest replacing it with .cloned(), which fixes the issue.
Lint Name
useless_asref
Reproducer
I tried this code:
fn main() {
let r: Result<i32, i64> = Ok(1);
let _r = r.as_ref().map(Clone::clone);
}
I saw this happen:
Checking playground v0.0.1 (/playground)
warning: this call to `as_ref.map(...)` does nothing
--> src/main.rs:3:14
|
3 | let _r = r.as_ref().map(Clone::clone);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `r.clone()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#useless_asref
= note: `#[warn(clippy::useless_asref)]` on by default
I expected to see this happen:
No lint or complains about .map(Clone::clone).
Version
rustc 1.95.0-nightly (f889772d6 2026-02-05)
binary: rustc
commit-hash: f889772d6500faebcac5bb70fa44b5e6581c38cd
commit-date: 2026-02-05
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 22.1.0
Additional Labels
@rustbot label +I-suggestion-causes-error
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.