Adjust the edition2021 resolver diff report.

This commit is contained in:
Eric Huss 2021-07-02 13:01:58 -07:00
parent 0a38a2138d
commit 5559e028a8
3 changed files with 28 additions and 56 deletions

View File

@ -351,10 +351,9 @@ impl ResolvedFeatures {
/// Compares the result against the original resolver behavior.
///
/// Used by `cargo fix --edition` to display any differences.
pub fn compare_legacy(&self, legacy: &ResolvedFeatures) -> FeatureDifferences {
pub fn compare_legacy(&self, legacy: &ResolvedFeatures) -> DiffMap {
let legacy_features = legacy.legacy_features.as_ref().unwrap();
let features = self
.activated_features
self.activated_features
.iter()
.filter_map(|((pkg_id, for_host), new_features)| {
let old_features = match legacy_features.get(pkg_id) {
@ -371,30 +370,7 @@ impl ResolvedFeatures {
Some(((*pkg_id, *for_host), removed_features))
}
})
.collect();
let legacy_deps = legacy.legacy_dependencies.as_ref().unwrap();
let optional_deps = self
.activated_dependencies
.iter()
.filter_map(|((pkg_id, for_host), new_deps)| {
let old_deps = match legacy_deps.get(pkg_id) {
Some(deps) => deps.iter().cloned().collect(),
None => BTreeSet::new(),
};
// The new resolver should never add dependencies.
assert_eq!(new_deps.difference(&old_deps).next(), None);
let removed_deps: BTreeSet<_> = old_deps.difference(new_deps).cloned().collect();
if removed_deps.is_empty() {
None
} else {
Some(((*pkg_id, *for_host), removed_deps))
}
})
.collect();
FeatureDifferences {
features,
optional_deps,
}
.collect()
}
}
@ -403,12 +379,6 @@ impl ResolvedFeatures {
/// Key is `(pkg_id, for_host)`. Value is a set of features or dependencies removed.
pub type DiffMap = BTreeMap<(PackageId, bool), BTreeSet<InternedString>>;
/// Differences between resolvers.
pub struct FeatureDifferences {
pub features: DiffMap,
pub optional_deps: DiffMap,
}
pub struct FeatureResolver<'a, 'cfg> {
ws: &'a Workspace<'cfg>,
target_data: &'a RustcTargetData<'cfg>,

View File

@ -255,7 +255,7 @@ fn check_resolver_change(ws: &Workspace<'_>, opts: &FixOptions) -> CargoResult<(
)?;
let differences = v2_features.compare_legacy(&ws_resolve.resolved_features);
if differences.features.is_empty() && differences.optional_deps.is_empty() {
if differences.is_empty() {
// Nothing is different, nothing to report.
return Ok(());
}
@ -265,32 +265,27 @@ fn check_resolver_change(ws: &Workspace<'_>, opts: &FixOptions) -> CargoResult<(
)?;
drop_eprintln!(
config,
"This may cause dependencies to resolve with a different set of features."
"This may cause some dependencies to be built with fewer features enabled than previously."
);
drop_eprintln!(
config,
"More information about the resolver changes may be found \
at https://doc.rust-lang.org/cargo/reference/features.html#feature-resolver-version-2"
at https://doc.rust-lang.org/nightly/edition-guide/rust-2021/default-cargo-resolver.html"
);
drop_eprintln!(
config,
"The following differences were detected with the current configuration:\n"
"When building the following dependencies, \
the given features will no longer be used:\n"
);
let report = |changes: crate::core::resolver::features::DiffMap, what| {
for ((pkg_id, for_host), removed) in changes {
drop_eprint!(config, " {}", pkg_id);
if for_host {
drop_eprint!(config, " (as build dependency)");
}
if !removed.is_empty() {
let joined: Vec<_> = removed.iter().map(|s| s.as_str()).collect();
drop_eprint!(config, " removed {} `{}`", what, joined.join(","));
}
drop_eprint!(config, "\n");
for ((pkg_id, for_host), removed) in differences {
drop_eprint!(config, " {}", pkg_id);
if for_host {
drop_eprint!(config, " (as host dependency)");
}
};
report(differences.features, "features");
report(differences.optional_deps, "optional dependency");
drop_eprint!(config, ": ");
let joined: Vec<_> = removed.iter().map(|s| s.as_str()).collect();
drop_eprintln!(config, "{}", joined.join(", "));
}
drop_eprint!(config, "\n");
report_maybe_diesel(config, &ws_resolve.targeted_resolve)?;
Ok(())

View File

@ -1431,8 +1431,9 @@ fn edition_v2_resolver_report() {
}
Package::new("common", "1.0.0")
.feature("f1", &[])
.file("src/lib.rs", "")
.add_dep(Dependency::new("opt_dep", "1.0").optional(true))
.publish();
Package::new("opt_dep", "1.0.0").publish();
Package::new("bar", "1.0.0")
.add_dep(
@ -1454,6 +1455,9 @@ fn edition_v2_resolver_report() {
[dependencies]
common = "1.0"
bar = "1.0"
[build-dependencies]
common = { version = "1.0", features = ["opt_dep"] }
"#,
)
.file("src/lib.rs", "")
@ -1466,13 +1470,16 @@ fn edition_v2_resolver_report() {
[DOWNLOADING] crates ...
[DOWNLOADED] common v1.0.0 [..]
[DOWNLOADED] bar v1.0.0 [..]
[DOWNLOADED] opt_dep v1.0.0 [..]
note: Switching to Edition 2021 will enable the use of the version 2 feature resolver in Cargo.
This may cause dependencies to resolve with a different set of features.
More information about the resolver changes may be found at https://doc.rust-lang.org/cargo/reference/features.html#feature-resolver-version-2
The following differences were detected with the current configuration:
This may cause some dependencies to be built with fewer features enabled than previously.
More information about the resolver changes may be found at https://doc.rust-lang.org/nightly/edition-guide/rust-2021/default-cargo-resolver.html
When building the following dependencies, the given features will no longer be used:
common v1.0.0 removed features `f1`
common v1.0.0: f1, opt_dep
common v1.0.0 (as host dependency): f1
[CHECKING] opt_dep v1.0.0
[CHECKING] common v1.0.0
[CHECKING] bar v1.0.0
[CHECKING] foo v0.1.0 [..]