@@ -722,24 +722,28 @@ impl BuildOutput {
722
722
const DOCS_LINK_SUGGESTION : & str = "See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
723
723
for more information about build script outputs.";
724
724
725
+ fn has_reserved_prefix ( flag : & str ) -> bool {
726
+ RESERVED_PREFIXES
727
+ . iter ( )
728
+ . any ( |reserved_prefix| flag. starts_with ( reserved_prefix) )
729
+ }
730
+
725
731
fn check_minimum_supported_rust_version_for_new_syntax (
726
732
pkg_descr : & str ,
727
733
msrv : & Option < RustVersion > ,
728
- key : & str ,
734
+ flag : & str ,
729
735
) -> CargoResult < ( ) > {
730
736
if let Some ( msrv) = msrv {
731
737
let new_syntax_added_in = RustVersion :: from_str ( "1.77.0" ) ?;
732
738
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 ( ) ;
739
+ let old_syntax_suggestion = if has_reserved_prefix ( flag) {
740
+ format ! ( "Consider using the old `cargo:` syntax in front of `{flag}`.\n " )
741
+ } else if flag. starts_with ( "metadata=" ) {
742
+ let old_format_flag = flag. strip_prefix ( "metadata=" ) . unwrap ( ) ;
743
+ format ! ( "Consider using the old `cargo:{old_format_flag}` syntax instead of `cargo::{flag}` (note the single colon).\n " )
744
+ } else {
745
+ String :: new ( )
746
+ } ;
743
747
744
748
bail ! (
745
749
"the `cargo::` syntax for build script output instructions was added in \
@@ -806,17 +810,13 @@ impl BuildOutput {
806
810
} ;
807
811
let mut old_syntax = false ;
808
812
let ( key, value) = if let Some ( data) = line. strip_prefix ( "cargo::" ) {
813
+ check_minimum_supported_rust_version_for_new_syntax ( pkg_descr, msrv, data) ?;
809
814
// For instance, `cargo::rustc-flags=foo` or `cargo::metadata=foo=bar`.
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)
815
+ parse_directive ( whence. as_str ( ) , line, data, old_syntax) ?
813
816
} else if let Some ( data) = line. strip_prefix ( "cargo:" ) {
814
817
old_syntax = true ;
815
818
// For instance, `cargo:rustc-flags=foo`.
816
- if RESERVED_PREFIXES
817
- . iter ( )
818
- . any ( |prefix| data. starts_with ( prefix) )
819
- {
819
+ if has_reserved_prefix ( data) {
820
820
parse_directive ( whence. as_str ( ) , line, data, old_syntax) ?
821
821
} else {
822
822
// For instance, `cargo:foo=bar`.
0 commit comments