mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Adjust the edition2021 resolver diff report.
This commit is contained in:
parent
0a38a2138d
commit
5559e028a8
@ -351,10 +351,9 @@ impl ResolvedFeatures {
|
|||||||
/// Compares the result against the original resolver behavior.
|
/// Compares the result against the original resolver behavior.
|
||||||
///
|
///
|
||||||
/// Used by `cargo fix --edition` to display any differences.
|
/// 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 legacy_features = legacy.legacy_features.as_ref().unwrap();
|
||||||
let features = self
|
self.activated_features
|
||||||
.activated_features
|
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|((pkg_id, for_host), new_features)| {
|
.filter_map(|((pkg_id, for_host), new_features)| {
|
||||||
let old_features = match legacy_features.get(pkg_id) {
|
let old_features = match legacy_features.get(pkg_id) {
|
||||||
@ -371,30 +370,7 @@ impl ResolvedFeatures {
|
|||||||
Some(((*pkg_id, *for_host), removed_features))
|
Some(((*pkg_id, *for_host), removed_features))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.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,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,12 +379,6 @@ impl ResolvedFeatures {
|
|||||||
/// Key is `(pkg_id, for_host)`. Value is a set of features or dependencies removed.
|
/// Key is `(pkg_id, for_host)`. Value is a set of features or dependencies removed.
|
||||||
pub type DiffMap = BTreeMap<(PackageId, bool), BTreeSet<InternedString>>;
|
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> {
|
pub struct FeatureResolver<'a, 'cfg> {
|
||||||
ws: &'a Workspace<'cfg>,
|
ws: &'a Workspace<'cfg>,
|
||||||
target_data: &'a RustcTargetData<'cfg>,
|
target_data: &'a RustcTargetData<'cfg>,
|
||||||
|
@ -255,7 +255,7 @@ fn check_resolver_change(ws: &Workspace<'_>, opts: &FixOptions) -> CargoResult<(
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
let differences = v2_features.compare_legacy(&ws_resolve.resolved_features);
|
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.
|
// Nothing is different, nothing to report.
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@ -265,32 +265,27 @@ fn check_resolver_change(ws: &Workspace<'_>, opts: &FixOptions) -> CargoResult<(
|
|||||||
)?;
|
)?;
|
||||||
drop_eprintln!(
|
drop_eprintln!(
|
||||||
config,
|
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!(
|
drop_eprintln!(
|
||||||
config,
|
config,
|
||||||
"More information about the resolver changes may be found \
|
"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!(
|
drop_eprintln!(
|
||||||
config,
|
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 differences {
|
||||||
for ((pkg_id, for_host), removed) in changes {
|
drop_eprint!(config, " {}", pkg_id);
|
||||||
drop_eprint!(config, " {}", pkg_id);
|
if for_host {
|
||||||
if for_host {
|
drop_eprint!(config, " (as host dependency)");
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
};
|
drop_eprint!(config, ": ");
|
||||||
report(differences.features, "features");
|
let joined: Vec<_> = removed.iter().map(|s| s.as_str()).collect();
|
||||||
report(differences.optional_deps, "optional dependency");
|
drop_eprintln!(config, "{}", joined.join(", "));
|
||||||
|
}
|
||||||
drop_eprint!(config, "\n");
|
drop_eprint!(config, "\n");
|
||||||
report_maybe_diesel(config, &ws_resolve.targeted_resolve)?;
|
report_maybe_diesel(config, &ws_resolve.targeted_resolve)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1431,8 +1431,9 @@ fn edition_v2_resolver_report() {
|
|||||||
}
|
}
|
||||||
Package::new("common", "1.0.0")
|
Package::new("common", "1.0.0")
|
||||||
.feature("f1", &[])
|
.feature("f1", &[])
|
||||||
.file("src/lib.rs", "")
|
.add_dep(Dependency::new("opt_dep", "1.0").optional(true))
|
||||||
.publish();
|
.publish();
|
||||||
|
Package::new("opt_dep", "1.0.0").publish();
|
||||||
|
|
||||||
Package::new("bar", "1.0.0")
|
Package::new("bar", "1.0.0")
|
||||||
.add_dep(
|
.add_dep(
|
||||||
@ -1454,6 +1455,9 @@ fn edition_v2_resolver_report() {
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
common = "1.0"
|
common = "1.0"
|
||||||
bar = "1.0"
|
bar = "1.0"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
common = { version = "1.0", features = ["opt_dep"] }
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.file("src/lib.rs", "")
|
.file("src/lib.rs", "")
|
||||||
@ -1466,13 +1470,16 @@ fn edition_v2_resolver_report() {
|
|||||||
[DOWNLOADING] crates ...
|
[DOWNLOADING] crates ...
|
||||||
[DOWNLOADED] common v1.0.0 [..]
|
[DOWNLOADED] common v1.0.0 [..]
|
||||||
[DOWNLOADED] bar 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.
|
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.
|
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/cargo/reference/features.html#feature-resolver-version-2
|
More information about the resolver changes may be found at https://doc.rust-lang.org/nightly/edition-guide/rust-2021/default-cargo-resolver.html
|
||||||
The following differences were detected with the current configuration:
|
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] common v1.0.0
|
||||||
[CHECKING] bar v1.0.0
|
[CHECKING] bar v1.0.0
|
||||||
[CHECKING] foo v0.1.0 [..]
|
[CHECKING] foo v0.1.0 [..]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user