Skip to content

False positive "variable does not need to be mutable" #15623

@jDomantas

Description

@jDomantas

In this code:

pub struct Foo;

impl Foo {
    fn needs_mut(&mut self) {}
}

pub fn foo(mut foo: Foo) {
    let mut call_me = || {
        let 0 = 1 else { return };
        foo.needs_mut();
    };
    call_me();
}

Rust analyzer shows 2 "variable deos not need to be mutable" warnings:

image

image

The same code compiles with rustc without any warnings or errors. Removing either mut makes rust analyzer stop reporting that warning and does not introduce any other diagnostics from ra, but then rustc reports that mut is needed there.

rust-analyzer version: 0.3.1657-standalone (326f37e 2023-09-10)

rustc version: rustc 1.71.0 (8ede3aae2 2023-07-12)

relevant settings:

"rust-analyzer.checkOnSave": false,
"rust-analyzer.completion.postfix.enable": false,
"rust-analyzer.inlayHints.chainingHints.enable": false,
"rust-analyzer.inlayHints.closingBraceHints.enable": false,
"rust-analyzer.inlayHints.parameterHints.enable": false,
"rust-analyzer.inlayHints.typeHints.enable": false,
"rust-analyzer.lens.enable": false,
"rust-analyzer.procMacro.enable": true,
"rust-analyzer.diagnostics.experimental.enable": true,

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions