Skip to content

Commit 2b913b6

Browse files
committed
doc(features2): explain the meaning of presence in activated_features
1 parent 9e83959 commit 2b913b6

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/cargo/core/resolver/features.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ type ActivateMap = HashMap<PackageFeaturesKey, BTreeSet<InternedString>>;
5757
/// Set of all activated features for all packages in the resolve graph.
5858
pub struct ResolvedFeatures {
5959
/// Map of features activated for each package.
60+
///
61+
/// The presence of each key also means the package itself is activated,
62+
/// even its associated set contains no features.
6063
activated_features: ActivateMap,
6164
/// Options that change how the feature resolver operates.
6265
opts: FeatureOpts,
@@ -406,8 +409,14 @@ pub struct FeatureResolver<'a, 'cfg> {
406409
/// Options that change how the feature resolver operates.
407410
opts: FeatureOpts,
408411
/// Map of features activated for each package.
412+
///
413+
/// The presence of each key also means the package itself is activated,
414+
/// even its associated set contains no features.
409415
activated_features: ActivateMap,
410416
/// Map of optional dependencies activated for each package.
417+
///
418+
/// The key is the package having their dependencies activated.
419+
/// The value comes from `dep_name` part of the feature syntax `dep:dep_name`.
411420
activated_dependencies: ActivateMap,
412421
/// Keeps track of which packages have had its dependencies processed.
413422
/// Used to avoid cycles, and to speed up processing.
@@ -497,20 +506,24 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
497506
Ok(())
498507
}
499508

500-
/// Activates [`FeatureValue`]s on the given package.
509+
/// Activates a list of [`FeatureValue`] for a given package.
501510
///
502-
/// This is the main entrance into the recursion of feature activation
503-
/// for a package.
511+
/// This is the main entrance into the recursion of feature activation for a package.
512+
/// Other `activate_*` functions would be called inside this function accordingly.
504513
fn activate_pkg(
505514
&mut self,
506515
pkg_id: PackageId,
507516
fk: FeaturesFor,
508517
fvs: &[FeatureValue],
509518
) -> CargoResult<()> {
510519
log::trace!("activate_pkg {} {}", pkg_id.name(), fk);
511-
// Add an empty entry to ensure everything is covered. This is intended for
512-
// finding bugs where the resolver missed something it should have visited.
513-
// Remove this in the future if `activated_features` uses an empty default.
520+
// Cargo must insert an empty set here as the presence of an (empty) set
521+
// also means that the dependency is activated.
522+
// This `is_activated` behavior for dependencies was previously depends on field
523+
// `activated_dependencies`, which is less useful after rust-lang/cargo#11183.
524+
//
525+
// That is, we may keep or remove `activated_dependencies` in the future
526+
// if figuring out it can completely be replaced with `activated_features`.
514527
self.activated_features
515528
.entry((pkg_id, fk.apply_opts(&self.opts)))
516529
.or_insert_with(BTreeSet::new);

0 commit comments

Comments
 (0)