Skip to content

Commit fe0819e

Browse files
committed
fix(toml): Validate crates_types/proc-macro for bin like others
Turns out, we allow these fields, just in limited ways, so we need to be consistent. I limited when this applies to reduce noise from the user solving there problem because they are unlikely to keep the field and switch it to the opposite value
1 parent 2c31fe3 commit fe0819e

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/cargo/util/toml/targets.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ pub fn resolve_bins(
277277

278278
for bin in &mut bins {
279279
validate_bin_name(bin, warnings)?;
280-
validate_bin_crate_types(bin, warnings, errors)?;
281-
validate_bin_proc_macro(bin, warnings, errors)?;
280+
validate_bin_crate_types(bin, edition, warnings, errors)?;
281+
validate_bin_proc_macro(bin, edition, warnings, errors)?;
282282

283283
let path = target_path(bin, &inferred, "bin", package_root, edition, &mut |_| {
284284
if let Some(legacy_path) = legacy_bin_path(package_root, name_or_panic(bin), has_lib) {
@@ -1057,7 +1057,8 @@ fn validate_target_name(
10571057

10581058
fn validate_bin_proc_macro(
10591059
target: &TomlTarget,
1060-
_warnings: &mut Vec<String>,
1060+
edition: Edition,
1061+
warnings: &mut Vec<String>,
10611062
errors: &mut Vec<String>,
10621063
) -> CargoResult<()> {
10631064
if target.proc_macro() == Some(true) {
@@ -1067,6 +1068,8 @@ fn validate_bin_proc_macro(
10671068
set `true`",
10681069
name
10691070
));
1071+
} else {
1072+
validate_proc_macro(target, "binary", edition, warnings)?;
10701073
}
10711074
Ok(())
10721075
}
@@ -1090,7 +1093,8 @@ fn validate_proc_macro(
10901093

10911094
fn validate_bin_crate_types(
10921095
target: &TomlTarget,
1093-
_warnings: &mut Vec<String>,
1096+
edition: Edition,
1097+
warnings: &mut Vec<String>,
10941098
errors: &mut Vec<String>,
10951099
) -> CargoResult<()> {
10961100
if let Some(crate_types) = target.crate_types() {
@@ -1102,6 +1106,8 @@ fn validate_bin_crate_types(
11021106
name,
11031107
crate_types.join(", ")
11041108
));
1109+
} else {
1110+
validate_crate_types(target, "binary", edition, warnings)?;
11051111
}
11061112
}
11071113
Ok(())

tests/testsuite/bad_config.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,8 @@ fn bin_crate_type2() {
11591159
p.cargo("check")
11601160
.with_stderr(
11611161
"\
1162+
[WARNING] `crate_type` is deprecated in favor of `crate-type` and will not work in the 2024 edition
1163+
(in the `foo` binary target)
11621164
[CHECKING] foo v0.5.0 ([CWD])
11631165
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s
11641166
",
@@ -1190,10 +1192,14 @@ fn bin_crate_type2_2024() {
11901192
.build();
11911193
p.cargo("check")
11921194
.masquerade_as_nightly_cargo(&["edition2024"])
1195+
.with_status(101)
11931196
.with_stderr(
11941197
"\
1195-
[CHECKING] foo v0.5.0 ([CWD])
1196-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s
1198+
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
1199+
1200+
Caused by:
1201+
`crate_type` is unsupported as of the 2024 edition; instead use `crate-type`
1202+
(in the `foo` binary target)
11971203
",
11981204
)
11991205
.run();
@@ -1223,6 +1229,7 @@ fn bin_crate_type2_conflict() {
12231229
p.cargo("check")
12241230
.with_stderr(
12251231
"\
1232+
[WARNING] `crate_type` is redundant with `crate-type`, preferring `crate-type` in the `foo` binary target
12261233
[CHECKING] foo v0.5.0 ([CWD])
12271234
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s
12281235
",
@@ -2057,6 +2064,8 @@ fn bin_proc_macro2() {
20572064
foo.cargo("check")
20582065
.with_stderr(
20592066
"\
2067+
[WARNING] `proc_macro` is deprecated in favor of `proc-macro` and will not work in the 2024 edition
2068+
(in the `foo` binary target)
20602069
[CHECKING] foo v0.5.0 ([CWD])
20612070
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s
20622071
",
@@ -2075,7 +2084,7 @@ fn bin_proc_macro2_2024() {
20752084
[package]
20762085
name = "foo"
20772086
version = "0.5.0"
2078-
edition = "2015"
2087+
edition = "2024"
20792088
authors = ["wycats@example.com"]
20802089
20812090
[[bin]]
@@ -2089,10 +2098,14 @@ fn bin_proc_macro2_2024() {
20892098

20902099
foo.cargo("check")
20912100
.masquerade_as_nightly_cargo(&["edition2024"])
2101+
.with_status(101)
20922102
.with_stderr(
20932103
"\
2094-
[CHECKING] foo v0.5.0 ([CWD])
2095-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s
2104+
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
2105+
2106+
Caused by:
2107+
`proc_macro` is unsupported as of the 2024 edition; instead use `proc-macro`
2108+
(in the `foo` binary target)
20962109
",
20972110
)
20982111
.run();
@@ -2123,6 +2136,7 @@ fn bin_proc_macro2_conflict() {
21232136
foo.cargo("check")
21242137
.with_stderr(
21252138
"\
2139+
[WARNING] `proc_macro` is redundant with `proc-macro`, preferring `proc-macro` in the `foo` binary target
21262140
[CHECKING] foo v0.5.0 ([CWD])
21272141
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s
21282142
",

0 commit comments

Comments
 (0)