diff --git a/src/cargo/ops/cargo_update.rs b/src/cargo/ops/cargo_update.rs
index 89e999096ba1..f206cb9045be 100644
--- a/src/cargo/ops/cargo_update.rs
+++ b/src/cargo/ops/cargo_update.rs
@@ -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())
{
@@ -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())
{
@@ -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
}
diff --git a/tests/testsuite/cargo_add/rust_version_older/stderr.term.svg b/tests/testsuite/cargo_add/rust_version_older/stderr.term.svg
index 19c491f8029b..d1580f34a102 100644
--- a/tests/testsuite/cargo_add/rust_version_older/stderr.term.svg
+++ b/tests/testsuite/cargo_add/rust_version_older/stderr.term.svg
@@ -28,7 +28,7 @@
Locking 1 package to latest Rust 1.70 compatible version
- Adding rust-version-user v0.1.0 (available: v0.2.1)
+ Adding rust-version-user v0.1.0 (available: v0.2.1, requires Rust 1.72)
diff --git a/tests/testsuite/cargo_add/rustc_latest/stderr.term.svg b/tests/testsuite/cargo_add/rustc_latest/stderr.term.svg
index 849120b58322..7b86b2ab9788 100644
--- a/tests/testsuite/cargo_add/rustc_latest/stderr.term.svg
+++ b/tests/testsuite/cargo_add/rustc_latest/stderr.term.svg
@@ -28,7 +28,7 @@
Locking 1 package to latest Rust [..] compatible version
- Adding rust-version-user v0.1.1 (available: v0.2.1)
+ Adding rust-version-user v0.1.1 (available: v0.2.1, requires Rust 1.2345)
diff --git a/tests/testsuite/cargo_add/rustc_older/stderr.term.svg b/tests/testsuite/cargo_add/rustc_older/stderr.term.svg
index 849120b58322..7b86b2ab9788 100644
--- a/tests/testsuite/cargo_add/rustc_older/stderr.term.svg
+++ b/tests/testsuite/cargo_add/rustc_older/stderr.term.svg
@@ -28,7 +28,7 @@
Locking 1 package to latest Rust [..] compatible version
- Adding rust-version-user v0.1.1 (available: v0.2.1)
+ Adding rust-version-user v0.1.1 (available: v0.2.1, requires Rust 1.2345)
diff --git a/tests/testsuite/rust_version.rs b/tests/testsuite/rust_version.rs
index a93d478addf7..c00ff012e2e5 100644
--- a/tests/testsuite/rust_version.rs
+++ b/tests/testsuite/rust_version.rs
@@ -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)
"#]])
@@ -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)
"#]])
@@ -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)
"#]])
@@ -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)
"#]])
@@ -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)
"#]])
@@ -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();
@@ -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();
@@ -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`)