From 780f32b8ae6e87fea9a817f8697245309332e465 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 25 Nov 2020 09:12:19 +1000 Subject: [PATCH] fix new Clippy lints --- rslib/src/search/parser.rs | 8 ++++---- rslib/src/template.rs | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/rslib/src/search/parser.rs b/rslib/src/search/parser.rs index 3fb20c3e7..9f8a2c5ca 100644 --- a/rslib/src/search/parser.rs +++ b/rslib/src/search/parser.rs @@ -414,16 +414,16 @@ fn parse_template(val: &str) -> ParseResult { } fn parse_single_field<'a>(key: &'a str, val: &'a str) -> ParseResult> { - Ok(if val.starts_with("re:") { + Ok(if let Some(stripped) = val.strip_prefix("re:") { SearchNode::SingleField { field: unescape(key)?, - text: unescape_quotes(&val[3..]), + text: unescape_quotes(stripped), is_re: true, } - } else if val.starts_with("r:") { + } else if let Some(stripped) = val.strip_prefix("r:") { SearchNode::SingleField { field: unescape(key)?, - text: unescape_raw(&val[2..]), + text: unescape_raw(stripped), is_re: false, } } else { diff --git a/rslib/src/template.rs b/rslib/src/template.rs index 34663d650..121386caf 100644 --- a/rslib/src/template.rs +++ b/rslib/src/template.rs @@ -90,12 +90,12 @@ fn classify_handle(s: &str) -> Token { if start.len() < 2 { return Token::Replacement(start); } - if start.starts_with('#') { - Token::OpenConditional(&start[1..].trim_start()) - } else if start.starts_with('/') { - Token::CloseConditional(&start[1..].trim_start()) - } else if start.starts_with('^') { - Token::OpenNegated(&start[1..].trim_start()) + if let Some(stripped) = start.strip_prefix('#') { + Token::OpenConditional(stripped.trim_start()) + } else if let Some(stripped) = start.strip_prefix('/') { + Token::CloseConditional(stripped.trim_start()) + } else if let Some(stripped) = start.strip_prefix('^') { + Token::OpenNegated(stripped.trim_start()) } else { Token::Replacement(start) } @@ -116,9 +116,9 @@ fn legacy_text_token(s: &str) -> nom::IResult<&str, Token> { // if we locate a starting normal or alternate handlebar, use // whichever one we found first let normal_result: nom::IResult<&str, &str> = take_until("{{")(s); - let (normal_remaining, normal_span) = normal_result.unwrap_or_else(|_e| ("", s)); + let (normal_remaining, normal_span) = normal_result.unwrap_or(("", s)); let alt_result: nom::IResult<&str, &str> = take_until("<%")(s); - let (alt_remaining, alt_span) = alt_result.unwrap_or_else(|_e| ("", s)); + let (alt_remaining, alt_span) = alt_result.unwrap_or(("", s)); match (normal_span.len(), alt_span.len()) { (0, 0) => { // neither handlebar kind found