Skip to content

Filter package-scoped features#22432

Merged
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
mkeeter:package-feature-scope
May 23, 2026
Merged

Filter package-scoped features#22432
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
mkeeter:package-feature-scope

Conversation

@mkeeter
Copy link
Copy Markdown
Contributor

@mkeeter mkeeter commented May 23, 2026

When rust-analyzer runs a flycheck on a binary package after a file write, it uses check -p regardless of rust-analyzer.check.workspace. This interacts poorly with package-specific features (in package/feature form) enabled in rust-analyzer.cargo.features.

Consider a workspace with two binary crates, foo and bar, each with a non-default feature:

[package]
name = "foo"
version = "0.1.0"
edition = "2024"

[features]
omg = []
[package]
name = "bar"
version = "0.1.0"
edition = "2024"

[features]
lol = []

I would like to enable both features, so I have configured rust-analyzer as such:

rust-analyzer.cargo.features = ["foo/omg", "bar/lol"]

The initial indexing and check work fine, because they happen in the workspace scope, and all of those features exist.

However, if I edit and save a file within one of the crates, the subsequent check happens with a package scope. This fails because all of the features are still passed to cargo check, but it's only targeting a single package:

2026-05-22T20:17:40.648309-04:00 ERROR Flycheck failed to run the following command:
CommandHandle {
  program: "/Users/mjk/.cargo/bin/cargo",
  arguments: [
    "check", "-p", "bar", "--bin", "bar", "--message-format=json",
    "--manifest-path", "/Users/mjk/code/r-a-test/Cargo.toml",
    "--keep-going", "--features", "foo/omg bar/lol"
  ],
  current_dir: Some("/Users/mjk/code/r-a-test")
},
error=Cargo watcher failed, the command produced no valid metadata (exit code: ExitStatus(unix_wait_status(25856))):
error: the package 'bar' does not contain this feature: foo/omg

(Repro repo is at mkeeter/ra-crate-features)


This PR adjusts CargoOptions::apply_on_command to take an optional package name. When the package name is present, package-specific features (package/feat) that do not match aren't passed to the cargo subcommand. Unscoped features (feat) are unmodified.

I believe this is a strict improvement to the previous behavior: passing package-specific features for packages not being built would always fail, and this PR eliminates those failure modes. It doesn't fix everything: unscoped features in rust-analyzer.cargo.features may still lead to failures, but that's a preexisting condition.

(This took a few false starts; apologies for the noise in #22421 and #22422)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 23, 2026
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we have an issue about this.

Thanks!

View changes since this review

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue May 23, 2026
Merged via the queue into rust-lang:master with commit 987ea33 May 23, 2026
18 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 23, 2026
@mkeeter
Copy link
Copy Markdown
Contributor Author

mkeeter commented May 24, 2026

It looks like #10298 is the relevant issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants