Skip to content

Commit 37f39f6

Browse files
committed
Auto merge of #11185 - weihanglo:features2-docs, r=epage
doc(features2): polish docs a bit
2 parents c71f344 + 6b8903e commit 37f39f6

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/cargo/core/resolver/features.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
//! Feature resolver.
1+
//! # Feature resolver
22
//!
3-
//! This is a new feature resolver that runs independently of the main
3+
//! This is a [new feature resolver] that runs independently of the main
44
//! dependency resolver. It has several options which can enable new feature
55
//! resolution behavior.
66
//!
77
//! One of its key characteristics is that it can avoid unifying features for
8-
//! shared dependencies in some situations. See `FeatureOpts` for the
8+
//! shared dependencies in some situations. See [`FeatureOpts`] for the
99
//! different behaviors that can be enabled. If no extra options are enabled,
1010
//! then it should behave exactly the same as the dependency resolver's
1111
//! feature resolution.
1212
//!
13-
//! The preferred way to engage this new resolver is via
14-
//! `resolve_ws_with_opts`.
13+
//! The preferred way to engage this new resolver is via [`resolve_ws_with_opts`].
1514
//!
1615
//! This does not *replace* feature resolution in the dependency resolver, but
1716
//! instead acts as a second pass which can *narrow* the features selected in
@@ -24,11 +23,19 @@
2423
//! we could experiment with that, but it seems unlikely to work or be all
2524
//! that helpful.
2625
//!
27-
//! There are many assumptions made about the dependency resolver. This
28-
//! feature resolver assumes validation has already been done on the feature
29-
//! maps, and doesn't do any validation itself. It assumes dev-dependencies
30-
//! within a dependency have been removed. There are probably other
31-
//! assumptions that I am forgetting.
26+
//! ## Assumptions
27+
//!
28+
//! There are many assumptions made about the dependency resolver:
29+
//!
30+
//! * Assumes feature validation has already been done during the construction
31+
//! of feature maps, so the feature resolver doesn't do that validation at all.
32+
//! * Assumes `dev-dependencies` within a dependency have been removed
33+
//! in the given [`Resolve`].
34+
//!
35+
//! There are probably other assumptions that I am forgetting.
36+
//!
37+
//! [new feature resolver]: https://doc.rust-lang.org/nightly/cargo/reference/resolver.html#feature-resolver-version-2
38+
//! [`resolve_ws_with_opts`]: crate::ops::resolve_ws_with_opts
3239
3340
use crate::core::compiler::{CompileKind, CompileTarget, RustcTargetData};
3441
use crate::core::dependency::{ArtifactTarget, DepKind, Dependency};
@@ -42,7 +49,7 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
4249
use std::rc::Rc;
4350

4451
/// The key used in various places to store features for a particular dependency.
45-
/// The actual discrimination happens with the `FeaturesFor` type.
52+
/// The actual discrimination happens with the [`FeaturesFor`] type.
4653
type PackageFeaturesKey = (PackageId, FeaturesFor);
4754
/// Map of activated features.
4855
type ActivateMap = HashMap<PackageFeaturesKey, BTreeSet<InternedString>>;
@@ -393,6 +400,12 @@ impl ResolvedFeatures {
393400
/// Key is `(pkg_id, for_host)`. Value is a set of features or dependencies removed.
394401
pub type DiffMap = BTreeMap<PackageFeaturesKey, BTreeSet<InternedString>>;
395402

403+
/// The new feature resolver that [`resolve`]s your project.
404+
///
405+
/// For more information, please see the [module-level documentation].
406+
///
407+
/// [`resolve`]: Self::resolve
408+
/// [module-level documentation]: crate::core::resolver::features
396409
pub struct FeatureResolver<'a, 'cfg> {
397410
ws: &'a Workspace<'cfg>,
398411
target_data: &'a RustcTargetData<'cfg>,
@@ -428,7 +441,7 @@ pub struct FeatureResolver<'a, 'cfg> {
428441
}
429442

430443
impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
431-
/// Runs the resolution algorithm and returns a new `ResolvedFeatures`
444+
/// Runs the resolution algorithm and returns a new [`ResolvedFeatures`]
432445
/// with the result.
433446
pub fn resolve(
434447
ws: &Workspace<'cfg>,
@@ -495,6 +508,10 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
495508
Ok(())
496509
}
497510

511+
/// Activates [`FeatureValue`]s on the given package.
512+
///
513+
/// This is the main entrance into the recursion of feature activation
514+
/// for a package.
498515
fn activate_pkg(
499516
&mut self,
500517
pkg_id: PackageId,

0 commit comments

Comments
 (0)