Skip to content

Rust-analyzer shows an error for code that compiles #20662

@dirkvdb

Description

@dirkvdb

Rust analyzer version 0.3.2593-standalone (6b2e677795 2025-08-25)
rustc version 1.89.0 (29483883e 2025-08-04)
editor extension: both vscode and zed show the same errors

For a few months I'm getting a few lines of code that are flagged as an error by rust-analyzer but the code compiles just fine with rustc. I tried to simplify the code to a minimal snippet that still triggers the error. The error reported by rust-analyzer is: cannot mutate immutable variable 'b' [E0384]

code snippet to reproduce:

pub trait A: std::ops::IndexMut<usize> {
    type T: A;
}

fn func(a: &mut impl A, b: &mut [i32]) {
    b[0] += 1;
}

Removing the unused argument a causes the error to go away.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions