]> git.proxmox.com Git - cargo.git/commitdiff
Make the `rust-version` error recommend `cargo update -p crate@ver --precise ...`
authorJosh Triplett <josh@joshtriplett.org>
Sat, 23 Jul 2022 06:52:49 +0000 (23:52 -0700)
committerJosh Triplett <josh@joshtriplett.org>
Mon, 8 Aug 2022 17:37:15 +0000 (10:37 -0700)
People encountering a dependency with a newer `rust-version` requirement
may not know about `cargo update --precise`, or may consider alternate
approaches that may be harmful (such as pinning with a `=` dependency).

Provide specific guidance in the error message.

If the user is using `cargo install`, suggest `cargo install --locked` instead.

src/cargo/ops/cargo_compile.rs
tests/testsuite/rust_version.rs

index 5d273295ae357e27f29000795ba2da06f90fdf00..2ac85cad48a24ca168da1107e574840896124c38 100644 (file)
@@ -661,12 +661,32 @@ pub fn create_bcx<'a, 'cfg>(
                 continue;
             }
 
+            let guidance = if ws.is_ephemeral() {
+                if ws.ignore_lock() {
+                    "Try re-running cargo install with `--locked`".to_string()
+                } else {
+                    String::new()
+                }
+            } else {
+                format!(
+                    "Either upgrade to rustc {} or newer, or use\n\
+                     cargo update -p {}@{} --precise ver\n\
+                     where `ver` is the latest version of `{}` supporting rustc {}",
+                    version,
+                    unit.pkg.name(),
+                    unit.pkg.version(),
+                    unit.pkg.name(),
+                    current_version,
+                )
+            };
+
             anyhow::bail!(
                 "package `{}` cannot be built because it requires rustc {} or newer, \
-                 while the currently active rustc version is {}",
+                 while the currently active rustc version is {}\n{}",
                 unit.pkg,
                 version,
                 current_version,
+                guidance,
             );
         }
     }
index 6f849141ff6b1d1c0cbcbabb96c1165e5dd26e69..1823cdad98adf35bbd9416be0f46b423b7e519c2 100644 (file)
@@ -124,7 +124,10 @@ fn rust_version_too_high() {
         .with_status(101)
         .with_stderr(
             "error: package `foo v0.0.1 ([..])` cannot be built because it requires \
-             rustc 1.9876.0 or newer, while the currently active rustc version is [..]",
+             rustc 1.9876.0 or newer, while the currently active rustc version is [..]\n\
+             Either upgrade to rustc 1.9876.0 or newer, or use\n\
+             cargo update -p foo@0.0.1 --precise ver\n\
+             where `ver` is the latest version of `foo` supporting rustc [..]",
         )
         .run();
     p.cargo("build --ignore-rust-version").run();
@@ -159,7 +162,10 @@ fn rust_version_dependency_fails() {
              Downloading crates ...\n  \
              Downloaded bar v0.0.1 (registry `[..]`)\n\
              error: package `bar v0.0.1` cannot be built because it requires \
-             rustc 1.2345.0 or newer, while the currently active rustc version is [..]",
+             rustc 1.2345.0 or newer, while the currently active rustc version is [..]\n\
+             Either upgrade to rustc 1.2345.0 or newer, or use\n\
+             cargo update -p bar@0.0.1 --precise ver\n\
+             where `ver` is the latest version of `bar` supporting rustc [..]",
         )
         .run();
     p.cargo("build --ignore-rust-version").run();