Skip to content

False positive useless_asref on Result #16529

@domwst

Description

@domwst

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

Link to playground

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions