diff --git a/src/cargo/util/toml/targets.rs b/src/cargo/util/toml/targets.rs index 9b30dd7fc..401761a84 100644 --- a/src/cargo/util/toml/targets.rs +++ b/src/cargo/util/toml/targets.rs @@ -277,8 +277,8 @@ pub fn resolve_bins( for bin in &mut bins { validate_bin_name(bin, warnings)?; - validate_bin_crate_types(bin, warnings, errors)?; - validate_bin_proc_macro(bin, warnings, errors)?; + validate_bin_crate_types(bin, edition, warnings, errors)?; + validate_bin_proc_macro(bin, edition, warnings, errors)?; let path = target_path(bin, &inferred, "bin", package_root, edition, &mut |_| { if let Some(legacy_path) = legacy_bin_path(package_root, name_or_panic(bin), has_lib) { @@ -1057,7 +1057,8 @@ fn validate_target_name( fn validate_bin_proc_macro( target: &TomlTarget, - _warnings: &mut Vec, + edition: Edition, + warnings: &mut Vec, errors: &mut Vec, ) -> CargoResult<()> { if target.proc_macro() == Some(true) { @@ -1067,6 +1068,8 @@ fn validate_bin_proc_macro( set `true`", name )); + } else { + validate_proc_macro(target, "binary", edition, warnings)?; } Ok(()) } @@ -1090,7 +1093,8 @@ fn validate_proc_macro( fn validate_bin_crate_types( target: &TomlTarget, - _warnings: &mut Vec, + edition: Edition, + warnings: &mut Vec, errors: &mut Vec, ) -> CargoResult<()> { if let Some(crate_types) = target.crate_types() { @@ -1102,6 +1106,8 @@ fn validate_bin_crate_types( name, crate_types.join(", ") )); + } else { + validate_crate_types(target, "binary", edition, warnings)?; } } Ok(()) diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index 86f3f097f..3ed3cce12 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -1159,6 +1159,8 @@ fn bin_crate_type2() { p.cargo("check") .with_stderr( "\ +[WARNING] `crate_type` is deprecated in favor of `crate-type` and will not work in the 2024 edition +(in the `foo` binary target) [CHECKING] foo v0.5.0 ([CWD]) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s ", @@ -1190,10 +1192,14 @@ fn bin_crate_type2_2024() { .build(); p.cargo("check") .masquerade_as_nightly_cargo(&["edition2024"]) + .with_status(101) .with_stderr( "\ -[CHECKING] foo v0.5.0 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s +[ERROR] failed to parse manifest at `[CWD]/Cargo.toml` + +Caused by: + `crate_type` is unsupported as of the 2024 edition; instead use `crate-type` + (in the `foo` binary target) ", ) .run(); @@ -1223,6 +1229,7 @@ fn bin_crate_type2_conflict() { p.cargo("check") .with_stderr( "\ +[WARNING] `crate_type` is redundant with `crate-type`, preferring `crate-type` in the `foo` binary target [CHECKING] foo v0.5.0 ([CWD]) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s ", @@ -2057,6 +2064,8 @@ fn bin_proc_macro2() { foo.cargo("check") .with_stderr( "\ +[WARNING] `proc_macro` is deprecated in favor of `proc-macro` and will not work in the 2024 edition +(in the `foo` binary target) [CHECKING] foo v0.5.0 ([CWD]) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s ", @@ -2075,7 +2084,7 @@ fn bin_proc_macro2_2024() { [package] name = "foo" version = "0.5.0" - edition = "2015" + edition = "2024" authors = ["wycats@example.com"] [[bin]] @@ -2089,10 +2098,14 @@ fn bin_proc_macro2_2024() { foo.cargo("check") .masquerade_as_nightly_cargo(&["edition2024"]) + .with_status(101) .with_stderr( "\ -[CHECKING] foo v0.5.0 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s +[ERROR] failed to parse manifest at `[CWD]/Cargo.toml` + +Caused by: + `proc_macro` is unsupported as of the 2024 edition; instead use `proc-macro` + (in the `foo` binary target) ", ) .run(); @@ -2123,6 +2136,7 @@ fn bin_proc_macro2_conflict() { foo.cargo("check") .with_stderr( "\ +[WARNING] `proc_macro` is redundant with `proc-macro`, preferring `proc-macro` in the `foo` binary target [CHECKING] foo v0.5.0 ([CWD]) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s ",