Skip to content

Commit ce40690

Browse files
committed
Auto merge of #10891 - joshtriplett:rust-version-recommend-precise, r=ehuss
Make the `rust-version` error recommend `cargo update --precise -p crate@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.
2 parents e6827ee + 934e790 commit ce40690

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/cargo/ops/cargo_compile.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,12 +661,34 @@ pub fn create_bcx<'a, 'cfg>(
661661
continue;
662662
}
663663

664+
let guidance = if ws.is_ephemeral() {
665+
if ws.ignore_lock() {
666+
"Try re-running cargo install with `--locked`".to_string()
667+
} else {
668+
String::new()
669+
}
670+
} else if !unit.is_local() {
671+
format!(
672+
"Either upgrade to rustc {} or newer, or use\n\
673+
cargo update -p {}@{} --precise ver\n\
674+
where `ver` is the latest version of `{}` supporting rustc {}",
675+
version,
676+
unit.pkg.name(),
677+
unit.pkg.version(),
678+
unit.pkg.name(),
679+
current_version,
680+
)
681+
} else {
682+
String::new()
683+
};
684+
664685
anyhow::bail!(
665686
"package `{}` cannot be built because it requires rustc {} or newer, \
666-
while the currently active rustc version is {}",
687+
while the currently active rustc version is {}\n{}",
667688
unit.pkg,
668689
version,
669690
current_version,
691+
guidance,
670692
);
671693
}
672694
}

tests/testsuite/rust_version.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ fn rust_version_too_high() {
124124
.with_status(101)
125125
.with_stderr(
126126
"error: package `foo v0.0.1 ([..])` cannot be built because it requires \
127-
rustc 1.9876.0 or newer, while the currently active rustc version is [..]",
127+
rustc 1.9876.0 or newer, while the currently active rustc version is [..]\n\n",
128128
)
129129
.run();
130130
p.cargo("build --ignore-rust-version").run();
@@ -159,7 +159,10 @@ fn rust_version_dependency_fails() {
159159
Downloading crates ...\n \
160160
Downloaded bar v0.0.1 (registry `[..]`)\n\
161161
error: package `bar v0.0.1` cannot be built because it requires \
162-
rustc 1.2345.0 or newer, while the currently active rustc version is [..]",
162+
rustc 1.2345.0 or newer, while the currently active rustc version is [..]\n\
163+
Either upgrade to rustc 1.2345.0 or newer, or use\n\
164+
cargo update -p bar@0.0.1 --precise ver\n\
165+
where `ver` is the latest version of `bar` supporting rustc [..]",
163166
)
164167
.run();
165168
p.cargo("build --ignore-rust-version").run();

0 commit comments

Comments
 (0)