VSCode rust-analyzer and `cargo watch -x run` recompile when saving

Hi there,

I have a weird problem: whenever I use VSCode with rust-analyzer to work on a project, cargo watch -x run recompiles several dependencies. And the other way round: whenever cargo watch -x run recompiles the project, VSCode rust-analyzer has to recompile the project on save.

When I don't use VSCode Rust Analyzer and edit the Code e.g. with NeoVim (with a working rust-analyzer setup), this does not happen. When I use VS Code but do not start cargo to compile the project, it doesn't happen.

I checked if there might be different toolchain versions, but I have no other toolchain installed but the current stable.

And now I am baffled.

What am I doing wrong?

Best regards,

This can happen if you have some custom RUSTFLAGS set (by env or config file) and either

  • The flags differ between the two builds, or
  • One build is a cross-compilation (--target specified) and the other is not

Make the flags the same, and if you are using --target, include it in the arguments to both, even if that means specifying the current machine's target triple.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.