Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bvanjoi opened this issue May 14, 2024 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bvanjoi
Copy link
Contributor

bvanjoi commented May 14, 2024

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

@bvanjoi bvanjoi added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 14, 2024
@tbu-
Copy link
Contributor

tbu- commented May 14, 2024

I'd canonically call (*b).clone(). What do you think about that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants