rust-lang / rust-lang/rust

Can we suppress the `suspicious_double_ref_op` lint if we have successive `clone` calls?

Open
#125,113 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
// rustc code.rs

#[derive(Clone)]
struct S;

fn main() {
    let a = S;
    let b = &&a;
    let _ = b.clone().clone();
}
Current output
warning: using `.clone()` on a double reference, which returns `&S` instead of cloning the inner type
  --> ./src/main.rs:20:14
   |
20 |     let _ = b.clone().clone();
   |              ^^^^^^^^
   |
   = note: `#[warn(suspicious_double_ref_op)]` on by default

warning: 1 warning emitted
Desired output
No lint issues because we invoked two successive `clone` methods.
Rationale and extra context

No response

Other cases

No response

Rust Version
rustc 1.80.0-nightly (ef0027897 2024-05-12)
binary: rustc
commit-hash: ef0027897d2e9014766fb47dce9ddbb925d2f540
commit-date: 2024-05-12
host: aarch64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.4
Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Rust reproducer in code.rs and the suspicious_double_ref_op lint named in the issue. Run it with rustc and inspect the lint's compiler implementation and related tests, if present. Done means successive clone calls on the reproduced double reference no longer emit this lint while the current warning behavior remains covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.