Skip to content

Confusing new warning suspicious_double_ref_op in beta 1.71.0 #112489

Closed
@tspiteri

Description

@tspiteri

Code

use std::borrow::Borrow;

struct S;

trait T: Sized {
    fn foo(self) {}
}

impl T for S {}
impl T for &S {}

fn main() {
    let s = S;
    s.borrow().foo();
    s.foo();
}

Current output

Compiling borrow v0.1.0 (/tmp/borrow)
warning: using `.borrow()` on a double reference, which returns `&S` instead of borrowing the inner type
  --> src/main.rs:14:6
   |
14 |     s.borrow().foo();
   |      ^^^^^^^^^
   |
   = note: `#[warn(suspicious_double_ref_op)]` on by default

warning: `borrow` (bin "borrow") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.12s

Desired output

Compiling borrow v0.1.0 (/tmp/borrow)
    Finished dev [unoptimized + debuginfo] target(s) in 0.20s

Rationale and extra context

If I have a type S, and a trait T that is implemented for both S and &S, s.borrow() is a valid way to get a reference &S from an object of type S. But since beta 1.71, this emits a warning. I have no idea what the warning is trying to convey, what "double reference" is referring to, or what "the inner type" is.

Other cases

No response

Anything else?

$ rustc +beta --version
rustc 1.71.0-beta.3 (78a6ac0a8 2023-06-08)

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions