Skip to content

Commit 2d02b29

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

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/cargo/core/resolver/features.rs

Lines changed: 13 additions & 4 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,10 +506,10 @@ 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,
@@ -510,7 +519,7 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
510519
log::trace!("activate_pkg {} {}", pkg_id.name(), fk);
511520
// Add an empty entry to ensure everything is covered. This is intended for
512521
// finding bugs where the resolver missed something it should have visited.
513-
// Remove this in the future if `activated_features` uses an empty default.
522+
// The presence of an (empty) set also means that the dependency is activated,
514523
self.activated_features
515524
.entry((pkg_id, fk.apply_opts(&self.opts)))
516525
.or_insert_with(BTreeSet::new);

0 commit comments

Comments
 (0)