diff options
author | Melody Horn <melody@boringcactus.com> | 2024-11-10 16:02:48 -0700 |
---|---|---|
committer | Melody Horn <melody@boringcactus.com> | 2024-11-10 16:02:48 -0700 |
commit | 7029372c9fada6316852915765cc0d763be3c63c (patch) | |
tree | d649d79de0b83b84637d85595fd6de2cfa38f17c /src/makefile/functions.rs | |
parent | e9080b515d86b9f39e97d4c8e1a157dfa4ba86f3 (diff) | |
download | makers-7029372c9fada6316852915765cc0d763be3c63c.tar.gz makers-7029372c9fada6316852915765cc0d763be3c63c.zip |
clippy moment
Diffstat (limited to 'src/makefile/functions.rs')
-rw-r--r-- | src/makefile/functions.rs | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs index a78d582..5d5e222 100644 --- a/src/makefile/functions.rs +++ b/src/makefile/functions.rs @@ -10,6 +10,7 @@ use super::r#macro::{Macro, Set as MacroSet}; use super::token::TokenString; use super::ItemSource; +#[allow(clippy::cognitive_complexity)] pub fn expand_call( name: &str, args: &[TokenString], @@ -174,17 +175,14 @@ mod text { let from = macros.expand(from)?; let to = macros.expand(to)?; let text = macros.expand(text)?; - let words = text - .split_whitespace() - .map(|word| { - let pattern_match = r#match(&from, word)?.and_then(|x| x.get(1)); - Ok(if let Some(pm) = pattern_match { - to.replace('%', pm.as_str()) - } else { - word.to_owned() + let words = + text.split_whitespace() + .map(|word| { + let pattern_match = r#match(&from, word)?.and_then(|x| x.get(1)); + Ok(pattern_match + .map_or_else(|| word.to_owned(), |pm| to.replace('%', pm.as_str()))) }) - }) - .collect::<Result<Vec<_>>>()?; + .collect::<Result<Vec<_>>>()?; Ok(words.join(" ")) } @@ -273,7 +271,7 @@ mod text { pub fn firstword(macros: &MacroSet, words: &TokenString) -> Result<String> { let words = macros.expand(words)?; - Ok(words.split_whitespace().nth(0).unwrap_or("").to_owned()) + Ok(words.split_whitespace().next().unwrap_or("").to_owned()) } pub fn lastword(macros: &MacroSet, words: &TokenString) -> Result<String> { @@ -419,11 +417,7 @@ mod conditional { condition.trim_end(); let condition = macros.expand(&condition)?; if condition.is_empty() { - if let Some(if_false) = if_false { - macros.expand(if_false) - } else { - Ok(String::new()) - } + if_false.map_or_else(|| Ok(String::new()), |if_false| macros.expand(if_false)) } else { macros.expand(if_true) } |