nightly clippy
This commit is contained in:
parent
a555352713
commit
8ea601ee43
@ -25,7 +25,7 @@ pub(crate) fn map_get(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult
|
||||
.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> {
|
||||
@ -43,7 +43,7 @@ pub(crate) fn map_has_key(mut args: CallArgs, parser: &mut Parser<'_>) -> SassRe
|
||||
.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> {
|
||||
|
@ -206,7 +206,7 @@ fn main() -> std::io::Result<()> {
|
||||
|
||||
buf_out.write_all(
|
||||
if let Some(name) = matches.value_of("INPUT") {
|
||||
from_path(name, &options)
|
||||
from_path(name, options)
|
||||
} else if matches.is_present("STDIN") {
|
||||
from_string(
|
||||
{
|
||||
|
@ -232,7 +232,7 @@ impl<'a> Parser<'a> {
|
||||
let pos = *pos;
|
||||
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() {
|
||||
return Err(("expected \")\".", pos).into());
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
loop {
|
||||
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);
|
||||
let ident = peek_ident_no_interpolation(self.toks, false, pos)?;
|
||||
if ident.as_str() != "else" {
|
||||
@ -72,7 +72,7 @@ impl<'a> Parser<'a> {
|
||||
break;
|
||||
}
|
||||
self.whitespace_or_comment();
|
||||
if let Some(tok) = self.toks.peek().cloned() {
|
||||
if let Some(tok) = self.toks.peek().copied() {
|
||||
match tok.kind {
|
||||
'i' if matches!(
|
||||
self.toks.peek_forward(1),
|
||||
@ -195,9 +195,9 @@ impl<'a> Parser<'a> {
|
||||
Some(..) | None => false,
|
||||
})?;
|
||||
|
||||
let through = if self.scan_identifier("through")? {
|
||||
let through = if self.scan_identifier("through") {
|
||||
1
|
||||
} else if self.scan_identifier("to")? {
|
||||
} else if self.scan_identifier("to") {
|
||||
0
|
||||
} else {
|
||||
return Err(("Expected \"to\" or \"through\".", self.span_before).into());
|
||||
|
@ -59,7 +59,7 @@ impl<'a> Parser<'a> {
|
||||
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();
|
||||
// TODO: if ident, interpolate literally
|
||||
@ -136,7 +136,7 @@ impl<'a> Parser<'a> {
|
||||
let Token { kind, pos } = self
|
||||
.toks
|
||||
.peek()
|
||||
.cloned()
|
||||
.copied()
|
||||
.ok_or(("Expected identifier.", self.span_before))?;
|
||||
let mut text = String::new();
|
||||
if kind == '-' {
|
||||
|
@ -34,7 +34,7 @@ impl<'a, 'b> KeyframesSelectorParser<'a, 'b> {
|
||||
fn parse_keyframes_selector(&mut self) -> SassResult<Vec<KeyframesSelector>> {
|
||||
let mut selectors = Vec::new();
|
||||
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 {
|
||||
't' | 'T' => {
|
||||
let mut ident = self.parser.parse_identifier()?;
|
||||
@ -128,7 +128,7 @@ impl<'a> Parser<'a> {
|
||||
span = span.merge(tok.pos());
|
||||
match tok.kind {
|
||||
'#' => {
|
||||
if let Some(Token { kind: '{', .. }) = self.toks.peek().cloned() {
|
||||
if let Some(Token { kind: '{', .. }) = self.toks.peek().copied() {
|
||||
self.toks.next();
|
||||
string.push_str(&self.parse_interpolation()?.to_css_string(span)?);
|
||||
} else {
|
||||
@ -154,6 +154,8 @@ impl<'a> Parser<'a> {
|
||||
string.push(' ');
|
||||
}
|
||||
'{' => {
|
||||
// we must collect here because the parser is not generic over iterator
|
||||
#[allow(clippy::needless_collect)]
|
||||
let sel_toks: Vec<Token> =
|
||||
string.chars().map(|x| Token::new(span, x)).collect();
|
||||
|
||||
|
@ -11,20 +11,24 @@ impl<'a> Parser<'a> {
|
||||
/// consume the identifier
|
||||
///
|
||||
/// 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 =
|
||||
match peek_ident_no_interpolation(self.toks, false, self.span_before) {
|
||||
Ok(v) => v.node,
|
||||
Err(..) => return Ok(false),
|
||||
Err(..) => return false,
|
||||
};
|
||||
|
||||
peeked_identifier.make_ascii_lowercase();
|
||||
|
||||
if peeked_identifier == ident {
|
||||
self.toks.truncate_iterator_to_cursor();
|
||||
self.toks.next();
|
||||
return Ok(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
self.toks.reset_cursor();
|
||||
Ok(false)
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
pub fn expression_until_comparison(&mut self) -> SassResult<Cow<'static, str>> {
|
||||
@ -94,7 +98,7 @@ impl<'a> Parser<'a> {
|
||||
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 == '>');
|
||||
if is_angle || matches!(next_tok, Some(Token { kind: '=', .. })) {
|
||||
buf.push(' ');
|
||||
@ -140,7 +144,7 @@ impl<'a> Parser<'a> {
|
||||
} else {
|
||||
buf.push_str(&ident);
|
||||
|
||||
if self.scan_identifier("and")? {
|
||||
if self.scan_identifier("and") {
|
||||
self.whitespace_or_comment();
|
||||
buf.push_str(" and ");
|
||||
} else {
|
||||
@ -153,7 +157,7 @@ impl<'a> Parser<'a> {
|
||||
self.whitespace_or_comment();
|
||||
buf.push_str(&self.parse_media_feature()?);
|
||||
self.whitespace_or_comment();
|
||||
if !self.scan_identifier("and")? {
|
||||
if !self.scan_identifier("and") {
|
||||
break;
|
||||
}
|
||||
buf.push_str(" and ");
|
||||
|
@ -403,7 +403,7 @@ impl<'a> Parser<'a> {
|
||||
span = span.merge(pos);
|
||||
match kind {
|
||||
'#' => {
|
||||
if let Some(Token { kind: '{', .. }) = self.toks.peek().cloned() {
|
||||
if let Some(Token { kind: '{', .. }) = self.toks.peek().copied() {
|
||||
self.toks.next();
|
||||
string.push_str(&self.parse_interpolation()?.to_css_string(span)?);
|
||||
} else {
|
||||
@ -447,6 +447,8 @@ impl<'a> Parser<'a> {
|
||||
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 mut iter = sel_toks.into_iter().peekmore();
|
||||
@ -565,7 +567,7 @@ impl<'a> Parser<'a> {
|
||||
///
|
||||
/// The newline is consumed
|
||||
pub fn read_until_newline(&mut self) {
|
||||
while let Some(tok) = self.toks.next() {
|
||||
for tok in &mut self.toks {
|
||||
if tok.kind == '\n' {
|
||||
break;
|
||||
}
|
||||
@ -585,6 +587,7 @@ impl<'a> Parser<'a> {
|
||||
found_whitespace = true;
|
||||
self.toks.next();
|
||||
self.toks.next();
|
||||
#[allow(clippy::while_let_on_iterator)]
|
||||
while let Some(tok) = self.toks.next() {
|
||||
if tok.kind == '*' {
|
||||
if let Some(Token { kind: '/', .. }) = self.toks.peek() {
|
||||
@ -885,7 +888,7 @@ impl<'a> Parser<'a> {
|
||||
match tok.kind {
|
||||
'{' => 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.span_before = pos;
|
||||
let interpolation = self.parse_interpolation()?;
|
||||
|
@ -201,7 +201,7 @@ impl<'a> Parser<'a> {
|
||||
) -> SassResult<Vec<Style>> {
|
||||
let mut styles = Vec::new();
|
||||
self.whitespace();
|
||||
while let Some(tok) = self.toks.peek().cloned() {
|
||||
while let Some(tok) = self.toks.peek().copied() {
|
||||
match tok.kind {
|
||||
'{' => {
|
||||
self.toks.next();
|
||||
|
@ -6,7 +6,7 @@ use super::Parser;
|
||||
|
||||
impl<'a> Parser<'a> {
|
||||
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' {
|
||||
break;
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ impl<'a> Parser<'a> {
|
||||
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();
|
||||
if matches!(kind, 'a'..='z' | 'A'..='Z' | '_' | '\\' | '\u{7f}'..=std::char::MAX)
|
||||
{
|
||||
|
@ -141,7 +141,7 @@ impl Attribute {
|
||||
};
|
||||
parser.whitespace();
|
||||
|
||||
let modifier = match parser.toks.peek().cloned() {
|
||||
let modifier = match parser.toks.peek().copied() {
|
||||
Some(Token {
|
||||
kind: c @ 'a'..='z',
|
||||
..
|
||||
|
@ -461,73 +461,70 @@ impl Extender {
|
||||
// ]
|
||||
let mut first = self.mode != ExtendMode::Replace;
|
||||
|
||||
let unified_paths: Vec<Option<Vec<ComplexSelector>>> = paths(options)
|
||||
.into_iter()
|
||||
.map(|path| {
|
||||
let complexes: Vec<Vec<ComplexSelectorComponent>> = if first {
|
||||
// The first path is always the original selector. We can't just
|
||||
// return `compound` directly because pseudo selectors may be
|
||||
// modified, but we don't have to do any unification.
|
||||
first = false;
|
||||
let unified_paths = paths(options).into_iter().map(|path| {
|
||||
let complexes: Vec<Vec<ComplexSelectorComponent>> = if first {
|
||||
// The first path is always the original selector. We can't just
|
||||
// return `compound` directly because pseudo selectors may be
|
||||
// modified, but we don't have to do any unification.
|
||||
first = false;
|
||||
|
||||
vec![vec![ComplexSelectorComponent::Compound(CompoundSelector {
|
||||
components: path
|
||||
.clone()
|
||||
.into_iter()
|
||||
.flat_map(|state| {
|
||||
debug_assert!(state.extender.components.len() == 1);
|
||||
match state.extender.components.last().cloned() {
|
||||
Some(ComplexSelectorComponent::Compound(c)) => c.components,
|
||||
Some(..) | None => unreachable!(),
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
})]]
|
||||
} else {
|
||||
let mut to_unify: VecDeque<Vec<ComplexSelectorComponent>> = VecDeque::new();
|
||||
let mut originals: Vec<SimpleSelector> = Vec::new();
|
||||
|
||||
for state in path.clone() {
|
||||
if state.is_original {
|
||||
originals.extend(match state.extender.components.last().cloned() {
|
||||
vec![vec![ComplexSelectorComponent::Compound(CompoundSelector {
|
||||
components: path
|
||||
.clone()
|
||||
.into_iter()
|
||||
.flat_map(|state| {
|
||||
debug_assert!(state.extender.components.len() == 1);
|
||||
match state.extender.components.last().cloned() {
|
||||
Some(ComplexSelectorComponent::Compound(c)) => c.components,
|
||||
Some(..) | None => unreachable!(),
|
||||
});
|
||||
} else {
|
||||
to_unify.push_back(state.extender.components.clone());
|
||||
}
|
||||
}
|
||||
if !originals.is_empty() {
|
||||
to_unify.push_front(vec![ComplexSelectorComponent::Compound(
|
||||
CompoundSelector {
|
||||
components: originals,
|
||||
},
|
||||
)]);
|
||||
}
|
||||
|
||||
unify_complex(Vec::from(to_unify))?
|
||||
};
|
||||
|
||||
let mut line_break = false;
|
||||
|
||||
for state in path {
|
||||
state.assert_compatible_media_context(media_query_context);
|
||||
line_break = line_break || state.extender.line_break;
|
||||
}
|
||||
|
||||
Some(
|
||||
complexes
|
||||
.into_iter()
|
||||
.map(|components| ComplexSelector {
|
||||
components,
|
||||
line_break,
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
})]]
|
||||
} else {
|
||||
let mut to_unify: VecDeque<Vec<ComplexSelectorComponent>> = VecDeque::new();
|
||||
let mut originals: Vec<SimpleSelector> = Vec::new();
|
||||
|
||||
Some(unified_paths.into_iter().flatten().flatten().collect())
|
||||
for state in path.clone() {
|
||||
if state.is_original {
|
||||
originals.extend(match state.extender.components.last().cloned() {
|
||||
Some(ComplexSelectorComponent::Compound(c)) => c.components,
|
||||
Some(..) | None => unreachable!(),
|
||||
});
|
||||
} else {
|
||||
to_unify.push_back(state.extender.components.clone());
|
||||
}
|
||||
}
|
||||
if !originals.is_empty() {
|
||||
to_unify.push_front(vec![ComplexSelectorComponent::Compound(
|
||||
CompoundSelector {
|
||||
components: originals,
|
||||
},
|
||||
)]);
|
||||
}
|
||||
|
||||
unify_complex(Vec::from(to_unify))?
|
||||
};
|
||||
|
||||
let mut line_break = false;
|
||||
|
||||
for state in path {
|
||||
state.assert_compatible_media_context(media_query_context);
|
||||
line_break = line_break || state.extender.line_break;
|
||||
}
|
||||
|
||||
Some(
|
||||
complexes
|
||||
.into_iter()
|
||||
.map(|components| ComplexSelector {
|
||||
components,
|
||||
line_break,
|
||||
})
|
||||
.collect::<Vec<ComplexSelector>>(),
|
||||
)
|
||||
});
|
||||
|
||||
Some(unified_paths.flatten().flatten().collect())
|
||||
}
|
||||
|
||||
fn extend_simple(
|
||||
|
@ -477,7 +477,7 @@ impl Pseudo {
|
||||
///
|
||||
/// 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
|
||||
/// know if the parent selectors in the selector argument match `parents`.
|
||||
pub fn is_super_selector(
|
||||
|
@ -13,7 +13,7 @@ pub(crate) fn peek_until_closing_curly_brace(
|
||||
) -> SassResult<Vec<Token>> {
|
||||
let mut t = Vec::new();
|
||||
let mut nesting = 0;
|
||||
while let Some(tok) = toks.peek().cloned() {
|
||||
while let Some(tok) = toks.peek().copied() {
|
||||
match tok.kind {
|
||||
q @ '"' | q @ '\'' => {
|
||||
t.push(tok);
|
||||
@ -59,7 +59,7 @@ fn peek_until_closing_quote(
|
||||
q: char,
|
||||
) -> SassResult<Vec<Token>> {
|
||||
let mut t = Vec::new();
|
||||
while let Some(tok) = toks.peek().cloned() {
|
||||
while let Some(tok) = toks.peek().copied() {
|
||||
match tok.kind {
|
||||
'"' if q == '"' => {
|
||||
t.push(tok);
|
||||
|
@ -2,7 +2,6 @@ use std::{slice::Iter, vec::IntoIter};
|
||||
|
||||
use crate::{
|
||||
common::{Brackets, ListSeparator},
|
||||
error::SassResult,
|
||||
value::Value,
|
||||
};
|
||||
|
||||
@ -42,13 +41,14 @@ impl SassMap {
|
||||
/// save a clone of the value, since the only place this
|
||||
/// should be called is in a builtin function, which throws
|
||||
/// 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 {
|
||||
if &k == key {
|
||||
return Ok(Some(v));
|
||||
return Some(v);
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, key: &Value) -> Option<&mut Value> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user