Greetings.
I'm am using the rust-analyzer VSCode extension, and I'm trying to set it up to lint my code with clippy. I have the following configuration currently:
{
"rust-analyzer.checkOnSave": true,
"rust-analyzer.check.command": "clippy",
"rust-analyzer.check.extraArgs": [
"--",
"-W",
"clippy::all",
"-W",
"clippy::pedantic"
],
"rust-analyzer.diagnostics.enable": true,
"rust-analyzer.diagnostics.experimental.enable": false,
"rust-analyzer.cargo.buildScripts.enable": true,
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
}
}
I want to have the clippy::all and clippy::pedantic groups enabled, because I'm in the process of learning Rust and I think it might be helpful. The problem is that I'm having some weird issues with the extension.
Suppose we have the following code:
fn main() {
let test = String::from("");
}
It will give me a warning:
warning: empty String is being created manually
--> src/main.rs:13:16
|
13 | let test = String::from("");
| ^^^^^^^^^^^^^^^^ help: consider using: `String::new()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#manual_string_new
= note: `-W clippy::manual-string-new` implied by `-W clippy::pedantic`
= help: to override `-W clippy::pedantic` add `#[allow(clippy::manual_string_new)]`
So far so good. The problem is the following - after I go and refactor the code as suggested to use String::new() and then I save the file, the warning remains.
I don't understand why. I can open the command palette and run
rust-anaylzer: Restart server
Then the code gets analyzed again and the warning goes away as expected. But obviously that's not a solution.
Anyone have an idea how to fix this?