Rust-analyzer, vscode, old toolchains, and "cargo metadata"

Hi there. I'm running Windows 10, VS Code.

My problem is this: rust-analyzer wants to run the command:

cargo metadata --manifest-path .\path\to\Cargo.toml --filter-platform <something>

However, I have a rust-toolchain.toml like so:

[toolchain]
channel = "nightly-2019-01-06"

The resulting Cargo version does not have a --filter-platform flag:

$ cargo --version
cargo 1.33.0-nightly (34320d212 2019-01-03)
$ cargo help metadata | grep filter-platform
<null output>

Unfortunately cargo metadata for my toolchain version does not have a --filter-platform flag. This results in the following error:

rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file c:\projects\my-project\Cargo.toml, cargo 1.33.0-nightly (34320d212 2019-01-03): Failed to run `cargo metadata --manifest-path c:\projects\my-project\Cargo.toml` in `c:\projects\my-project\`: `cargo metadata` exited with an error: error: Found argument '--filter-platform' which wasn't expected, or isn't valid in this context

So it seems like I need to be able to customize the cargo metadata flags. Either that or turn off the cargo metadata invocation rust-analyzer performs. I have toggled off the Cargo: Autoreload feature in VS Code, but I still get these regular error pop-ups.

Is there anything I can do? Or should I open an issue on Github?

Using an old version of a nightly channel seems unusual, but I assume there is a reason.

From what I can tell rust-analyzer was not in a very usable state in January of 2019. Here is rust-analyzer as it existed when that toolchain version was released, 14,924 commits ago. You could try to find the latest version that is compatible with that old version of cargo and manually install that version or hack the currently-installed version to use a different command.

Yeah, in general rust-analyzer cannot support Rust versions that are too old, so you'll have to either change the current version and get lucky, or use a version from around the same time as the Rust version you're using.

1 Like

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.