nightly clippy

This commit is contained in:
Connor Skees 2021-07-04 01:24:08 -04:00
parent a555352713
commit 8ea601ee43
16 changed files with 100 additions and 94 deletions

View File

@ -25,7 +25,7 @@ pub(crate) fn map_get(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult
.into()) .into())
} }
}; };
Ok(map.get(&key)?.unwrap_or(Value::Null)) Ok(map.get(&key).unwrap_or(Value::Null))
} }
pub(crate) fn map_has_key(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> { pub(crate) fn map_has_key(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
@ -43,7 +43,7 @@ pub(crate) fn map_has_key(mut args: CallArgs, parser: &mut Parser<'_>) -> SassRe
.into()) .into())
} }
}; };
Ok(Value::bool(map.get(&key)?.is_some())) Ok(Value::bool(map.get(&key).is_some()))
} }
pub(crate) fn map_keys(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> { pub(crate) fn map_keys(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {

View File

@ -206,7 +206,7 @@ fn main() -> std::io::Result<()> {
buf_out.write_all( buf_out.write_all(
if let Some(name) = matches.value_of("INPUT") { if let Some(name) = matches.value_of("INPUT") {
from_path(name, &options) from_path(name, options)
} else if matches.is_present("STDIN") { } else if matches.is_present("STDIN") {
from_string( from_string(
{ {

View File

@ -232,7 +232,7 @@ impl<'a> Parser<'a> {
let pos = *pos; let pos = *pos;
self.toks.next(); self.toks.next();
if let Some(Token { kind: '.', pos }) = self.toks.peek().cloned() { if let Some(Token { kind: '.', pos }) = self.toks.peek().copied() {
if !name.is_empty() { if !name.is_empty() {
return Err(("expected \")\".", pos).into()); return Err(("expected \")\".", pos).into());
} }

View File

@ -60,7 +60,7 @@ impl<'a> Parser<'a> {
loop { loop {
self.whitespace_or_comment(); self.whitespace_or_comment();
if let Some(Token { kind: '@', pos }) = self.toks.peek().cloned() { if let Some(Token { kind: '@', pos }) = self.toks.peek().copied() {
self.toks.peek_forward(1); self.toks.peek_forward(1);
let ident = peek_ident_no_interpolation(self.toks, false, pos)?; let ident = peek_ident_no_interpolation(self.toks, false, pos)?;
if ident.as_str() != "else" { if ident.as_str() != "else" {
@ -72,7 +72,7 @@ impl<'a> Parser<'a> {
break; break;
} }
self.whitespace_or_comment(); self.whitespace_or_comment();
if let Some(tok) = self.toks.peek().cloned() { if let Some(tok) = self.toks.peek().copied() {
match tok.kind { match tok.kind {
'i' if matches!( 'i' if matches!(
self.toks.peek_forward(1), self.toks.peek_forward(1),
@ -195,9 +195,9 @@ impl<'a> Parser<'a> {
Some(..) | None => false, Some(..) | None => false,
})?; })?;
let through = if self.scan_identifier("through")? { let through = if self.scan_identifier("through") {
1 1
} else if self.scan_identifier("to")? { } else if self.scan_identifier("to") {
0 0
} else { } else {
return Err(("Expected \"to\" or \"through\".", self.span_before).into()); return Err(("Expected \"to\" or \"through\".", self.span_before).into());

View File

@ -59,7 +59,7 @@ impl<'a> Parser<'a> {
buf.push_str(&self.escape(false)?); buf.push_str(&self.escape(false)?);
} }
'#' => { '#' => {
if let Some(Token { kind: '{', .. }) = self.toks.peek_forward(1).cloned() { if let Some(Token { kind: '{', .. }) = self.toks.peek_forward(1).copied() {
self.toks.next(); self.toks.next();
self.toks.next(); self.toks.next();
// TODO: if ident, interpolate literally // TODO: if ident, interpolate literally
@ -136,7 +136,7 @@ impl<'a> Parser<'a> {
let Token { kind, pos } = self let Token { kind, pos } = self
.toks .toks
.peek() .peek()
.cloned() .copied()
.ok_or(("Expected identifier.", self.span_before))?; .ok_or(("Expected identifier.", self.span_before))?;
let mut text = String::new(); let mut text = String::new();
if kind == '-' { if kind == '-' {

View File

@ -34,7 +34,7 @@ impl<'a, 'b> KeyframesSelectorParser<'a, 'b> {
fn parse_keyframes_selector(&mut self) -> SassResult<Vec<KeyframesSelector>> { fn parse_keyframes_selector(&mut self) -> SassResult<Vec<KeyframesSelector>> {
let mut selectors = Vec::new(); let mut selectors = Vec::new();
self.parser.whitespace_or_comment(); self.parser.whitespace_or_comment();
while let Some(tok) = self.parser.toks.peek().cloned() { while let Some(tok) = self.parser.toks.peek().copied() {
match tok.kind { match tok.kind {
't' | 'T' => { 't' | 'T' => {
let mut ident = self.parser.parse_identifier()?; let mut ident = self.parser.parse_identifier()?;
@ -128,7 +128,7 @@ impl<'a> Parser<'a> {
span = span.merge(tok.pos()); span = span.merge(tok.pos());
match tok.kind { match tok.kind {
'#' => { '#' => {
if let Some(Token { kind: '{', .. }) = self.toks.peek().cloned() { if let Some(Token { kind: '{', .. }) = self.toks.peek().copied() {
self.toks.next(); self.toks.next();
string.push_str(&self.parse_interpolation()?.to_css_string(span)?); string.push_str(&self.parse_interpolation()?.to_css_string(span)?);
} else { } else {
@ -154,6 +154,8 @@ impl<'a> Parser<'a> {
string.push(' '); string.push(' ');
} }
'{' => { '{' => {
// we must collect here because the parser is not generic over iterator
#[allow(clippy::needless_collect)]
let sel_toks: Vec<Token> = let sel_toks: Vec<Token> =
string.chars().map(|x| Token::new(span, x)).collect(); string.chars().map(|x| Token::new(span, x)).collect();

View File

@ -11,20 +11,24 @@ impl<'a> Parser<'a> {
/// consume the identifier /// consume the identifier
/// ///
/// This method is case insensitive /// This method is case insensitive
pub fn scan_identifier(&mut self, ident: &'static str) -> SassResult<bool> { pub fn scan_identifier(&mut self, ident: &'static str) -> bool {
let mut peeked_identifier = let mut peeked_identifier =
match peek_ident_no_interpolation(self.toks, false, self.span_before) { match peek_ident_no_interpolation(self.toks, false, self.span_before) {
Ok(v) => v.node, Ok(v) => v.node,
Err(..) => return Ok(false), Err(..) => return false,
}; };
peeked_identifier.make_ascii_lowercase(); peeked_identifier.make_ascii_lowercase();
if peeked_identifier == ident { if peeked_identifier == ident {
self.toks.truncate_iterator_to_cursor(); self.toks.truncate_iterator_to_cursor();
self.toks.next(); self.toks.next();
return Ok(true); return true;
} }
self.toks.reset_cursor(); self.toks.reset_cursor();
Ok(false)
false
} }
pub fn expression_until_comparison(&mut self) -> SassResult<Cow<'static, str>> { pub fn expression_until_comparison(&mut self) -> SassResult<Cow<'static, str>> {
@ -94,7 +98,7 @@ impl<'a> Parser<'a> {
return Ok(buf); return Ok(buf);
} }
let next_tok = self.toks.peek().cloned(); let next_tok = self.toks.peek().copied();
let is_angle = next_tok.map_or(false, |t| t.kind == '<' || t.kind == '>'); let is_angle = next_tok.map_or(false, |t| t.kind == '<' || t.kind == '>');
if is_angle || matches!(next_tok, Some(Token { kind: '=', .. })) { if is_angle || matches!(next_tok, Some(Token { kind: '=', .. })) {
buf.push(' '); buf.push(' ');
@ -140,7 +144,7 @@ impl<'a> Parser<'a> {
} else { } else {
buf.push_str(&ident); buf.push_str(&ident);
if self.scan_identifier("and")? { if self.scan_identifier("and") {
self.whitespace_or_comment(); self.whitespace_or_comment();
buf.push_str(" and "); buf.push_str(" and ");
} else { } else {
@ -153,7 +157,7 @@ impl<'a> Parser<'a> {
self.whitespace_or_comment(); self.whitespace_or_comment();
buf.push_str(&self.parse_media_feature()?); buf.push_str(&self.parse_media_feature()?);
self.whitespace_or_comment(); self.whitespace_or_comment();
if !self.scan_identifier("and")? { if !self.scan_identifier("and") {
break; break;
} }
buf.push_str(" and "); buf.push_str(" and ");

View File

@ -403,7 +403,7 @@ impl<'a> Parser<'a> {
span = span.merge(pos); span = span.merge(pos);
match kind { match kind {
'#' => { '#' => {
if let Some(Token { kind: '{', .. }) = self.toks.peek().cloned() { if let Some(Token { kind: '{', .. }) = self.toks.peek().copied() {
self.toks.next(); self.toks.next();
string.push_str(&self.parse_interpolation()?.to_css_string(span)?); string.push_str(&self.parse_interpolation()?.to_css_string(span)?);
} else { } else {
@ -447,6 +447,8 @@ impl<'a> Parser<'a> {
return Err(("expected \"{\".", span).into()); return Err(("expected \"{\".", span).into());
} }
// we must collect here because the parser isn't generic over the iterator
#[allow(clippy::needless_collect)]
let sel_toks: Vec<Token> = string.chars().map(|x| Token::new(span, x)).collect(); let sel_toks: Vec<Token> = string.chars().map(|x| Token::new(span, x)).collect();
let mut iter = sel_toks.into_iter().peekmore(); let mut iter = sel_toks.into_iter().peekmore();
@ -565,7 +567,7 @@ impl<'a> Parser<'a> {
/// ///
/// The newline is consumed /// The newline is consumed
pub fn read_until_newline(&mut self) { pub fn read_until_newline(&mut self) {
while let Some(tok) = self.toks.next() { for tok in &mut self.toks {
if tok.kind == '\n' { if tok.kind == '\n' {
break; break;
} }
@ -585,6 +587,7 @@ impl<'a> Parser<'a> {
found_whitespace = true; found_whitespace = true;
self.toks.next(); self.toks.next();
self.toks.next(); self.toks.next();
#[allow(clippy::while_let_on_iterator)]
while let Some(tok) = self.toks.next() { while let Some(tok) = self.toks.next() {
if tok.kind == '*' { if tok.kind == '*' {
if let Some(Token { kind: '/', .. }) = self.toks.peek() { if let Some(Token { kind: '/', .. }) = self.toks.peek() {
@ -885,7 +888,7 @@ impl<'a> Parser<'a> {
match tok.kind { match tok.kind {
'{' => break, '{' => break,
'#' => { '#' => {
if let Some(Token { kind: '{', pos }) = self.toks.peek().cloned() { if let Some(Token { kind: '{', pos }) = self.toks.peek().copied() {
self.toks.next(); self.toks.next();
self.span_before = pos; self.span_before = pos;
let interpolation = self.parse_interpolation()?; let interpolation = self.parse_interpolation()?;

View File

@ -201,7 +201,7 @@ impl<'a> Parser<'a> {
) -> SassResult<Vec<Style>> { ) -> SassResult<Vec<Style>> {
let mut styles = Vec::new(); let mut styles = Vec::new();
self.whitespace(); self.whitespace();
while let Some(tok) = self.toks.peek().cloned() { while let Some(tok) = self.toks.peek().copied() {
match tok.kind { match tok.kind {
'{' => { '{' => {
self.toks.next(); self.toks.next();

View File

@ -6,7 +6,7 @@ use super::Parser;
impl<'a> Parser<'a> { impl<'a> Parser<'a> {
pub(super) fn throw_away_until_newline(&mut self) { pub(super) fn throw_away_until_newline(&mut self) {
while let Some(tok) = self.toks.next() { for tok in &mut self.toks {
if tok.kind == '\n' { if tok.kind == '\n' {
break; break;
} }

View File

@ -488,7 +488,7 @@ impl<'a> Parser<'a> {
Unit::from(u.node) Unit::from(u.node)
} }
'-' => { '-' => {
if let Some(Token { kind, .. }) = self.toks.peek_next().cloned() { if let Some(Token { kind, .. }) = self.toks.peek_next().copied() {
self.toks.reset_cursor(); self.toks.reset_cursor();
if matches!(kind, 'a'..='z' | 'A'..='Z' | '_' | '\\' | '\u{7f}'..=std::char::MAX) if matches!(kind, 'a'..='z' | 'A'..='Z' | '_' | '\\' | '\u{7f}'..=std::char::MAX)
{ {

View File

@ -141,7 +141,7 @@ impl Attribute {
}; };
parser.whitespace(); parser.whitespace();
let modifier = match parser.toks.peek().cloned() { let modifier = match parser.toks.peek().copied() {
Some(Token { Some(Token {
kind: c @ 'a'..='z', kind: c @ 'a'..='z',
.. ..

View File

@ -461,9 +461,7 @@ impl Extender {
// ] // ]
let mut first = self.mode != ExtendMode::Replace; let mut first = self.mode != ExtendMode::Replace;
let unified_paths: Vec<Option<Vec<ComplexSelector>>> = paths(options) let unified_paths = paths(options).into_iter().map(|path| {
.into_iter()
.map(|path| {
let complexes: Vec<Vec<ComplexSelectorComponent>> = if first { let complexes: Vec<Vec<ComplexSelectorComponent>> = if first {
// The first path is always the original selector. We can't just // The first path is always the original selector. We can't just
// return `compound` directly because pseudo selectors may be // return `compound` directly because pseudo selectors may be
@ -522,12 +520,11 @@ impl Extender {
components, components,
line_break, line_break,
}) })
.collect(), .collect::<Vec<ComplexSelector>>(),
) )
}) });
.collect();
Some(unified_paths.into_iter().flatten().flatten().collect()) Some(unified_paths.flatten().flatten().collect())
} }
fn extend_simple( fn extend_simple(

View File

@ -477,7 +477,7 @@ impl Pseudo {
/// ///
/// This assumes that `pseudo1`'s `selector` argument is not `None`. /// This assumes that `pseudo1`'s `selector` argument is not `None`.
/// ///
/// If `parents is passed, it represents the parents of `compound`. This is /// If `parents` is passed, it represents the parents of `compound`. This is
/// relevant for pseudo selectors with selector arguments, where we may need to /// relevant for pseudo selectors with selector arguments, where we may need to
/// know if the parent selectors in the selector argument match `parents`. /// know if the parent selectors in the selector argument match `parents`.
pub fn is_super_selector( pub fn is_super_selector(

View File

@ -13,7 +13,7 @@ pub(crate) fn peek_until_closing_curly_brace(
) -> SassResult<Vec<Token>> { ) -> SassResult<Vec<Token>> {
let mut t = Vec::new(); let mut t = Vec::new();
let mut nesting = 0; let mut nesting = 0;
while let Some(tok) = toks.peek().cloned() { while let Some(tok) = toks.peek().copied() {
match tok.kind { match tok.kind {
q @ '"' | q @ '\'' => { q @ '"' | q @ '\'' => {
t.push(tok); t.push(tok);
@ -59,7 +59,7 @@ fn peek_until_closing_quote(
q: char, q: char,
) -> SassResult<Vec<Token>> { ) -> SassResult<Vec<Token>> {
let mut t = Vec::new(); let mut t = Vec::new();
while let Some(tok) = toks.peek().cloned() { while let Some(tok) = toks.peek().copied() {
match tok.kind { match tok.kind {
'"' if q == '"' => { '"' if q == '"' => {
t.push(tok); t.push(tok);

View File

@ -2,7 +2,6 @@ use std::{slice::Iter, vec::IntoIter};
use crate::{ use crate::{
common::{Brackets, ListSeparator}, common::{Brackets, ListSeparator},
error::SassResult,
value::Value, value::Value,
}; };
@ -42,13 +41,14 @@ impl SassMap {
/// save a clone of the value, since the only place this /// save a clone of the value, since the only place this
/// should be called is in a builtin function, which throws /// should be called is in a builtin function, which throws
/// away the map immediately anyway /// away the map immediately anyway
pub fn get(self, key: &Value) -> SassResult<Option<Value>> { pub fn get(self, key: &Value) -> Option<Value> {
for (k, v) in self.0 { for (k, v) in self.0 {
if &k == key { if &k == key {
return Ok(Some(v)); return Some(v);
} }
} }
Ok(None)
None
} }
pub fn get_mut(&mut self, key: &Value) -> Option<&mut Value> { pub fn get_mut(&mut self, key: &Value) -> Option<&mut Value> {