diff --git a/src/cargo/core/resolver/features.rs b/src/cargo/core/resolver/features.rs index 8be2b48a0614..807bdc4533a8 100644 --- a/src/cargo/core/resolver/features.rs +++ b/src/cargo/core/resolver/features.rs @@ -854,7 +854,7 @@ impl<'a, 'gctx> FeatureResolver<'a, 'gctx> { // for various targets which are either specified in the manifest // or on the cargo command-line. let lib_fk = if fk == FeaturesFor::default() { - (self.track_for_host && (dep.is_build() || self.has_any_proc_macro(dep_id))) + (self.track_for_host && (dep.is_build() || self.has_proc_macro_lib(dep_id))) .then(|| FeaturesFor::HostDep) .unwrap_or_default() } else { @@ -966,4 +966,17 @@ impl<'a, 'gctx> FeatureResolver<'a, 'gctx> { .expect("packages downloaded") .proc_macro() } + + /// Whether the given package is a proc macro lib target. + /// + /// This is useful for checking if a dependency is a proc macro, + /// as it is not possible to depend on a non-lib target as a proc-macro. + fn has_proc_macro_lib(&self, package_id: PackageId) -> bool { + self.package_set + .get_one(package_id) + .expect("packages downloaded") + .library() + .map(|lib| lib.proc_macro()) + .unwrap_or_default() + } } diff --git a/tests/testsuite/features2.rs b/tests/testsuite/features2.rs index 878324290d9c..189514572873 100644 --- a/tests/testsuite/features2.rs +++ b/tests/testsuite/features2.rs @@ -2686,9 +2686,13 @@ fn dont_unify_proc_macro_example_from_dependency() { .build(); p.cargo("check") - .with_status(101) - .with_stderr_contains( - "[..]activated_features for invalid package: features did not find PackageId [..]pm_helper[..]NormalOrDev[..]" + .with_stderr( + "\ +[LOCKING] 2 packages to latest compatible versions +[CHECKING] pm_helper v0.0.0 ([CWD]/pm_helper) +[CHECKING] foo v0.0.0 ([CWD]) +[FINISHED] `dev` [..] +", ) .run(); }