Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the rust-version error recommend cargo update --precise -p crate@ver #10891

Merged
merged 2 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,12 +661,34 @@ pub fn create_bcx<'a, 'cfg>(
continue;
}

let guidance = if ws.is_ephemeral() {
joshtriplett marked this conversation as resolved.
Show resolved Hide resolved
if ws.ignore_lock() {
"Try re-running cargo install with `--locked`".to_string()
joshtriplett marked this conversation as resolved.
Show resolved Hide resolved
} else {
String::new()
}
} else if !unit.is_local() {
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,
)
} else {
String::new()
};

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
7 changes: 5 additions & 2 deletions tests/testsuite/rust_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ 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\n",
)
.run();
p.cargo("build --ignore-rust-version").run();
Expand Down Expand Up @@ -159,7 +159,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();
Expand Down