Skip to content

Commit

Permalink
Auto merge of #9649 - ehuss:edition2021-report-tweaking, r=alexcrichton
Browse files Browse the repository at this point in the history
Adjust the edition2021 resolver diff report.

This makes some adjustments to the report given on `cargo fix --edition` when there are differences in the feature resolver.

- Tweak the wording to be clearer.
- Removed the "activated dependencies" differences. This doesn't actually work (dependencies aren't ever completely removed), and isn't all that interesting (since it would be duplicating the same information from the feature differences).
  • Loading branch information
bors committed Jul 2, 2021
2 parents 0a38a21 + 5559e02 commit 3ebb5f1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 56 deletions.
36 changes: 3 additions & 33 deletions src/cargo/core/resolver/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()
}
}

Expand All @@ -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>,
Expand Down
31 changes: 13 additions & 18 deletions src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
}
Expand All @@ -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(())
Expand Down
17 changes: 12 additions & 5 deletions tests/testsuite/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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", "")
Expand All @@ -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 [..]
Expand Down

0 comments on commit 3ebb5f1

Please sign in to comment.