Skip to content

false positive "variable does not need to be mutable" report when mutating a variable with a pattern in a closure #18209

Closed
@1e1001

Description

@1e1001

rust-analyzer version: rust-analyzer version: 1.83.0-nightly (fa724e5 2024-09-27) (also occurs with the vscode bundled rust-analyzer)

rustc version: rustc 1.83.0-nightly (fa724e5d8 2024-09-27)

editor or extension: VSCode (rust-analyzer v0.3.2121)

relevant settings: "rust-analyzer.diagnostics.experimental.enable": true

repository link (if public, optional): none

code snippet to reproduce:

#![no_std]
fn main() {
	let mut var = 1;                 // variable does not need to be mutable  rust-analyzer(unused_mut)
	let mut func = || (var,) = (2,); // variable does not need to be mutable  rust-analyzer(unused_mut)
	func();
}

Removing either mut causes errors building (for obvious reason)

The combination of the variable being in the closure and the tuple pattern causes rust-analyzer to not think that var got mutated, removing either of them removes the error

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions