Skip to content

Commit a201d25

Browse files
committed
refactor: rename is_proc_macro to reflect it checks every targets
1 parent b3425d8 commit a201d25

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/cargo/core/resolver/features.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,12 @@ pub struct FeatureResolver<'a, 'gctx> {
426426
/// If this is `true`, then a non-default `feature_key` needs to be tracked while
427427
/// traversing the graph.
428428
///
429-
/// This is only here to avoid calling `is_proc_macro` when all feature
430-
/// options are disabled (because `is_proc_macro` can trigger downloads).
431-
/// This has to be separate from `FeatureOpts.decouple_host_deps` because
429+
/// This is only here to avoid calling [`has_any_proc_macro`] when all feature
430+
/// options are disabled (because [`has_any_proc_macro`] can trigger downloads).
431+
/// This has to be separate from [`FeatureOpts::decouple_host_deps`] because
432432
/// `for_host` tracking is also needed for `itarget` to work properly.
433+
///
434+
/// [`has_any_proc_macro`]: FeatureResolver::has_any_proc_macro
433435
track_for_host: bool,
434436
/// `dep_name?/feat_name` features that will be activated if `dep_name` is
435437
/// ever activated.
@@ -490,7 +492,7 @@ impl<'a, 'gctx> FeatureResolver<'a, 'gctx> {
490492
let member_features = self.ws.members_with_features(specs, cli_features)?;
491493
for (member, cli_features) in &member_features {
492494
let fvs = self.fvs_from_requested(member.package_id(), cli_features);
493-
let fk = if self.track_for_host && self.is_proc_macro(member.package_id()) {
495+
let fk = if self.track_for_host && self.has_any_proc_macro(member.package_id()) {
494496
// Also activate for normal dependencies. This is needed if the
495497
// proc-macro includes other targets (like binaries or tests),
496498
// or running in `cargo test`. Note that in a workspace, if
@@ -852,7 +854,7 @@ impl<'a, 'gctx> FeatureResolver<'a, 'gctx> {
852854
// for various targets which are either specified in the manifest
853855
// or on the cargo command-line.
854856
let lib_fk = if fk == FeaturesFor::default() {
855-
(self.track_for_host && (dep.is_build() || self.is_proc_macro(dep_id)))
857+
(self.track_for_host && (dep.is_build() || self.has_any_proc_macro(dep_id)))
856858
.then(|| FeaturesFor::HostDep)
857859
.unwrap_or_default()
858860
} else {
@@ -957,7 +959,8 @@ impl<'a, 'gctx> FeatureResolver<'a, 'gctx> {
957959
}
958960
}
959961

960-
fn is_proc_macro(&self, package_id: PackageId) -> bool {
962+
/// Whether the given package has any proc macro target, including proc-macro examples.
963+
fn has_any_proc_macro(&self, package_id: PackageId) -> bool {
961964
self.package_set
962965
.get_one(package_id)
963966
.expect("packages downloaded")

0 commit comments

Comments
 (0)