Passing feature flags to rust-analyzer in workspace

In a workspace with multiple packages, one package a has a feature myfeature that I want rust-analyzer to enable. I tried setting "rust-analyzer.cargo.features": ["a/myfeature"] in .vscode/settings.json, however RA then fails to check another package b that doesn't depend on a with the following error message:

cargo check failed to start: Cargo watcher failed, the command produced no valid metadata (exit code: ExitStatus(unix_wait_status(25856))): error: the package 'b' does not contain this feature: a/myfeature

How to fix this?


To sum up, the workspace looks like this:

workspace/
  Cargo.toml             # workspace = { resolver = "2", members = ["a", "b"] }
  .vscode/settings.json  # { "rust-analyzer.cargo.features": ["a/myfeature"] }
  a/
    Cargo.toml           # feature.myfeature = []
    src/main.rs
  b/                     # does not depend on package `a`
    Cargo.toml
    src/main.rs          # RA errors here: "cargo check failed to start ..."
1 Like
"rust-analyzer.cargo.features": ["myfeature"]
# instead of
"rust-analyzer.cargo.features": ["a/myfeature"]

seems to work.

1 Like

I tested wrong at the time, changing a/myfeature to myfeature in .vscode/settings.json doesn't fix my issue.

I found the open RA issue about it: Make `cargo.features` a crate-level config · Issue #18114 · rust-lang/rust-analyzer · GitHub