Skip to content

Commit 0ead10e

Browse files
committed
fix: proc-macro example from dep no longer affects feature resolution
Previously when checking if a dependency is a proc-macro, the v2 feature resolve resolver v2 looks for `proc-macro = true` for every target of the dependency. However, it's impossible to depend on a non-lib target as a proc-macro. This fix switches to only check if `proc-macro = true` for `[lib]` target for a dependency.
1 parent 2b0df94 commit 0ead10e

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/cargo/core/resolver/features.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ impl<'a, 'gctx> FeatureResolver<'a, 'gctx> {
854854
// for various targets which are either specified in the manifest
855855
// or on the cargo command-line.
856856
let lib_fk = if fk == FeaturesFor::default() {
857-
(self.track_for_host && (dep.is_build() || self.has_any_proc_macro(dep_id)))
857+
(self.track_for_host && (dep.is_build() || self.has_proc_macro_lib(dep_id)))
858858
.then(|| FeaturesFor::HostDep)
859859
.unwrap_or_default()
860860
} else {
@@ -966,4 +966,17 @@ impl<'a, 'gctx> FeatureResolver<'a, 'gctx> {
966966
.expect("packages downloaded")
967967
.proc_macro()
968968
}
969+
970+
/// Whether the given package is a proc macro lib target.
971+
///
972+
/// This is useful for checking if a dependency is a proc macro,
973+
/// as it is not possible to depend on a non-lib target as a proc-macro.
974+
fn has_proc_macro_lib(&self, package_id: PackageId) -> bool {
975+
self.package_set
976+
.get_one(package_id)
977+
.expect("packages downloaded")
978+
.library()
979+
.map(|lib| lib.proc_macro())
980+
.unwrap_or_default()
981+
}
969982
}

tests/testsuite/features2.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -2686,9 +2686,13 @@ fn dont_unify_proc_macro_example_from_dependency() {
26862686
.build();
26872687

26882688
p.cargo("check")
2689-
.with_status(101)
2690-
.with_stderr_contains(
2691-
"[..]activated_features for invalid package: features did not find PackageId [..]pm_helper[..]NormalOrDev[..]"
2689+
.with_stderr(
2690+
"\
2691+
[LOCKING] 2 packages to latest compatible versions
2692+
[CHECKING] pm_helper v0.0.0 ([CWD]/pm_helper)
2693+
[CHECKING] foo v0.0.0 ([CWD])
2694+
[FINISHED] `dev` [..]
2695+
",
26922696
)
26932697
.run();
26942698
}

0 commit comments

Comments
 (0)