Skip to content

Commit fd542b0

Browse files
committed
Add extra details in the new feature resolver doc comment.
1 parent e57bd02 commit fd542b0

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

src/cargo/core/resolver/features.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,38 @@
55
//! new behaviors. When `-Zfeatures` is not used, it will fall back to using
66
//! the original `Resolve` feature computation. With `-Zfeatures` enabled,
77
//! this will walk the dependency graph and compute the features using a
8-
//! different algorithm. One of its key characteristics is that it can avoid
9-
//! unifying features for shared dependencies in some situations.
8+
//! different algorithm.
9+
//!
10+
//! One of its key characteristics is that it can avoid unifying features for
11+
//! shared dependencies in some situations. See `FeatureOpts` for the
12+
//! different behaviors that can be enabled. If no extra options are enabled,
13+
//! then it should behave exactly the same as the dependency resolver's
14+
//! feature resolution. This can be verified by setting the
15+
//! `__CARGO_FORCE_NEW_FEATURES=compare` environment variable and running
16+
//! Cargo's test suite (or building other projects), and checking if it
17+
//! panics. Note: the `features2` tests will fail because they intentionally
18+
//! compare the old vs new behavior, so forcing the old behavior will
19+
//! naturally fail the tests.
1020
//!
1121
//! The preferred way to engage this new resolver is via
1222
//! `resolve_ws_with_opts`.
1323
//!
14-
//! There are many assumptions made about the resolver itself. It assumes
15-
//! validation has already been done on the feature maps, and doesn't do any
16-
//! validation itself. It assumes dev-dependencies within a dependency have
17-
//! been removed.
24+
//! This does not *replace* feature resolution in the dependency resolver, but
25+
//! instead acts as a second pass which can *narrow* the features selected in
26+
//! the dependency resolver. The dependency resolver still needs to do its own
27+
//! feature resolution in order to avoid selecting optional dependencies that
28+
//! are never enabled. The dependency resolver could, in theory, just assume
29+
//! all optional dependencies on all packages are enabled (and remove all
30+
//! knowledge of features), but that could introduce new requirements that
31+
//! might change old behavior or cause conflicts. Maybe some day in the future
32+
//! we could experiment with that, but it seems unlikely to work or be all
33+
//! that helpful.
34+
//!
35+
//! There are many assumptions made about the dependency resolver. This
36+
//! feature resolver assumes validation has already been done on the feature
37+
//! maps, and doesn't do any validation itself. It assumes dev-dependencies
38+
//! within a dependency have been removed. There are probably other
39+
//! assumptions that I am forgetting.
1840
1941
use crate::core::compiler::{CompileKind, RustcTargetData};
2042
use crate::core::dependency::{DepKind, Dependency};

0 commit comments

Comments
 (0)