mirror of
https://github.com/rust-lang/cargo
synced 2024-09-13 21:11:44 +00:00
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
This commit is contained in:
parent
2c31fe33e8
commit
fe0819ee9e
|
@ -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<String>,
|
||||
edition: Edition,
|
||||
warnings: &mut Vec<String>,
|
||||
errors: &mut Vec<String>,
|
||||
) -> 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<String>,
|
||||
edition: Edition,
|
||||
warnings: &mut Vec<String>,
|
||||
errors: &mut Vec<String>,
|
||||
) -> 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(())
|
||||
|
|
|
@ -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
|
||||
",
|
||||
|
|
Loading…
Reference in a new issue