Filter package-scoped features#22432
Merged
Merged
Conversation
ChayimFriedman2
approved these changes
May 23, 2026
Contributor
Author
|
It looks like #10298 is the relevant issue! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
rust-analyzerruns a flycheck on a binary package after a file write, it usescheck -pregardless ofrust-analyzer.check.workspace. This interacts poorly with package-specific features (inpackage/featureform) enabled inrust-analyzer.cargo.features.Consider a workspace with two binary crates,
fooandbar, each with a non-default feature:I would like to enable both features, so I have configured
rust-analyzeras such: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:(Repro repo is at
mkeeter/ra-crate-features)This PR adjusts
CargoOptions::apply_on_commandto 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.featuresmay still lead to failures, but that's a preexisting condition.(This took a few false starts; apologies for the noise in #22421 and #22422)