Skip to content

Commit 4b1ce53

Browse files
committed
refactor: Extract lints->rustflags function
1 parent bc4a3b6 commit 4b1ce53

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/cargo/util/toml/mod.rs

+26-27
Original file line numberDiff line numberDiff line change
@@ -2326,33 +2326,7 @@ impl TomlManifest {
23262326
.transpose()?;
23272327
let lints = verify_lints(lints)?;
23282328
let default = TomlLints::default();
2329-
let mut rustflags = lints
2330-
.as_ref()
2331-
.unwrap_or(&default)
2332-
.iter()
2333-
.flat_map(|(tool, lints)| {
2334-
lints.iter().map(move |(name, config)| {
2335-
let flag = config.level().flag();
2336-
let option = if tool == "rust" {
2337-
format!("{flag}={name}")
2338-
} else {
2339-
format!("{flag}={tool}::{name}")
2340-
};
2341-
(
2342-
config.priority(),
2343-
// Since the most common group will be `all`, put it last so people are more
2344-
// likely to notice that they need to use `priority`.
2345-
std::cmp::Reverse(name),
2346-
option,
2347-
)
2348-
})
2349-
})
2350-
.collect::<Vec<_>>();
2351-
rustflags.sort();
2352-
let rustflags = rustflags
2353-
.into_iter()
2354-
.map(|(_, _, option)| option)
2355-
.collect::<Vec<_>>();
2329+
let rustflags = lints_to_rustflags(lints.as_ref().unwrap_or(&default));
23562330

23572331
let mut target: BTreeMap<String, TomlPlatform> = BTreeMap::new();
23582332
for (name, platform) in me.target.iter().flatten() {
@@ -3009,6 +2983,31 @@ fn verify_lints(lints: Option<TomlLints>) -> CargoResult<Option<TomlLints>> {
30092983
Ok(Some(lints))
30102984
}
30112985

2986+
fn lints_to_rustflags(lints: &TomlLints) -> Vec<String> {
2987+
let mut rustflags = lints
2988+
.iter()
2989+
.flat_map(|(tool, lints)| {
2990+
lints.iter().map(move |(name, config)| {
2991+
let flag = config.level().flag();
2992+
let option = if tool == "rust" {
2993+
format!("{flag}={name}")
2994+
} else {
2995+
format!("{flag}={tool}::{name}")
2996+
};
2997+
(
2998+
config.priority(),
2999+
// Since the most common group will be `all`, put it last so people are more
3000+
// likely to notice that they need to use `priority`.
3001+
std::cmp::Reverse(name),
3002+
option,
3003+
)
3004+
})
3005+
})
3006+
.collect::<Vec<_>>();
3007+
rustflags.sort();
3008+
rustflags.into_iter().map(|(_, _, option)| option).collect()
3009+
}
3010+
30123011
fn unused_dep_keys(
30133012
dep_name: &str,
30143013
kind: &str,

0 commit comments

Comments
 (0)