From 20b2b8fd7672ed05ea394f789e83636ec6799f53 Mon Sep 17 00:00:00 2001 From: cetra3 Date: Thu, 24 Feb 2022 17:25:16 +1030 Subject: [PATCH] Fix clippy lints --- jmespath/build.rs | 2 +- jmespath/src/errors.rs | 2 +- jmespath/src/functions.rs | 12 ++++++------ jmespath/src/lexer.rs | 8 ++++---- jmespath/src/lib.rs | 4 ++-- jmespath/src/parser.rs | 10 +++++----- jmespath/src/variable.rs | 11 ++++------- 7 files changed, 23 insertions(+), 26 deletions(-) diff --git a/jmespath/build.rs b/jmespath/build.rs index 009f93fe..0e7b4754 100644 --- a/jmespath/build.rs +++ b/jmespath/build.rs @@ -121,7 +121,7 @@ fn generate_fn_name( let expr = get_expr(case); // Use the comment as the fn description if it is present. let description = match case.get("comment") { - Some(ref c) => c.as_str().expect("comment is not a string"), + Some(c) => c.as_str().expect("comment is not a string"), None => expr, }; format!( diff --git a/jmespath/src/errors.rs b/jmespath/src/errors.rs index 5fa5fd97..dfb211cf 100644 --- a/jmespath/src/errors.rs +++ b/jmespath/src/errors.rs @@ -68,7 +68,7 @@ impl From for JmespathError { fn inject_carat(column: usize, buff: &mut String) { buff.push_str(&(0..column).map(|_| ' ').collect::()); - buff.push_str(&"^\n"); + buff.push_str("^\n"); } impl fmt::Display for JmespathError { diff --git a/jmespath/src/functions.rs b/jmespath/src/functions.rs index ab257cf6..1eb64d48 100644 --- a/jmespath/src/functions.rs +++ b/jmespath/src/functions.rs @@ -282,7 +282,7 @@ macro_rules! min_and_max_by { expected: format!("expression->{}", entered_type), actual: mapped.get_type().to_string(), position: 1, - invocation: invocation, + invocation, }), )); } @@ -416,7 +416,7 @@ impl Function for ContainsFn { let haystack = &args[0]; let needle = &args[1]; match **haystack { - Variable::Array(ref a) => Ok(Rcvar::new(Variable::Bool(a.contains(&needle)))), + Variable::Array(ref a) => Ok(Rcvar::new(Variable::Bool(a.contains(needle)))), Variable::String(ref subj) => match needle.as_string() { None => Ok(Rcvar::new(Variable::Bool(false))), Some(s) => Ok(Rcvar::new(Variable::Bool(subj.contains(s)))), @@ -504,7 +504,7 @@ impl Function for JoinFn { }) }) .collect::, JmespathError>>()? - .join(&glue); + .join(glue); Ok(Rcvar::new(Variable::String(result))) } } @@ -567,7 +567,7 @@ impl Function for MapFn { })?; let mut results = vec![]; for value in values { - results.push(interpret(&value, &ast, ctx)?); + results.push(interpret(value, ast, ctx)?); } Ok(Rcvar::new(Variable::Array(results))) } @@ -728,7 +728,7 @@ impl Function for SortByFn { ) })?; let mut mapped: Vec<(Rcvar, Rcvar)> = vec![]; - let first_value = interpret(&vals[0], &ast, ctx)?; + let first_value = interpret(&vals[0], ast, ctx)?; let first_type = first_value.get_type(); if first_type != JmespathType::String && first_type != JmespathType::Number { let reason = ErrorReason::Runtime(RuntimeError::InvalidReturnType { @@ -741,7 +741,7 @@ impl Function for SortByFn { } mapped.push((vals[0].clone(), first_value)); for (invocation, v) in vals.iter().enumerate().skip(1) { - let mapped_value = interpret(v, &ast, ctx)?; + let mapped_value = interpret(v, ast, ctx)?; if mapped_value.get_type() != first_type { return Err(JmespathError::from_ctx( ctx, diff --git a/jmespath/src/lexer.rs b/jmespath/src/lexer.rs index 64999da6..27d029aa 100644 --- a/jmespath/src/lexer.rs +++ b/jmespath/src/lexer.rs @@ -193,10 +193,10 @@ impl<'a> Lexer<'a> { // Consume identifiers: ( ALPHA / "_" ) *( DIGIT / ALPHA / "_" ) #[inline] fn consume_identifier(&mut self, first_char: char) -> Token { - Identifier(self.consume_while(first_char.to_string(), |c| match c { - 'a'..='z' | '_' | 'A'..='Z' | '0'..='9' => true, - _ => false, - })) + Identifier(self.consume_while( + first_char.to_string(), + |c| matches!(c, 'a'..='z' | '_' | 'A'..='Z' | '0'..='9'), + )) } // Consumes numbers: *"-" "0" / ( %x31-39 *DIGIT ) diff --git a/jmespath/src/lib.rs b/jmespath/src/lib.rs index c10e19a8..f3533d66 100644 --- a/jmespath/src/lib.rs +++ b/jmespath/src/lib.rs @@ -178,12 +178,12 @@ pub trait ToJmespath { impl<'a, T: ser::Serialize> ToJmespath for T { #[cfg(not(feature = "specialized"))] fn to_jmespath(self) -> Result { - Ok(Variable::from_serializable(self).map(Rcvar::new)?) + Variable::from_serializable(self).map(Rcvar::new) } #[cfg(feature = "specialized")] default fn to_jmespath(self) -> Result { - Ok(Variable::from_serializable(self).map(|var| Rcvar::new(var))?) + Variable::from_serializable(self).map(|var| Rcvar::new(var)) } } diff --git a/jmespath/src/parser.rs b/jmespath/src/parser.rs index b5787322..88d0b745 100644 --- a/jmespath/src/parser.rs +++ b/jmespath/src/parser.rs @@ -88,7 +88,7 @@ impl<'a> Parser<'a> { actual_pos = p; } } - JmespathError::new(&self.expr, actual_pos, ErrorReason::Parse(buff)) + JmespathError::new(self.expr, actual_pos, ErrorReason::Parse(buff)) } /// Main parse function of the Pratt parser that parses while RBP < LBP @@ -339,12 +339,12 @@ impl<'a> Parser<'a> { if match self.peek(0) { &Token::Dot => true, &Token::Lbracket | &Token::Filter => false, - ref t if t.lbp() < PROJECTION_STOP => { + t if t.lbp() < PROJECTION_STOP => { return Ok(Ast::Identity { offset: self.offset, }); } - ref t => { + t => { return Err(self.err(t, "Expected '.', '[', or '[?'", true)); } } { @@ -404,7 +404,7 @@ impl<'a> Parser<'a> { pos += 1; match self.peek(0) { &Token::Number(_) | &Token::Colon | &Token::Rbracket => continue, - ref t => return Err(self.err(t, "Expected number, ':', or ']'", true)), + t => return Err(self.err(t, "Expected number, ':', or ']'", true)), }; } ref t => return Err(self.err(t, "Expected number, ':', or ']'", false)), @@ -417,7 +417,7 @@ impl<'a> Parser<'a> { offset: self.offset, idx: parts[0].ok_or_else(|| { JmespathError::new( - &self.expr, + self.expr, self.offset, ErrorReason::Parse( "Expected parts[0] to be Some; but found None".to_owned(), diff --git a/jmespath/src/variable.rs b/jmespath/src/variable.rs index ab5cebc0..8df87487 100644 --- a/jmespath/src/variable.rs +++ b/jmespath/src/variable.rs @@ -289,10 +289,7 @@ impl Variable { /// Returns true if the value is a Number. Returns false otherwise. pub fn is_number(&self) -> bool { - match self { - Variable::Number(_) => true, - _ => false, - } + matches!(self, Variable::Number(_)) } /// If the value is a number, return or cast it to a f64. @@ -1615,7 +1612,7 @@ mod tests { #[derive(serde_derive::Serialize)] struct Map { num: usize, - }; + } let map = Map { num: 231 }; @@ -1630,7 +1627,7 @@ mod tests { #[derive(serde_derive::Serialize)] struct Map { num: isize, - }; + } let map = Map { num: -2141 }; @@ -1645,7 +1642,7 @@ mod tests { #[derive(serde_derive::Serialize)] struct Map { num: f64, - }; + } let map = Map { num: 41.0 };