Skip to content

Commit 987ea33

Browse files
Merge pull request #22432 from mkeeter/package-feature-scope
Filter package-scoped features
2 parents f964ba4 + e702c54 commit 987ea33

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

crates/rust-analyzer/src/flycheck.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ pub(crate) enum Target {
6363
}
6464

6565
impl CargoOptions {
66-
pub(crate) fn apply_on_command(&self, cmd: &mut Command, ws_target_dir: Option<&Utf8Path>) {
66+
pub(crate) fn apply_on_command(
67+
&self,
68+
cmd: &mut Command,
69+
ws_target_dir: Option<&Utf8Path>,
70+
package_repr: Option<&str>,
71+
) {
6772
for target in &self.target_tuples {
6873
cmd.args(["--target", target.as_str()]);
6974
}
@@ -83,8 +88,24 @@ impl CargoOptions {
8388
cmd.arg("--no-default-features");
8489
}
8590
if !self.features.is_empty() {
91+
// If we are scoped to a particular package, filter any features of the form
92+
// `crate/feature` which target other packages.
93+
let features = if let Some(name) = package_repr {
94+
let filtered = self
95+
.features
96+
.iter()
97+
.filter(|f| match f.split_once('/') {
98+
Some((c, _)) => c == name,
99+
None => true,
100+
})
101+
.map(|s| s.as_str())
102+
.collect::<Vec<_>>();
103+
filtered.join(" ")
104+
} else {
105+
self.features.join(" ")
106+
};
86107
cmd.arg("--features");
87-
cmd.arg(self.features.join(" "));
108+
cmd.arg(features);
88109
}
89110
}
90111
if let Some(target_dir) = self.target_dir_config.target_dir(ws_target_dir) {
@@ -890,12 +911,18 @@ impl FlycheckActor {
890911
cmd.env("CARGO_LOG", "cargo::core::compiler::fingerprint=info");
891912
cmd.arg(&cargo_options.subcommand);
892913

893-
match scope {
894-
FlycheckScope::Workspace => cmd.arg("--workspace"),
914+
let package_repr = match scope {
915+
FlycheckScope::Workspace => {
916+
cmd.arg("--workspace");
917+
None
918+
}
895919
FlycheckScope::Package {
896920
package: PackageSpecifier::Cargo { package_id },
897921
..
898-
} => cmd.arg("-p").arg(&package_id.repr),
922+
} => {
923+
cmd.arg("-p").arg(&package_id.repr);
924+
Some(package_id.repr.as_str())
925+
}
899926
FlycheckScope::Package {
900927
package: PackageSpecifier::BuildInfo { .. }, ..
901928
} => {
@@ -935,6 +962,7 @@ impl FlycheckActor {
935962
cargo_options.apply_on_command(
936963
&mut cmd,
937964
self.ws_target_dir.as_ref().map(Utf8PathBuf::as_path),
965+
package_repr,
938966
);
939967
cmd.args(&cargo_options.extra_args);
940968
Some((cmd, FlycheckCommandOrigin::Cargo))

crates/rust-analyzer/src/test_runner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl CargoTestHandle {
124124
cmd.arg("--no-fail-fast");
125125
cmd.arg("--manifest-path");
126126
cmd.arg(root.join("Cargo.toml"));
127-
options.apply_on_command(&mut cmd, ws_target_dir);
127+
options.apply_on_command(&mut cmd, ws_target_dir, Some(&test_target.package));
128128
cmd.arg("--");
129129
if let Some(path) = path {
130130
cmd.arg(path);

0 commit comments

Comments
 (0)