Skip to content

Commit 931bb6c

Browse files
committed
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.
1 parent caf3c37 commit 931bb6c

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/cargo/ops/cargo_compile.rs

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

664+
let guidance = if ws.is_ephemeral() {
665+
String::new()
666+
} else {
667+
format!(
668+
"Either upgrade to rustc {} or newer, or use\n\
669+
cargo update --precise -p {}@ver\n\
670+
where `ver` is the latest version of `{}` supporting rustc {}",
671+
version, unit.pkg, unit.pkg, current_version,
672+
)
673+
};
674+
664675
anyhow::bail!(
665676
"package `{}` cannot be built because it requires rustc {} or newer, \
666-
while the currently active rustc version is {}",
677+
while the currently active rustc version is {}\n{}",
667678
unit.pkg,
668679
version,
669680
current_version,
681+
guidance,
670682
);
671683
}
672684
}

tests/testsuite/rust_version.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ 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\
128+
Either upgrade[..]\n\
129+
cargo update[..]\n\
130+
where[..]",
128131
)
129132
.run();
130133
p.cargo("build --ignore-rust-version").run();
@@ -159,7 +162,10 @@ fn rust_version_dependency_fails() {
159162
Downloading crates ...\n \
160163
Downloaded bar v0.0.1 (registry `[..]`)\n\
161164
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 [..]",
165+
rustc 1.2345.0 or newer, while the currently active rustc version is [..]\n\
166+
Either upgrade[..]\n\
167+
cargo update[..]\n\
168+
where[..]",
163169
)
164170
.run();
165171
p.cargo("build --ignore-rust-version").run();

0 commit comments

Comments
 (0)