Skip to content

Commit 82ae7fd

Browse files
committed
refactor(gctx): inline GlobalContext::get_list_or_string
It is only used in one place.
1 parent 5c8f865 commit 82ae7fd

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

src/cargo/util/context/de.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,24 @@ impl<'de, 'gctx> de::Deserializer<'de> for Deserializer<'gctx> {
155155
V: de::Visitor<'de>,
156156
{
157157
if name == "StringList" {
158-
let vals = self.gctx.get_list_or_string(&self.key)?;
159-
let vals: Vec<String> = vals.into_iter().map(|vd| vd.0).collect();
158+
let mut res = Vec::new();
159+
160+
match self.gctx.get_cv(&self.key)? {
161+
Some(CV::List(val, _def)) => res.extend(val),
162+
Some(CV::String(val, def)) => {
163+
let split_vs = val.split_whitespace().map(|s| (s.to_string(), def.clone()));
164+
res.extend(split_vs);
165+
}
166+
Some(val) => {
167+
self.gctx
168+
.expected("string or array of strings", &self.key, &val)?;
169+
}
170+
None => {}
171+
}
172+
173+
self.gctx.get_env_list(&self.key, &mut res)?;
174+
175+
let vals: Vec<String> = res.into_iter().map(|vd| vd.0).collect();
160176
visitor.visit_newtype_struct(vals.into_deserializer())
161177
} else {
162178
visitor.visit_newtype_struct(self)

src/cargo/util/context/mod.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,27 +1006,6 @@ impl GlobalContext {
10061006
}
10071007
}
10081008

1009-
/// Helper for `StringList` type to get something that is a string or list.
1010-
fn get_list_or_string(&self, key: &ConfigKey) -> CargoResult<Vec<(String, Definition)>> {
1011-
let mut res = Vec::new();
1012-
1013-
match self.get_cv(key)? {
1014-
Some(CV::List(val, _def)) => res.extend(val),
1015-
Some(CV::String(val, def)) => {
1016-
let split_vs = val.split_whitespace().map(|s| (s.to_string(), def.clone()));
1017-
res.extend(split_vs);
1018-
}
1019-
Some(val) => {
1020-
return self.expected("string or array of strings", key, &val);
1021-
}
1022-
None => {}
1023-
}
1024-
1025-
self.get_env_list(key, &mut res)?;
1026-
1027-
Ok(res)
1028-
}
1029-
10301009
/// Internal method for getting an environment variable as a list.
10311010
/// If the key is a non-mergeable list and a value is found in the environment, existing values are cleared.
10321011
fn get_env_list(

0 commit comments

Comments
 (0)