Skip to content

Commit 5559e02

Browse files
committed
Adjust the edition2021 resolver diff report.
1 parent 0a38a21 commit 5559e02

File tree

3 files changed

+28
-56
lines changed

3 files changed

+28
-56
lines changed

src/cargo/core/resolver/features.rs

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,9 @@ impl ResolvedFeatures {
351351
/// Compares the result against the original resolver behavior.
352352
///
353353
/// Used by `cargo fix --edition` to display any differences.
354-
pub fn compare_legacy(&self, legacy: &ResolvedFeatures) -> FeatureDifferences {
354+
pub fn compare_legacy(&self, legacy: &ResolvedFeatures) -> DiffMap {
355355
let legacy_features = legacy.legacy_features.as_ref().unwrap();
356-
let features = self
357-
.activated_features
356+
self.activated_features
358357
.iter()
359358
.filter_map(|((pkg_id, for_host), new_features)| {
360359
let old_features = match legacy_features.get(pkg_id) {
@@ -371,30 +370,7 @@ impl ResolvedFeatures {
371370
Some(((*pkg_id, *for_host), removed_features))
372371
}
373372
})
374-
.collect();
375-
let legacy_deps = legacy.legacy_dependencies.as_ref().unwrap();
376-
let optional_deps = self
377-
.activated_dependencies
378-
.iter()
379-
.filter_map(|((pkg_id, for_host), new_deps)| {
380-
let old_deps = match legacy_deps.get(pkg_id) {
381-
Some(deps) => deps.iter().cloned().collect(),
382-
None => BTreeSet::new(),
383-
};
384-
// The new resolver should never add dependencies.
385-
assert_eq!(new_deps.difference(&old_deps).next(), None);
386-
let removed_deps: BTreeSet<_> = old_deps.difference(new_deps).cloned().collect();
387-
if removed_deps.is_empty() {
388-
None
389-
} else {
390-
Some(((*pkg_id, *for_host), removed_deps))
391-
}
392-
})
393-
.collect();
394-
FeatureDifferences {
395-
features,
396-
optional_deps,
397-
}
373+
.collect()
398374
}
399375
}
400376

@@ -403,12 +379,6 @@ impl ResolvedFeatures {
403379
/// Key is `(pkg_id, for_host)`. Value is a set of features or dependencies removed.
404380
pub type DiffMap = BTreeMap<(PackageId, bool), BTreeSet<InternedString>>;
405381

406-
/// Differences between resolvers.
407-
pub struct FeatureDifferences {
408-
pub features: DiffMap,
409-
pub optional_deps: DiffMap,
410-
}
411-
412382
pub struct FeatureResolver<'a, 'cfg> {
413383
ws: &'a Workspace<'cfg>,
414384
target_data: &'a RustcTargetData<'cfg>,

src/cargo/ops/fix.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ fn check_resolver_change(ws: &Workspace<'_>, opts: &FixOptions) -> CargoResult<(
255255
)?;
256256

257257
let differences = v2_features.compare_legacy(&ws_resolve.resolved_features);
258-
if differences.features.is_empty() && differences.optional_deps.is_empty() {
258+
if differences.is_empty() {
259259
// Nothing is different, nothing to report.
260260
return Ok(());
261261
}
@@ -265,32 +265,27 @@ fn check_resolver_change(ws: &Workspace<'_>, opts: &FixOptions) -> CargoResult<(
265265
)?;
266266
drop_eprintln!(
267267
config,
268-
"This may cause dependencies to resolve with a different set of features."
268+
"This may cause some dependencies to be built with fewer features enabled than previously."
269269
);
270270
drop_eprintln!(
271271
config,
272272
"More information about the resolver changes may be found \
273-
at https://doc.rust-lang.org/cargo/reference/features.html#feature-resolver-version-2"
273+
at https://doc.rust-lang.org/nightly/edition-guide/rust-2021/default-cargo-resolver.html"
274274
);
275275
drop_eprintln!(
276276
config,
277-
"The following differences were detected with the current configuration:\n"
277+
"When building the following dependencies, \
278+
the given features will no longer be used:\n"
278279
);
279-
let report = |changes: crate::core::resolver::features::DiffMap, what| {
280-
for ((pkg_id, for_host), removed) in changes {
281-
drop_eprint!(config, " {}", pkg_id);
282-
if for_host {
283-
drop_eprint!(config, " (as build dependency)");
284-
}
285-
if !removed.is_empty() {
286-
let joined: Vec<_> = removed.iter().map(|s| s.as_str()).collect();
287-
drop_eprint!(config, " removed {} `{}`", what, joined.join(","));
288-
}
289-
drop_eprint!(config, "\n");
280+
for ((pkg_id, for_host), removed) in differences {
281+
drop_eprint!(config, " {}", pkg_id);
282+
if for_host {
283+
drop_eprint!(config, " (as host dependency)");
290284
}
291-
};
292-
report(differences.features, "features");
293-
report(differences.optional_deps, "optional dependency");
285+
drop_eprint!(config, ": ");
286+
let joined: Vec<_> = removed.iter().map(|s| s.as_str()).collect();
287+
drop_eprintln!(config, "{}", joined.join(", "));
288+
}
294289
drop_eprint!(config, "\n");
295290
report_maybe_diesel(config, &ws_resolve.targeted_resolve)?;
296291
Ok(())

tests/testsuite/fix.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,8 +1431,9 @@ fn edition_v2_resolver_report() {
14311431
}
14321432
Package::new("common", "1.0.0")
14331433
.feature("f1", &[])
1434-
.file("src/lib.rs", "")
1434+
.add_dep(Dependency::new("opt_dep", "1.0").optional(true))
14351435
.publish();
1436+
Package::new("opt_dep", "1.0.0").publish();
14361437

14371438
Package::new("bar", "1.0.0")
14381439
.add_dep(
@@ -1454,6 +1455,9 @@ fn edition_v2_resolver_report() {
14541455
[dependencies]
14551456
common = "1.0"
14561457
bar = "1.0"
1458+
1459+
[build-dependencies]
1460+
common = { version = "1.0", features = ["opt_dep"] }
14571461
"#,
14581462
)
14591463
.file("src/lib.rs", "")
@@ -1466,13 +1470,16 @@ fn edition_v2_resolver_report() {
14661470
[DOWNLOADING] crates ...
14671471
[DOWNLOADED] common v1.0.0 [..]
14681472
[DOWNLOADED] bar v1.0.0 [..]
1473+
[DOWNLOADED] opt_dep v1.0.0 [..]
14691474
note: Switching to Edition 2021 will enable the use of the version 2 feature resolver in Cargo.
1470-
This may cause dependencies to resolve with a different set of features.
1471-
More information about the resolver changes may be found at https://doc.rust-lang.org/cargo/reference/features.html#feature-resolver-version-2
1472-
The following differences were detected with the current configuration:
1475+
This may cause some dependencies to be built with fewer features enabled than previously.
1476+
More information about the resolver changes may be found at https://doc.rust-lang.org/nightly/edition-guide/rust-2021/default-cargo-resolver.html
1477+
When building the following dependencies, the given features will no longer be used:
14731478
1474-
common v1.0.0 removed features `f1`
1479+
common v1.0.0: f1, opt_dep
1480+
common v1.0.0 (as host dependency): f1
14751481
1482+
[CHECKING] opt_dep v1.0.0
14761483
[CHECKING] common v1.0.0
14771484
[CHECKING] bar v1.0.0
14781485
[CHECKING] foo v0.1.0 [..]

0 commit comments

Comments
 (0)