Skip to content

Confusing reborrow hints when calling immutable method from mutable method #13131

@al2me6

Description

@al2me6

rust-analyzer version: 0.4.1183-standalone (6bea872 2022-08-26)

rustc version: rustc 1.65.0-nightly (878aef79d 2022-08-20)

relevant settings: "rust-analyzer.inlayHints.reborrowHints.enable": "always"

For the snippet

struct Foo;

impl Foo {
    fn immutable(&self) -> usize {
        0
    }

    fn mutable(&mut self) {
        let x = self.immutable();
    }
}

r-a gives the hint

let x = &*self.immutable();
//      ^^

which doesn't compile.

When self is manually parenthesized, r-a does show the correct hint:

let x = (&*self).immutable();
//       ^^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions