From beff60ad31c68780ff0ccefe1154debc2749040d Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Mon, 30 Mar 2020 17:06:23 -0400 Subject: [PATCH] clippy --- src/atrule/function.rs | 7 +++---- src/atrule/mod.rs | 2 +- src/builtin/map.rs | 4 ++-- src/selector.rs | 4 ++-- src/style.rs | 2 +- src/utils.rs | 10 ++++------ src/value/map.rs | 6 +++--- src/value/mod.rs | 2 +- src/value/ops.rs | 2 +- src/value/parse.rs | 4 ++-- tests/map.rs | 6 ++---- 11 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/atrule/function.rs b/src/atrule/function.rs index 32f9fe0..1b1053e 100644 --- a/src/atrule/function.rs +++ b/src/atrule/function.rs @@ -69,19 +69,18 @@ impl Function { match stmt { Stmt::AtRule(AtRule::Return(toks)) => { return Value::from_tokens( - &mut toks.clone().into_iter().peekable(), + &mut toks.into_iter().peekable(), &self.scope, super_selector, ) } Stmt::AtRule(AtRule::For(..)) => todo!("@for in function"), Stmt::AtRule(AtRule::If(i)) => { - match self.call( + if let Ok(v) = self.call( super_selector, i.eval(&mut self.scope.clone(), super_selector)?, ) { - Ok(v) => return Ok(v), - Err(..) => {} + return Ok(v); } } _ => return Err("This at-rule is not allowed here.".into()), diff --git a/src/atrule/mod.rs b/src/atrule/mod.rs index c1e931b..787c626 100644 --- a/src/atrule/mod.rs +++ b/src/atrule/mod.rs @@ -132,7 +132,7 @@ impl AtRule { 'h' => { let r = toks.next().unwrap(); these_toks.push(r); - if &r.kind != &'r' { + if r.kind != 'r' { from_toks.extend(these_toks); continue; } diff --git a/src/builtin/map.rs b/src/builtin/map.rs index 575dd8c..b155436 100644 --- a/src/builtin/map.rs +++ b/src/builtin/map.rs @@ -15,7 +15,7 @@ pub(crate) fn register(f: &mut HashMap) { Value::List(v, ..) if v.is_empty() => SassMap::new(), v => return Err(format!("$map: {} is not a map.", v).into()), }; - Ok(map.get(key)?.unwrap_or(Value::Null).clone()) + Ok(map.get(&key)?.unwrap_or(Value::Null)) }), ); f.insert( @@ -28,7 +28,7 @@ pub(crate) fn register(f: &mut HashMap) { Value::List(v, ..) if v.is_empty() => SassMap::new(), v => return Err(format!("$map: {} is not a map.", v).into()), }; - Ok(Value::bool(map.get(key)?.is_some())) + Ok(Value::bool(map.get(&key)?.is_some())) }), ); f.insert( diff --git a/src/selector.rs b/src/selector.rs index 836915c..cf5fc41 100644 --- a/src/selector.rs +++ b/src/selector.rs @@ -201,7 +201,7 @@ impl<'a> SelectorParser<'a> { let s = format!( "{}{}", v, - eat_ident(tokens, &self.scope, &self.super_selector)? + eat_ident(tokens, self.scope, self.super_selector)? ); if let Some(Token { kind: '(', .. }) = tokens.peek() { tokens.next(); @@ -225,7 +225,7 @@ impl<'a> SelectorParser<'a> { } } ':' => { - let s = eat_ident(tokens, &self.scope, &self.super_selector)?; + let s = eat_ident(tokens, self.scope, self.super_selector)?; self.selectors.push(SelectorKind::PseudoElement(s)) } _ => return Err("Expected identifier.".into()), diff --git a/src/style.rs b/src/style.rs index 466905b..512f662 100644 --- a/src/style.rs +++ b/src/style.rs @@ -192,7 +192,7 @@ impl<'a> StyleParser<'a> { mut super_property: String, ) -> SassResult { devour_whitespace(toks); - let property = eat_ident(toks, &self.scope, &self.super_selector)?; + let property = eat_ident(toks, self.scope, self.super_selector)?; devour_whitespace_or_comment(toks)?; if toks.peek().is_some() && toks.peek().unwrap().kind == ':' { toks.next(); diff --git a/src/utils.rs b/src/utils.rs index 6497aac..dae27bd 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -515,7 +515,7 @@ pub(crate) fn eat_number>(toks: &mut Peekable) -> S /// /// The newline is consumed pub(crate) fn read_until_newline>(toks: &mut Peekable) { - while let Some(tok) = toks.next() { + for tok in toks { if tok.kind == '\n' { break; } @@ -534,11 +534,9 @@ pub(crate) fn eat_comment>( ) -> SassResult { let mut comment = String::new(); while let Some(tok) = toks.next() { - if tok.kind == '*' { - if toks.peek().unwrap().kind == '/' { - toks.next(); - break; - } + if tok.kind == '*' && toks.peek().unwrap().kind == '/' { + toks.next(); + break; } comment.push(tok.kind); } diff --git a/src/value/map.rs b/src/value/map.rs index 238214a..3614d67 100644 --- a/src/value/map.rs +++ b/src/value/map.rs @@ -8,11 +8,11 @@ use crate::error::SassResult; pub(crate) struct SassMap(Vec<(Value, Value)>); impl SassMap { - pub fn new() -> SassMap { + pub const fn new() -> SassMap { SassMap(Vec::new()) } - pub fn get(self, key: Value) -> SassResult> { + pub fn get(self, key: &Value) -> SassResult> { for (k, v) in self.0 { if k.equals(key.clone())? { return Ok(Some(v)); @@ -31,7 +31,7 @@ impl SassMap { } pub fn merge(&mut self, other: SassMap) { - for (key, value) in other.into_iter() { + for (key, value) in other { self.insert(key, value); } } diff --git a/src/value/mod.rs b/src/value/mod.rs index e31b513..59f19ff 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -228,7 +228,7 @@ impl Value { Ok(match self { Self::Dimension(num, ref unit) => match other { Self::Dimension(num2, unit2) => { - if !unit.comparable(&unit2) { + if !unit.comparable(unit2) { return Err(format!("Incompatible units {} and {}.", unit2, unit).into()); } if unit == unit2 { diff --git a/src/value/ops.rs b/src/value/ops.rs index 52b75ac..fbcccdd 100644 --- a/src/value/ops.rs +++ b/src/value/ops.rs @@ -170,7 +170,7 @@ impl Sub for Value { format!("{}-{}{}{}", self, q.normalize(), s, q.normalize()), QuoteKind::None, ), - Self::Paren(..) => (self + other.eval()?)?, + Self::Paren(..) => (self - other.eval()?)?, _ => Value::Ident(format!("{}-{}", self, other), QuoteKind::None), }, _ => match other { diff --git a/src/value/parse.rs b/src/value/parse.rs index cd17122..8c1e801 100644 --- a/src/value/parse.rs +++ b/src/value/parse.rs @@ -186,7 +186,7 @@ impl Value { let right = Self::from_tokens(toks, scope, super_selector)?; Ok(Value::BinaryOp(Box::new(left), Op::Equal, Box::new(right))) } else { - return Err("expected \"=\".".into()); + Err("expected \"=\".".into()) } } q @ '>' | q @ '<' => { @@ -231,7 +231,7 @@ impl Value { Brackets::None, )) } else { - return Err("Expected \"important\".".into()); + Err("Expected \"important\".".into()) } } '-' => { diff --git a/tests/map.rs b/tests/map.rs index a5b112a..a423ec7 100644 --- a/tests/map.rs +++ b/tests/map.rs @@ -113,11 +113,9 @@ test!( ); error!( map_get_one_arg, - "a {\n color: map-get(1);\n}\n", - "Error: Missing argument $key." + "a {\n color: map-get(1);\n}\n", "Error: Missing argument $key." ); error!( map_has_key_one_arg, - "a {\n color: map-has-key(1);\n}\n", - "Error: Missing argument $key." + "a {\n color: map-has-key(1);\n}\n", "Error: Missing argument $key." );