Open
Description
The autofix for map[&key] = value;
generates invalid code:
use std::collections::HashMap;
fn main() {
let mut map = HashMap::<usize, usize>::new();
map[&42] = 27;
}
==>
use std::collections::HashMap;
fn main() {
let mut map = HashMap::<usize, usize>::new();
let val = map.insert(get_mut(entry(&42, p(|val| { *val.or_insert(27); }));
}
rust-analyzer version: rust-analyzer 1 (e402c49 2023-12-01) (installed from the Arch Linux repos)
rustc version:
$ rustc -vV
rustc 1.76.0-nightly (06e02d5b2 2023-12-09)
binary: rustc
commit-hash: 06e02d5b259c1e88cbf0c74366d9e0a4c7cfd6d9
commit-date: 2023-12-09
host: x86_64-unknown-linux-gnu
release: 1.76.0-nightly
LLVM version: 17.0.5
(installed via rustup
)
relevant settings: Editor used is nvim version NVIM v0.10.0-dev-1807+g096211a87b
(current git head) using current git head of nvim-lspconfig
. The command used to trigger the refactor is :lua vim.lsp.buf.code_action()
and then selecting “to modify a HashMap [...]” while in normal mode with the cursor above the line map[&42] = 27;
.