Skip to content

Commit

Permalink
Make the rust-version error recommend `cargo update --precise -p cr…
Browse files Browse the repository at this point in the history
…ate@ver`

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.
  • Loading branch information
joshtriplett committed Jul 23, 2022
1 parent caf3c37 commit 931bb6c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,12 +661,24 @@ pub fn create_bcx<'a, 'cfg>(
continue;
}

let guidance = if ws.is_ephemeral() {
String::new()
} else {
format!(
"Either upgrade to rustc {} or newer, or use\n\
cargo update --precise -p {}@ver\n\
where `ver` is the latest version of `{}` supporting rustc {}",
version, unit.pkg, unit.pkg, 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,
);
}
}
Expand Down
10 changes: 8 additions & 2 deletions tests/testsuite/rust_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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[..]\n\
cargo update[..]\n\
where[..]",
)
.run();
p.cargo("build --ignore-rust-version").run();
Expand Down Expand Up @@ -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[..]\n\
cargo update[..]\n\
where[..]",
)
.run();
p.cargo("build --ignore-rust-version").run();
Expand Down

0 comments on commit 931bb6c

Please sign in to comment.