Skip to content

Commit f715156

Browse files
committed
refactor(toml): Pull bin crate-types validation out
1 parent d34d0a1 commit f715156

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/cargo/util/toml/targets.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub(super) fn to_targets(
6464
resolved_toml.bin.as_deref().unwrap_or_default(),
6565
package_root,
6666
edition,
67+
warnings,
6768
errors,
6869
)?);
6970

@@ -308,6 +309,7 @@ fn to_bin_targets(
308309
bins: &[TomlBinTarget],
309310
package_root: &Path,
310311
edition: Edition,
312+
warnings: &mut Vec<String>,
311313
errors: &mut Vec<String>,
312314
) -> CargoResult<Vec<Target>> {
313315
// This loop performs basic checks on each of the TomlTarget in `bins`.
@@ -318,17 +320,7 @@ fn to_bin_targets(
318320
features.require(Feature::different_binary_name())?;
319321
}
320322

321-
if let Some(crate_types) = bin.crate_types() {
322-
if !crate_types.is_empty() {
323-
let name = name_or_panic(bin);
324-
errors.push(format!(
325-
"the target `{}` is a binary and can't have any \
326-
crate-types set (currently \"{}\")",
327-
name,
328-
crate_types.join(", ")
329-
));
330-
}
331-
}
323+
validate_bin_crate_types(bin, warnings, errors)?;
332324

333325
if bin.proc_macro() == Some(true) {
334326
let name = name_or_panic(bin);
@@ -1093,6 +1085,25 @@ fn validate_proc_macro(
10931085
)
10941086
}
10951087

1088+
fn validate_bin_crate_types(
1089+
target: &TomlTarget,
1090+
_warnings: &mut Vec<String>,
1091+
errors: &mut Vec<String>,
1092+
) -> CargoResult<()> {
1093+
if let Some(crate_types) = target.crate_types() {
1094+
if !crate_types.is_empty() {
1095+
let name = name_or_panic(target);
1096+
errors.push(format!(
1097+
"the target `{}` is a binary and can't have any \
1098+
crate-types set (currently \"{}\")",
1099+
name,
1100+
crate_types.join(", ")
1101+
));
1102+
}
1103+
}
1104+
Ok(())
1105+
}
1106+
10961107
fn validate_crate_types(
10971108
target: &TomlTarget,
10981109
kind: &str,

0 commit comments

Comments
 (0)