Skip to content

Commit ccccff1

Browse files
committed
refactor(toml): Move target duplicate-field logic next to use
1 parent 0a6fe0a commit ccccff1

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2286,28 +2286,6 @@ impl schema::TomlTarget {
22862286
None => panic!("target name is required"),
22872287
}
22882288
}
2289-
2290-
fn validate_proc_macro(&self, warnings: &mut Vec<String>) {
2291-
if self.proc_macro_raw.is_some() && self.proc_macro_raw2.is_some() {
2292-
warn_on_deprecated(
2293-
"proc-macro",
2294-
self.name().as_str(),
2295-
"library target",
2296-
warnings,
2297-
);
2298-
}
2299-
}
2300-
2301-
fn validate_crate_types(&self, target_kind_human: &str, warnings: &mut Vec<String>) {
2302-
if self.crate_type.is_some() && self.crate_type2.is_some() {
2303-
warn_on_deprecated(
2304-
"crate-type",
2305-
self.name().as_str(),
2306-
format!("{target_kind_human} target").as_str(),
2307-
warnings,
2308-
);
2309-
}
2310-
}
23112289
}
23122290

23132291
impl schema::MaybeWorkspaceLints {

src/cargo/util/toml/targets.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::core::compiler::CrateType;
2323
use crate::core::{Edition, Feature, Features, Target};
2424
use crate::util::errors::CargoResult;
2525
use crate::util::restricted_names;
26+
use crate::util::toml::warn_on_deprecated;
2627

2728
use anyhow::Context as _;
2829

@@ -172,8 +173,8 @@ fn clean_lib(
172173
};
173174

174175
let Some(ref lib) = lib else { return Ok(None) };
175-
lib.validate_proc_macro(warnings);
176-
lib.validate_crate_types("library", warnings);
176+
validate_proc_macro(lib, "library", warnings);
177+
validate_crate_types(lib, "library", warnings);
177178

178179
validate_target_name(lib, "library", "lib", warnings)?;
179180

@@ -398,7 +399,7 @@ fn clean_examples(
398399

399400
let mut result = Vec::new();
400401
for (path, toml) in targets {
401-
toml.validate_crate_types("example", warnings);
402+
validate_crate_types(&toml, "example", warnings);
402403
let crate_types = match toml.crate_types() {
403404
Some(kinds) => kinds.iter().map(|s| s.into()).collect(),
404405
None => Vec::new(),
@@ -984,3 +985,25 @@ fn maybe_custom_build(build: &Option<StringOrBool>, package_root: &Path) -> Opti
984985
}
985986
}
986987
}
988+
989+
fn validate_proc_macro(target: &TomlTarget, kind: &str, warnings: &mut Vec<String>) {
990+
if target.proc_macro_raw.is_some() && target.proc_macro_raw2.is_some() {
991+
warn_on_deprecated(
992+
"proc-macro",
993+
target.name().as_str(),
994+
format!("{kind} target").as_str(),
995+
warnings,
996+
);
997+
}
998+
}
999+
1000+
fn validate_crate_types(target: &TomlTarget, kind: &str, warnings: &mut Vec<String>) {
1001+
if target.crate_type.is_some() && target.crate_type2.is_some() {
1002+
warn_on_deprecated(
1003+
"crate-type",
1004+
target.name().as_str(),
1005+
format!("{kind} target").as_str(),
1006+
warnings,
1007+
);
1008+
}
1009+
}

0 commit comments

Comments
 (0)