@@ -426,10 +426,12 @@ pub struct FeatureResolver<'a, 'gctx> {
426
426
/// If this is `true`, then a non-default `feature_key` needs to be tracked while
427
427
/// traversing the graph.
428
428
///
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
432
432
/// `for_host` tracking is also needed for `itarget` to work properly.
433
+ ///
434
+ /// [`has_any_proc_macro`]: FeatureResolver::has_any_proc_macro
433
435
track_for_host : bool ,
434
436
/// `dep_name?/feat_name` features that will be activated if `dep_name` is
435
437
/// ever activated.
@@ -490,7 +492,7 @@ impl<'a, 'gctx> FeatureResolver<'a, 'gctx> {
490
492
let member_features = self . ws . members_with_features ( specs, cli_features) ?;
491
493
for ( member, cli_features) in & member_features {
492
494
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 ( ) ) {
494
496
// Also activate for normal dependencies. This is needed if the
495
497
// proc-macro includes other targets (like binaries or tests),
496
498
// or running in `cargo test`. Note that in a workspace, if
@@ -852,7 +854,7 @@ impl<'a, 'gctx> FeatureResolver<'a, 'gctx> {
852
854
// for various targets which are either specified in the manifest
853
855
// or on the cargo command-line.
854
856
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_proc_macro_lib ( dep_id) ) )
856
858
. then ( || FeaturesFor :: HostDep )
857
859
. unwrap_or_default ( )
858
860
} else {
@@ -957,10 +959,24 @@ impl<'a, 'gctx> FeatureResolver<'a, 'gctx> {
957
959
}
958
960
}
959
961
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 {
961
964
self . package_set
962
965
. get_one ( package_id)
963
966
. expect ( "packages downloaded" )
964
967
. proc_macro ( )
965
968
}
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
+ }
966
982
}
0 commit comments