Skip to content

suspicious_double_ref_op names incorrect return type in method receiver #146227

@arkeet

Description

@arkeet

Code

use std::io::Write;

pub fn f(file: &std::fs::File) {
    _ = file.clone().write(&[]);
}

Current output

warning: using `.clone()` on a double reference, which returns `&mut &File` instead of cloning the inner type
 --> src\lib.rs:4:13
  |
4 |     _ = file.clone().write(&[]);
  |             ^^^^^^^^
  |
  = note: `#[warn(suspicious_double_ref_op)]` on by default

Desired output

warning: using `.clone()` on a double reference, which returns `&File` instead of cloning the inner type

Rationale and extra context

The return type of file.clone() is &File, but the message strangely claims it is &mut &File, which happens to be the the receiver type of the write call (from impl Write for &File).

Other cases

Rust Version

rustc 1.89.0 (29483883e 2025-08-04)
binary: rustc
commit-hash: 29483883eed69d5fb4db01964cdf2af4d86e9cb2
commit-date: 2025-08-04
host: x86_64-pc-windows-msvc
release: 1.89.0
LLVM version: 20.1.7

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions