clippy
This commit is contained in:
parent
4ee9cc72a6
commit
53861ccb0d
@ -163,7 +163,7 @@ pub(crate) fn eat_call_args<I: Iterator<Item = Token>>(
|
||||
TokenKind::Symbol(Symbol::CloseParen) => {
|
||||
args.insert(
|
||||
name,
|
||||
Value::from_tokens(&mut val.clone().into_iter().peekable(), scope)?,
|
||||
Value::from_tokens(&mut val.into_iter().peekable(), scope)?,
|
||||
);
|
||||
return Ok(CallArgs(args));
|
||||
}
|
||||
@ -192,7 +192,7 @@ pub(crate) fn eat_call_args<I: Iterator<Item = Token>>(
|
||||
fn read_until_close_paren<I: Iterator<Item = Token>>(toks: &mut Peekable<I>) -> Vec<Token> {
|
||||
let mut v = Vec::new();
|
||||
let mut scope = 0;
|
||||
while let Some(tok) = toks.next() {
|
||||
for tok in toks {
|
||||
match tok.kind {
|
||||
TokenKind::Symbol(Symbol::CloseParen) => {
|
||||
if scope <= 1 {
|
||||
|
@ -157,7 +157,7 @@ fn eat_unknown_atrule_body<I: Iterator<Item = Token>>(
|
||||
while let Some(expr) = eat_expr(toks, scope, super_selector)? {
|
||||
match expr {
|
||||
Expr::AtRule(a) => stmts.push(Stmt::AtRule(a)),
|
||||
Expr::Style(s) => stmts.push(Stmt::Style(s)),
|
||||
Expr::Style(s) => stmts.push(Stmt::Style(*s)),
|
||||
Expr::Styles(s) => stmts.extend(s.into_iter().map(Stmt::Style)),
|
||||
Expr::Include(s) => stmts.extend(s),
|
||||
Expr::MixinDecl(..) | Expr::FunctionDecl(..) | Expr::Debug(..) | Expr::Warn(..) => {
|
||||
|
@ -18,28 +18,28 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
max_args!(args, 1);
|
||||
match arg!(args, 0, "number") {
|
||||
Value::Dimension(n, u) => Ok(Value::Dimension(n.round(), u)),
|
||||
v => return Err(format!("$number: {} is not a number.", v).into()),
|
||||
v => Err(format!("$number: {} is not a number.", v).into()),
|
||||
}
|
||||
});
|
||||
decl!(f "ceil", |args, _| {
|
||||
max_args!(args, 1);
|
||||
match arg!(args, 0, "number") {
|
||||
Value::Dimension(n, u) => Ok(Value::Dimension(n.ceil(), u)),
|
||||
v => return Err(format!("$number: {} is not a number.", v).into()),
|
||||
v => Err(format!("$number: {} is not a number.", v).into()),
|
||||
}
|
||||
});
|
||||
decl!(f "floor", |args, _| {
|
||||
max_args!(args, 1);
|
||||
match arg!(args, 0, "number") {
|
||||
Value::Dimension(n, u) => Ok(Value::Dimension(n.floor(), u)),
|
||||
v => return Err(format!("$number: {} is not a number.", v).into()),
|
||||
v => Err(format!("$number: {} is not a number.", v).into()),
|
||||
}
|
||||
});
|
||||
decl!(f "abs", |args, _| {
|
||||
max_args!(args, 1);
|
||||
match arg!(args, 0, "number") {
|
||||
Value::Dimension(n, u) => Ok(Value::Dimension(n.abs(), u)),
|
||||
v => return Err(format!("$number: {} is not a number.", v).into()),
|
||||
v => Err(format!("$number: {} is not a number.", v).into()),
|
||||
}
|
||||
});
|
||||
decl!(f "comparable", |args, _| {
|
||||
|
@ -28,7 +28,7 @@ pub(crate) struct Color {
|
||||
}
|
||||
|
||||
impl Color {
|
||||
pub fn new_rgba(
|
||||
pub const fn new_rgba(
|
||||
red: Number,
|
||||
green: Number,
|
||||
blue: Number,
|
||||
|
10
src/lib.rs
10
src/lib.rs
@ -228,7 +228,7 @@ impl RuleSet {
|
||||
#[derive(Clone, Debug)]
|
||||
enum Expr {
|
||||
/// A style: `color: red`
|
||||
Style(Style),
|
||||
Style(Box<Style>),
|
||||
/// Several styles
|
||||
Styles(Vec<Style>),
|
||||
/// A collection of styles, from a mixin or function
|
||||
@ -486,7 +486,7 @@ impl<'a> StyleSheetParser<'a> {
|
||||
let mut stmts = Vec::new();
|
||||
while let Some(expr) = eat_expr(&mut self.lexer, scope, super_selector)? {
|
||||
match expr {
|
||||
Expr::Style(s) => stmts.push(Stmt::Style(s)),
|
||||
Expr::Style(s) => stmts.push(Stmt::Style(*s)),
|
||||
Expr::AtRule(s) => stmts.push(Stmt::AtRule(s)),
|
||||
Expr::Styles(s) => stmts.extend(s.into_iter().map(Stmt::Style)),
|
||||
Expr::MixinDecl(name, mixin) => {
|
||||
@ -556,7 +556,7 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
||||
let mut v = values.into_iter().peekable();
|
||||
let property = Style::parse_property(&mut v, scope, super_selector, String::new())?;
|
||||
let value = Style::parse_value(&mut v, scope, super_selector)?;
|
||||
return Ok(Some(Expr::Style(Style { property, value })));
|
||||
return Ok(Some(Expr::Style(Box::new(Style { property, value }))));
|
||||
}
|
||||
TokenKind::Symbol(Symbol::CloseCurlyBrace) => {
|
||||
if values.is_empty() {
|
||||
@ -571,7 +571,7 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
||||
let property =
|
||||
Style::parse_property(&mut v, scope, super_selector, String::new())?;
|
||||
let value = Style::parse_value(&mut v, scope, super_selector)?;
|
||||
return Ok(Some(Expr::Style(Style { property, value })));
|
||||
return Ok(Some(Expr::Style(Box::new(Style { property, value }))));
|
||||
}
|
||||
}
|
||||
TokenKind::Symbol(Symbol::OpenCurlyBrace) => {
|
||||
@ -634,7 +634,7 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
||||
pos,
|
||||
}) = toks.next()
|
||||
{
|
||||
return match AtRule::from_tokens(rule, pos, toks, scope, &super_selector)? {
|
||||
return match AtRule::from_tokens(rule, pos, toks, scope, super_selector)? {
|
||||
AtRule::Mixin(name, mixin) => Ok(Some(Expr::MixinDecl(name, mixin))),
|
||||
AtRule::Function(name, func) => Ok(Some(Expr::FunctionDecl(name, func))),
|
||||
AtRule::Charset(_) => todo!("@charset as expr"),
|
||||
|
@ -95,7 +95,7 @@ impl Mixin {
|
||||
while let Some(expr) = eat_expr(&mut self.body, &self.scope, super_selector)? {
|
||||
match expr {
|
||||
Expr::AtRule(a) => stmts.push(Stmt::AtRule(a)),
|
||||
Expr::Style(s) => stmts.push(Stmt::Style(s)),
|
||||
Expr::Style(s) => stmts.push(Stmt::Style(*s)),
|
||||
Expr::Styles(s) => stmts.extend(s.into_iter().map(Stmt::Style)),
|
||||
Expr::Include(s) => stmts.extend(s),
|
||||
Expr::MixinDecl(..) | Expr::FunctionDecl(..) | Expr::Debug(..) | Expr::Warn(..) => {
|
||||
|
@ -13,7 +13,7 @@ use std::vec::IntoIter;
|
||||
pub(crate) struct Selector(pub Vec<SelectorKind>);
|
||||
|
||||
impl Selector {
|
||||
pub fn new() -> Selector {
|
||||
pub const fn new() -> Selector {
|
||||
Selector(Vec::new())
|
||||
}
|
||||
}
|
||||
|
10
src/style.rs
10
src/style.rs
@ -118,7 +118,7 @@ impl<'a> StyleParser<'a> {
|
||||
if tok.equals_symbol(Symbol::OpenCurlyBrace) {
|
||||
match self.eat_style_group(toks, property)? {
|
||||
Expr::Styles(s) => styles.extend(s),
|
||||
Expr::Style(s) => styles.push(s),
|
||||
Expr::Style(s) => styles.push(*s),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
devour_whitespace(toks);
|
||||
@ -150,7 +150,7 @@ impl<'a> StyleParser<'a> {
|
||||
value,
|
||||
});
|
||||
match self.eat_style_group(toks, property)? {
|
||||
Expr::Style(s) => styles.push(s),
|
||||
Expr::Style(s) => styles.push(*s),
|
||||
Expr::Styles(s) => styles.extend(s),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
@ -186,7 +186,7 @@ impl<'a> StyleParser<'a> {
|
||||
value: val,
|
||||
}];
|
||||
match self.eat_style_group(toks, super_property)? {
|
||||
Expr::Style(s) => v.push(s),
|
||||
Expr::Style(s) => v.push(*s),
|
||||
Expr::Styles(s) => v.extend(s),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
@ -194,10 +194,10 @@ impl<'a> StyleParser<'a> {
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
return Ok(Expr::Style(Style {
|
||||
return Ok(Expr::Style(Box::new(Style {
|
||||
property: super_property,
|
||||
value: val,
|
||||
}));
|
||||
})));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user