Skip to content

Commit

Permalink
fix(resolve): Don't list transitive, incompatible dependencies as ava…
Browse files Browse the repository at this point in the history
…ilable

This is part of rust-lang#13908
  • Loading branch information
epage committed Sep 19, 2024
1 parent 2107a43 commit fd743da
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 41 deletions.
74 changes: 37 additions & 37 deletions src/cargo/ops/cargo_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,29 +795,27 @@ fn report_latest(possibilities: &[IndexSummary], change: &PackageChange) -> Opti
return Some(report);
}

let incompat_ver_compat_msrv_summary = possibilities
.iter()
.map(|s| s.as_summary())
.filter(|s| {
if let (Some(summary_rust_version), Some(required_rust_version)) =
(s.rust_version(), required_rust_version)
{
summary_rust_version.is_compatible_with(required_rust_version)
} else {
true
}
})
.filter(|s| is_latest(s.version(), package_id.version()))
.max_by_key(|s| s.version());
if let Some(summary) = incompat_ver_compat_msrv_summary {
let warn = if change.is_transitive.unwrap_or(true) {
Default::default()
} else {
style::WARN
};
let version = summary.version();
let report = format!(" {warn}(available: v{version}){warn:#}");
return Some(report);
if !change.is_transitive.unwrap_or(true) {
let incompat_ver_compat_msrv_summary = possibilities
.iter()
.map(|s| s.as_summary())
.filter(|s| {
if let (Some(summary_rust_version), Some(required_rust_version)) =
(s.rust_version(), required_rust_version)
{
summary_rust_version.is_compatible_with(required_rust_version)
} else {
true
}
})
.filter(|s| is_latest(s.version(), package_id.version()))
.max_by_key(|s| s.version());
if let Some(summary) = incompat_ver_compat_msrv_summary {
let warn = style::WARN;
let version = summary.version();
let report = format!(" {warn}(available: v{version}){warn:#}");
return Some(report);
}
}

let compat_ver_summary = possibilities
Expand All @@ -836,20 +834,22 @@ fn report_latest(possibilities: &[IndexSummary], change: &PackageChange) -> Opti
return Some(report);
}

let incompat_ver_summary = possibilities
.iter()
.map(|s| s.as_summary())
.filter(|s| is_latest(s.version(), package_id.version()))
.max_by_key(|s| s.version());
if let Some(summary) = incompat_ver_summary {
let msrv_note = summary
.rust_version()
.map(|rv| format!(", requires Rust {rv}"))
.unwrap_or_default();
let warn = style::NOP;
let version = summary.version();
let report = format!(" {warn}(available: v{version}{msrv_note}){warn:#}");
return Some(report);
if !change.is_transitive.unwrap_or(true) {
let incompat_ver_summary = possibilities
.iter()
.map(|s| s.as_summary())
.filter(|s| is_latest(s.version(), package_id.version()))
.max_by_key(|s| s.version());
if let Some(summary) = incompat_ver_summary {
let msrv_note = summary
.rust_version()
.map(|rv| format!(", requires Rust {rv}"))
.unwrap_or_default();
let warn = style::NOP;
let version = summary.version();
let report = format!(" {warn}(available: v{version}{msrv_note}){warn:#}");
return Some(report);
}
}

None
Expand Down
1 change: 0 additions & 1 deletion tests/testsuite/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ fn broken_path_override_warns() {
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
[ADDING] bar v0.1.0 (available: v0.2.0)
[WARNING] path override for crate `a` has altered the original list of
dependencies; the dependency on `bar` was either added or
modified to not match the previously resolved version
Expand Down
5 changes: 2 additions & 3 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ fn update_precise() {
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[DOWNGRADING] serde v0.2.1 -> v0.2.0
[NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest
"#]])
.run();
Expand Down Expand Up @@ -2183,7 +2182,7 @@ fn update_breaking_specific_packages_that_wont_update() {
[UPDATING] non-semver v1.0.0 -> v1.0.1 (available: v2.0.0)
[UPDATING] renamed-from v1.0.0 -> v1.0.1 (available: v2.0.0)
[UPDATING] transitive-compatible v1.0.0 -> v1.0.1
[UPDATING] transitive-incompatible v1.0.0 -> v1.0.1 (available: v2.0.0)
[UPDATING] transitive-incompatible v1.0.0 -> v1.0.1
"#]])
.run();
Expand Down Expand Up @@ -2397,7 +2396,7 @@ fn update_breaking_spec_version_transitive() {
.with_stderr_data(str![[r#"
[UPDATING] `[..]` index
[LOCKING] 1 package to latest compatible version
[UPDATING] dep v1.1.0 -> v1.1.1 (available: v2.0.0)
[UPDATING] dep v1.1.0 -> v1.1.1
"#]])
.run();
Expand Down

0 comments on commit fd743da

Please sign in to comment.