fix: emit 1.77 syntax error only when msrv is incompatible

This commit is contained in:
Weihang Lo 2024-04-26 09:30:26 -04:00
parent f70bfd3f4a
commit ba5ec686f9
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7
2 changed files with 2 additions and 8 deletions

View File

@ -724,10 +724,9 @@ impl BuildOutput {
pkg_descr: &str, pkg_descr: &str,
msrv: &Option<RustVersion>, msrv: &Option<RustVersion>,
) -> CargoResult<()> { ) -> CargoResult<()> {
let new_syntax_added_in = &RustVersion::from_str("1.77.0")?;
if let Some(msrv) = msrv { if let Some(msrv) = msrv {
if msrv < new_syntax_added_in { let new_syntax_added_in = RustVersion::from_str("1.77.0")?;
if !new_syntax_added_in.is_compatible_with(msrv.as_partial()) {
bail!( bail!(
"the `cargo::` syntax for build script output instructions was added in \ "the `cargo::` syntax for build script output instructions was added in \
Rust 1.77.0, but the minimum supported Rust version of `{pkg_descr}` is {msrv}.\n\ Rust 1.77.0, but the minimum supported Rust version of `{pkg_descr}` is {msrv}.\n\

View File

@ -5527,14 +5527,9 @@ fn test_new_syntax_with_compatible_partial_msrv() {
.build(); .build();
p.cargo("check") p.cargo("check")
.with_status(101)
.with_stderr_contains( .with_stderr_contains(
"\ "\
[COMPILING] foo [..] [COMPILING] foo [..]
[ERROR] the `cargo::` syntax for build script output instructions was added in Rust 1.77.0, \
but the minimum supported Rust version of `foo v0.0.0 ([ROOT]/foo)` is 1.77.
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
for more information about build script outputs.
", ",
) )
.run(); .run();