diff --git a/src/cargo/ops/cargo_update.rs b/src/cargo/ops/cargo_update.rs
index a73a829baba..f206cb9045b 100644
--- a/src/cargo/ops/cargo_update.rs
+++ b/src/cargo/ops/cargo_update.rs
@@ -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);
}
diff --git a/tests/testsuite/cargo_add/default_features/stderr.term.svg b/tests/testsuite/cargo_add/default_features/stderr.term.svg
index dac62f4c166..dd0680b5e70 100644
--- a/tests/testsuite/cargo_add/default_features/stderr.term.svg
+++ b/tests/testsuite/cargo_add/default_features/stderr.term.svg
@@ -28,7 +28,7 @@
Locking 2 packages to latest compatible versions
- Adding my-package2 v0.4.1+my-package (latest: v99999.0.0+my-package)
+ Adding my-package2 v0.4.1+my-package (available: v99999.0.0+my-package)
diff --git a/tests/testsuite/cargo_add/list_features_path/stderr.term.svg b/tests/testsuite/cargo_add/list_features_path/stderr.term.svg
index c2bfc437b63..e1120826456 100644
--- a/tests/testsuite/cargo_add/list_features_path/stderr.term.svg
+++ b/tests/testsuite/cargo_add/list_features_path/stderr.term.svg
@@ -37,7 +37,7 @@
Locking 1 package to latest compatible version
- Adding my-package v0.1.1+my-package (latest: v99999.0.0+my-package)
+ Adding my-package v0.1.1+my-package (available: v99999.0.0+my-package)
diff --git a/tests/testsuite/cargo_add/list_features_path_no_default/stderr.term.svg b/tests/testsuite/cargo_add/list_features_path_no_default/stderr.term.svg
index 00f0c40d3e6..4e71147a29c 100644
--- a/tests/testsuite/cargo_add/list_features_path_no_default/stderr.term.svg
+++ b/tests/testsuite/cargo_add/list_features_path_no_default/stderr.term.svg
@@ -37,7 +37,7 @@
Locking 1 package to latest compatible version
- Adding my-package v0.1.1+my-package (latest: v99999.0.0+my-package)
+ Adding my-package v0.1.1+my-package (available: v99999.0.0+my-package)
diff --git a/tests/testsuite/cargo_add/namever/stderr.term.svg b/tests/testsuite/cargo_add/namever/stderr.term.svg
index b9b7272d826..b2faa90be48 100644
--- a/tests/testsuite/cargo_add/namever/stderr.term.svg
+++ b/tests/testsuite/cargo_add/namever/stderr.term.svg
@@ -30,7 +30,7 @@
Locking 3 packages to latest compatible versions
- Adding my-package2 v0.2.3+my-package (latest: v99999.0.0+my-package)
+ Adding my-package2 v0.2.3+my-package (available: v99999.0.0+my-package)
diff --git a/tests/testsuite/cargo_add/no_default_features/stderr.term.svg b/tests/testsuite/cargo_add/no_default_features/stderr.term.svg
index dac62f4c166..dd0680b5e70 100644
--- a/tests/testsuite/cargo_add/no_default_features/stderr.term.svg
+++ b/tests/testsuite/cargo_add/no_default_features/stderr.term.svg
@@ -28,7 +28,7 @@
Locking 2 packages to latest compatible versions
- Adding my-package2 v0.4.1+my-package (latest: v99999.0.0+my-package)
+ Adding my-package2 v0.4.1+my-package (available: v99999.0.0+my-package)
diff --git a/tests/testsuite/cargo_add/overwrite_default_features/stderr.term.svg b/tests/testsuite/cargo_add/overwrite_default_features/stderr.term.svg
index dac62f4c166..dd0680b5e70 100644
--- a/tests/testsuite/cargo_add/overwrite_default_features/stderr.term.svg
+++ b/tests/testsuite/cargo_add/overwrite_default_features/stderr.term.svg
@@ -28,7 +28,7 @@
Locking 2 packages to latest compatible versions
- Adding my-package2 v0.4.1+my-package (latest: v99999.0.0+my-package)
+ Adding my-package2 v0.4.1+my-package (available: v99999.0.0+my-package)
diff --git a/tests/testsuite/cargo_add/overwrite_default_features_with_no_default_features/stderr.term.svg b/tests/testsuite/cargo_add/overwrite_default_features_with_no_default_features/stderr.term.svg
index dac62f4c166..dd0680b5e70 100644
--- a/tests/testsuite/cargo_add/overwrite_default_features_with_no_default_features/stderr.term.svg
+++ b/tests/testsuite/cargo_add/overwrite_default_features_with_no_default_features/stderr.term.svg
@@ -28,7 +28,7 @@
Locking 2 packages to latest compatible versions
- Adding my-package2 v0.4.1+my-package (latest: v99999.0.0+my-package)
+ Adding my-package2 v0.4.1+my-package (available: v99999.0.0+my-package)
diff --git a/tests/testsuite/cargo_add/overwrite_no_default_features/stderr.term.svg b/tests/testsuite/cargo_add/overwrite_no_default_features/stderr.term.svg
index dac62f4c166..dd0680b5e70 100644
--- a/tests/testsuite/cargo_add/overwrite_no_default_features/stderr.term.svg
+++ b/tests/testsuite/cargo_add/overwrite_no_default_features/stderr.term.svg
@@ -28,7 +28,7 @@
Locking 2 packages to latest compatible versions
- Adding my-package2 v0.4.1+my-package (latest: v99999.0.0+my-package)
+ Adding my-package2 v0.4.1+my-package (available: v99999.0.0+my-package)
diff --git a/tests/testsuite/cargo_add/overwrite_no_default_features_with_default_features/stderr.term.svg b/tests/testsuite/cargo_add/overwrite_no_default_features_with_default_features/stderr.term.svg
index dac62f4c166..dd0680b5e70 100644
--- a/tests/testsuite/cargo_add/overwrite_no_default_features_with_default_features/stderr.term.svg
+++ b/tests/testsuite/cargo_add/overwrite_no_default_features_with_default_features/stderr.term.svg
@@ -28,7 +28,7 @@
Locking 2 packages to latest compatible versions
- Adding my-package2 v0.4.1+my-package (latest: v99999.0.0+my-package)
+ Adding my-package2 v0.4.1+my-package (available: v99999.0.0+my-package)
diff --git a/tests/testsuite/cargo_add/overwrite_path_with_version/stderr.term.svg b/tests/testsuite/cargo_add/overwrite_path_with_version/stderr.term.svg
index 0755e89c410..97f168c0d65 100644
--- a/tests/testsuite/cargo_add/overwrite_path_with_version/stderr.term.svg
+++ b/tests/testsuite/cargo_add/overwrite_path_with_version/stderr.term.svg
@@ -1,4 +1,4 @@
-