Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(resolve): Report MSRV compatible version instead of incomptible #14471

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat(resolve): Report MSRV compatible version instead of incomptible
This expands on #14461 to where only MSRV-compatible versions are
"actionable".  MSRV-incompatible versions are therefore unstyled.

We report the MSRV needed so people can choose to unblock by updating
their MSRV.  I had wondered if we should report the the absolute latest
MSRV-incompatible version or the one with the next higher MSRV from
where the user is at.  Both are reasonable use cases, so I erred with
absolute latest version.
  • Loading branch information
epage committed Aug 30, 2024
commit 911f5e17b61bbd185c235c7d323035590b2f9c92
52 changes: 52 additions & 0 deletions src/cargo/ops/cargo_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,20 @@ fn report_latest(possibilities: &[IndexSummary], change: &PackageChange) -> Opti
}

let version_req = package_id.version().to_caret_req();
let required_rust_version = change.required_rust_version.as_ref();

if let Some(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| package_id.version() != s.version() && version_req.matches(s.version()))
.max_by_key(|s| s.version())
{
Expand All @@ -772,6 +783,15 @@ fn report_latest(possibilities: &[IndexSummary], change: &PackageChange) -> Opti
if let Some(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())
{
Expand All @@ -785,6 +805,38 @@ fn report_latest(possibilities: &[IndexSummary], change: &PackageChange) -> Opti
return Some(report);
}

if let Some(summary) = possibilities
.iter()
.map(|s| s.as_summary())
.filter(|s| package_id.version() != s.version() && version_req.matches(s.version()))
.max_by_key(|s| s.version())
{
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 let Some(summary) = possibilities
.iter()
.map(|s| s.as_summary())
.filter(|s| is_latest(s.version(), package_id.version()))
.max_by_key(|s| s.version())
{
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testsuite/cargo_add/rustc_latest/stderr.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testsuite/cargo_add/rustc_older/stderr.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions tests/testsuite/rust_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ foo v0.0.1 ([ROOT]/foo)
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest Rust 1.60.0 compatible versions
[ADDING] newer-and-older v1.5.0 (available: v1.6.0)
[ADDING] newer-and-older v1.5.0 (available: v1.6.0, requires Rust 1.65.0)
[ADDING] only-newer v1.6.0 (requires Rust 1.65.0)

"#]])
Expand Down Expand Up @@ -319,7 +319,7 @@ foo v0.0.1 ([ROOT]/foo)
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest Rust 1.60.0 compatible versions
[ADDING] newer-and-older v1.5.0 (available: v1.6.0)
[ADDING] newer-and-older v1.5.0 (available: v1.6.0, requires Rust 1.2345)
[ADDING] only-newer v1.6.0 (requires Rust 1.2345)

"#]])
Expand Down Expand Up @@ -490,7 +490,7 @@ higher v0.0.1 ([ROOT]/foo)
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest Rust 1.50.0 compatible versions
[ADDING] newer-and-older v1.5.0 (available: v1.6.0)
[ADDING] newer-and-older v1.5.0 (available: v1.6.0, requires Rust 1.65.0)
[ADDING] only-newer v1.6.0 (requires Rust 1.65.0)

"#]])
Expand Down Expand Up @@ -619,7 +619,7 @@ fn resolve_edition2024() {
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest Rust 1.60.0 compatible versions
[ADDING] newer-and-older v1.5.0 (available: v1.6.0)
[ADDING] newer-and-older v1.5.0 (available: v1.6.0, requires Rust 1.65.0)
[ADDING] only-newer v1.6.0 (requires Rust 1.65.0)

"#]])
Expand Down Expand Up @@ -723,7 +723,7 @@ fn resolve_v3() {
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest Rust 1.60.0 compatible versions
[ADDING] newer-and-older v1.5.0 (available: v1.6.0)
[ADDING] newer-and-older v1.5.0 (available: v1.6.0, requires Rust 1.65.0)
[ADDING] only-newer v1.6.0 (requires Rust 1.65.0)

"#]])
Expand Down Expand Up @@ -871,7 +871,7 @@ fn update_msrv_resolve() {
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest Rust 1.60.0 compatible version
[ADDING] bar v1.5.0 (available: v1.6.0)
[ADDING] bar v1.5.0 (available: v1.6.0, requires Rust 1.65.0)

"#]])
.run();
Expand Down Expand Up @@ -932,7 +932,7 @@ fn update_precise_overrides_msrv_resolver() {
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest Rust 1.60.0 compatible version
[ADDING] bar v1.5.0 (available: v1.6.0)
[ADDING] bar v1.5.0 (available: v1.6.0, requires Rust 1.65.0)

"#]])
.run();
Expand Down Expand Up @@ -1019,7 +1019,7 @@ foo v0.0.1 ([ROOT]/foo)
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest Rust 1.60.0 compatible versions
[ADDING] newer-and-older v1.5.0 (available: v1.6.0)
[ADDING] newer-and-older v1.5.0 (available: v1.6.0, requires Rust 1.65.0)
[ADDING] only-newer v1.6.0 (requires Rust 1.65.0)
[DOWNLOADING] crates ...
[DOWNLOADED] newer-and-older v1.5.0 (registry `dummy-registry`)
Expand Down