Skip to content

Commit

Permalink
Auto merge of #14471 - epage:msrv, r=ehuss
Browse files Browse the repository at this point in the history
feat(resolve): Report MSRV compatible version instead of incomptible

### What does this PR try to resolve?

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.

```console
$ cargo update --workspace -v
```
![image](https://github.com/user-attachments/assets/27e40dda-287b-4223-a377-0233205307a2)

### How should we test and review this PR?

I changed the label from `latest` to `available` to not have to keep coming up with relevant terms for each case.

### Additional information

This is the final step before asking for new feedback on #13908
  • Loading branch information
bors committed Sep 3, 2024
2 parents 2807645 + 911f5e1 commit fda48a0
Show file tree
Hide file tree
Showing 36 changed files with 125 additions and 73 deletions.
68 changes: 60 additions & 8 deletions src/cargo/ops/cargo_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,31 +757,83 @@ fn report_latest(possibilities: &[IndexSummary], change: &PackageChange) -> Opti
}

let version_req = package_id.version().to_caret_req();
if let Some(version) = possibilities
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()))
.map(|s| s.version().clone())
.max()
.max_by_key(|s| s.version())
{
let warn = style::WARN;
let report = format!(" {warn}(latest compatible: v{version}){warn:#}");
let version = summary.version();
let report = format!(" {warn}(available: v{version}){warn:#}");
return Some(report);
}

if let Some(version) = possibilities
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()))
.map(|s| s.version().clone())
.max()
.max_by_key(|s| s.version())
{
let warn = if change.is_transitive.unwrap_or(true) {
Default::default()
} else {
style::WARN
};
let report = format!(" {warn}(latest: v{version}){warn:#}");
let version = summary.version();
let report = format!(" {warn}(available: v{version}){warn:#}");
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);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/cargo_add/default_features/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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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/namever/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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/testsuite/cargo_add/preserve_sorted/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.
4 changes: 2 additions & 2 deletions tests/testsuite/cargo_add/preserve_unsorted/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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fn ignore_version_from_other_platform() {
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
[ADDING] bar v0.1.0 (latest: v0.2.0)
[ADDING] bar v0.1.0 (available: v0.2.0)
[DOWNLOADING] crates ...
[DOWNLOADED] bar v0.1.0 (registry `dummy-registry`)
[CHECKING] bar v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/collisions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ fn collision_doc_multiple_versions() {
str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 3 packages to latest compatible versions
[ADDING] bar v1.0.0 (latest: v2.0.0)
[ADDING] bar v1.0.0 (available: v2.0.0)
[DOWNLOADING] crates ...
[DOWNLOADED] bar v2.0.0 (registry `dummy-registry`)
[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`)
Expand Down Expand Up @@ -503,7 +503,7 @@ fn collision_doc_target() {
str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 3 packages to latest compatible versions
[ADDING] bar v1.0.0 (latest: v2.0.0)
[ADDING] bar v1.0.0 (available: v2.0.0)
[DOWNLOADING] crates ...
[DOWNLOADED] orphaned v1.0.0 (registry `dummy-registry`)
[DOWNLOADED] bar v2.0.0 (registry `dummy-registry`)
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/direct_minimal_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn simple() {
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package
[ADDING] dep v1.0.0 (latest compatible: v1.1.0)
[ADDING] dep v1.0.0 (available: v1.1.0)
"#]])
.run();
Expand Down Expand Up @@ -122,7 +122,7 @@ fn yanked() {
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package
[ADDING] dep v1.1.0 (latest compatible: v1.2.0)
[ADDING] dep v1.1.0 (available: v1.2.0)
"#]])
.run();
Expand Down Expand Up @@ -176,7 +176,7 @@ fn indirect() {
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages
[ADDING] direct v1.0.0 (latest compatible: v1.1.0)
[ADDING] direct v1.0.0 (available: v1.1.0)
"#]])
.run();
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ fn multiple() {
p.cargo("check")
.with_stderr_data(str![[r#"
[LOCKING] 1 package to latest compatible version
[ADDING] bar v0.1.0 (latest: v0.2.0)
[ADDING] bar v0.1.0 (available: v0.2.0)
[CHECKING] bar v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
Expand Down
Loading

0 comments on commit fda48a0

Please sign in to comment.