Skip to content

Commit 2607f6d

Browse files
committed
Old syntax suggestion.
1 parent d72d0b2 commit 2607f6d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,13 +725,26 @@ impl BuildOutput {
725725
fn check_minimum_supported_rust_version_for_new_syntax(
726726
pkg_descr: &str,
727727
msrv: &Option<RustVersion>,
728+
key: &str,
728729
) -> CargoResult<()> {
729730
if let Some(msrv) = msrv {
730731
let new_syntax_added_in = RustVersion::from_str("1.77.0")?;
731732
if !new_syntax_added_in.is_compatible_with(msrv.as_partial()) {
733+
let prefix = format!("{key}=");
734+
735+
let old_syntax_suggestion = RESERVED_PREFIXES
736+
.contains(&&*prefix)
737+
.then(|| {
738+
format!(
739+
"Consider using the old `cargo:` syntax in front of `{prefix}`.\n"
740+
)
741+
})
742+
.unwrap_or_default();
743+
732744
bail!(
733745
"the `cargo::` syntax for build script output instructions was added in \
734746
Rust 1.77.0, but the minimum supported Rust version of `{pkg_descr}` is {msrv}.\n\
747+
{old_syntax_suggestion}\
735748
{DOCS_LINK_SUGGESTION}"
736749
);
737750
}
@@ -793,9 +806,10 @@ impl BuildOutput {
793806
};
794807
let mut old_syntax = false;
795808
let (key, value) = if let Some(data) = line.strip_prefix("cargo::") {
796-
check_minimum_supported_rust_version_for_new_syntax(pkg_descr, msrv)?;
797809
// For instance, `cargo::rustc-flags=foo` or `cargo::metadata=foo=bar`.
798-
parse_directive(whence.as_str(), line, data, old_syntax)?
810+
let (key, value) = parse_directive(whence.as_str(), line, data, old_syntax)?;
811+
check_minimum_supported_rust_version_for_new_syntax(pkg_descr, msrv, key)?;
812+
(key, value)
799813
} else if let Some(data) = line.strip_prefix("cargo:") {
800814
old_syntax = true;
801815
// For instance, `cargo:rustc-flags=foo`.

0 commit comments

Comments
 (0)