Skip to content

Run cargo fmt and cargo clippy --fix on all files #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions color/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ where
let token = input.next()?;
match *token {
Token::Hash(ref value) | Token::IDHash(ref value) => {
parse_hash_color(value.as_bytes()).map(|(r, g, b, a)| {
P::Output::from_rgba(r, g, b, a)
})
},
parse_hash_color(value.as_bytes()).map(|(r, g, b, a)| P::Output::from_rgba(r, g, b, a))
}
Token::Ident(ref value) => parse_color_keyword(value),
Token::Function(ref name) => {
let name = name.clone();
Expand Down
29 changes: 17 additions & 12 deletions color/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use super::*;
use crate::{ColorParser, PredefinedColorSpace, Color, RgbaLegacy};
use crate::{Color, ColorParser, PredefinedColorSpace, RgbaLegacy};
use cssparser::{Parser, ParserInput};
use serde_json::{self, json, Value};

Expand Down Expand Up @@ -43,7 +43,6 @@ fn assert_json_eq(results: Value, expected: Value, message: &str) {
}
}


fn run_raw_json_tests<F: Fn(Value, Value) -> ()>(json_data: &str, run: F) {
let items = match serde_json::from_str(json_data) {
Ok(Value::Array(items)) => items,
Expand Down Expand Up @@ -92,11 +91,14 @@ fn color3() {
#[cfg_attr(all(miri, feature = "skip_long_tests"), ignore)]
#[test]
fn color3_hsl() {
run_color_tests(include_str!("../src/css-parsing-tests/color3_hsl.json"), |c| {
c.ok()
.map(|v| v.to_css_string().to_json())
.unwrap_or(Value::Null)
})
run_color_tests(
include_str!("../src/css-parsing-tests/color3_hsl.json"),
|c| {
c.ok()
.map(|v| v.to_css_string().to_json())
.unwrap_or(Value::Null)
},
)
}

/// color3_keywords.json is different: R, G and B are in 0..255 rather than 0..1
Expand All @@ -115,11 +117,14 @@ fn color3_keywords() {
#[cfg_attr(all(miri, feature = "skip_long_tests"), ignore)]
#[test]
fn color4_hwb() {
run_color_tests(include_str!("../src/css-parsing-tests/color4_hwb.json"), |c| {
c.ok()
.map(|v| v.to_css_string().to_json())
.unwrap_or(Value::Null)
})
run_color_tests(
include_str!("../src/css-parsing-tests/color4_hwb.json"),
|c| {
c.ok()
.map(|v| v.to_css_string().to_json())
.unwrap_or(Value::Null)
},
)
}

#[cfg_attr(all(miri, feature = "skip_long_tests"), ignore)]
Expand Down
8 changes: 4 additions & 4 deletions macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ fn get_byte_from_lit(lit: &syn::Lit) -> u8 {

fn get_byte_from_expr_lit(expr: &syn::Expr) -> u8 {
match *expr {
syn::Expr::Lit(syn::ExprLit { ref lit, .. }) => {
get_byte_from_lit(lit)
}
syn::Expr::Lit(syn::ExprLit { ref lit, .. }) => get_byte_from_lit(lit),
_ => unreachable!(),
}
}
Expand All @@ -69,7 +67,9 @@ fn parse_pat_to_table<'a>(
table[value as usize] = case_id;
}
}
&syn::Pat::Range(syn::PatRange { ref start, ref end, .. }) => {
&syn::Pat::Range(syn::PatRange {
ref start, ref end, ..
}) => {
let lo = get_byte_from_expr_lit(&start.as_ref().unwrap());
let hi = get_byte_from_expr_lit(&end.as_ref().unwrap());
for value in lo..hi {
Expand Down
2 changes: 1 addition & 1 deletion src/cow_rc_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::borrow::{Borrow, Cow};
use std::rc::Rc;
use std::{cmp, fmt, hash, marker, mem, ops, slice, str, ptr};
use std::{cmp, fmt, hash, marker, mem, ops, ptr, slice, str};

/// A string that is either shared (heap-allocated and reference-counted) or borrowed.
///
Expand Down
4 changes: 2 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub fn _cssparser_internal_to_lowercase<'a>(
let input_bytes =
unsafe { &*(input.as_bytes() as *const [u8] as *const [MaybeUninit<u8>]) };

buffer.copy_from_slice(&*input_bytes);
buffer.copy_from_slice(input_bytes);

// Same as above re layout, plus these bytes have been initialized:
let buffer = unsafe { &mut *(buffer as *mut [MaybeUninit<u8>] as *mut [u8]) };
Expand All @@ -195,7 +195,7 @@ pub fn _cssparser_internal_to_lowercase<'a>(
}

Some(
match input.bytes().position(|byte| matches!(byte, b'A'..=b'Z')) {
match input.bytes().position(|byte| byte.is_ascii_uppercase()) {
Some(first_uppercase) => make_ascii_lowercase(buffer, input, first_uppercase),
// common case: input is already lower-case
None => input,
Expand Down
14 changes: 7 additions & 7 deletions src/nth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::{BasicParseError, Parser, ParserInput, Token};
/// The input is typically the arguments of a function,
/// in which case the caller needs to check if the arguments’ parser is exhausted.
/// Return `Ok((A, B))`, or `Err(())` for a syntax error.
pub fn parse_nth<'i, 't>(input: &mut Parser<'i, 't>) -> Result<(i32, i32), BasicParseError<'i>> {
pub fn parse_nth<'i>(input: &mut Parser<'i, '_>) -> Result<(i32, i32), BasicParseError<'i>> {
match *input.next()? {
Token::Number {
int_value: Some(b), ..
Expand All @@ -22,7 +22,7 @@ pub fn parse_nth<'i, 't>(input: &mut Parser<'i, 't>) -> Result<(i32, i32), Basic
unit,
"n" => Ok(parse_b(input, a)?),
"n-" => Ok(parse_signless_b(input, a, -1)?),
_ => match parse_n_dash_digits(&*unit) {
_ => match parse_n_dash_digits(unit) {
Ok(b) => Ok((a, b)),
Err(()) => {
let unit = unit.clone();
Expand All @@ -40,7 +40,7 @@ pub fn parse_nth<'i, 't>(input: &mut Parser<'i, 't>) -> Result<(i32, i32), Basic
"n-" => Ok(parse_signless_b(input, 1, -1)?),
"-n-" => Ok(parse_signless_b(input, -1, -1)?),
_ => {
let (slice, a) = if value.starts_with("-") {
let (slice, a) = if value.starts_with('-') {
(&value[1..], -1)
} else {
(&**value, 1)
Expand Down Expand Up @@ -81,7 +81,7 @@ pub fn parse_nth<'i, 't>(input: &mut Parser<'i, 't>) -> Result<(i32, i32), Basic
}
}

fn parse_b<'i, 't>(input: &mut Parser<'i, 't>, a: i32) -> Result<(i32, i32), BasicParseError<'i>> {
fn parse_b<'i>(input: &mut Parser<'i, '_>, a: i32) -> Result<(i32, i32), BasicParseError<'i>> {
let start = input.state();
match input.next() {
Ok(&Token::Delim('+')) => parse_signless_b(input, a, 1),
Expand All @@ -98,8 +98,8 @@ fn parse_b<'i, 't>(input: &mut Parser<'i, 't>, a: i32) -> Result<(i32, i32), Bas
}
}

fn parse_signless_b<'i, 't>(
input: &mut Parser<'i, 't>,
fn parse_signless_b<'i>(
input: &mut Parser<'i, '_>,
a: i32,
b_sign: i32,
) -> Result<(i32, i32), BasicParseError<'i>> {
Expand All @@ -118,7 +118,7 @@ fn parse_n_dash_digits(string: &str) -> Result<i32, ()> {
let bytes = string.as_bytes();
if bytes.len() >= 3
&& bytes[..2].eq_ignore_ascii_case(b"n-")
&& bytes[2..].iter().all(|&c| matches!(c, b'0'..=b'9'))
&& bytes[2..].iter().all(|&c| c.is_ascii_digit())
{
Ok(parse_number_saturate(&string[1..]).unwrap()) // Include the minus sign
} else {
Expand Down
14 changes: 7 additions & 7 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl<'i, T> From<BasicParseError<'i>> for ParseError<'i, T> {
impl SourceLocation {
/// Create a new BasicParseError at this location for an unexpected token
#[inline]
pub fn new_basic_unexpected_token_error<'i>(self, token: Token<'i>) -> BasicParseError<'i> {
pub fn new_basic_unexpected_token_error(self, token: Token<'_>) -> BasicParseError<'_> {
BasicParseError {
kind: BasicParseErrorKind::UnexpectedToken(token),
location: self,
Expand All @@ -125,7 +125,7 @@ impl SourceLocation {

/// Create a new ParseError at this location for an unexpected token
#[inline]
pub fn new_unexpected_token_error<'i, E>(self, token: Token<'i>) -> ParseError<'i, E> {
pub fn new_unexpected_token_error<E>(self, token: Token<'_>) -> ParseError<'_, E> {
ParseError {
kind: ParseErrorKind::Basic(BasicParseErrorKind::UnexpectedToken(token)),
location: self,
Expand Down Expand Up @@ -748,7 +748,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
match self.parse_until_before(Delimiter::Comma, &mut parse_one) {
Ok(v) => values.push(v),
Err(e) if !ignore_errors => return Err(e),
Err(_) => {},
Err(_) => {}
}
match self.next() {
Err(_) => return Ok(values),
Expand Down Expand Up @@ -835,7 +835,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
/// expect_ident, but clone the CowRcStr
#[inline]
pub fn expect_ident_cloned(&mut self) -> Result<CowRcStr<'i>, BasicParseError<'i>> {
self.expect_ident().map(|s| s.clone())
self.expect_ident().cloned()
}

/// Parse a <ident-token> whose unescaped value is an ASCII-insensitive match for the given value.
Expand All @@ -860,7 +860,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
/// expect_string, but clone the CowRcStr
#[inline]
pub fn expect_string_cloned(&mut self) -> Result<CowRcStr<'i>, BasicParseError<'i>> {
self.expect_string().map(|s| s.clone())
self.expect_string().cloned()
}

/// Parse either a <ident-token> or a <string-token>, and return the unescaped value.
Expand All @@ -879,7 +879,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
Token::UnquotedUrl(ref value) => Ok(value.clone()),
Token::Function(ref name) if name.eq_ignore_ascii_case("url") => {
self.parse_nested_block(|input| {
input.expect_string().map_err(Into::into).map(|s| s.clone())
input.expect_string().map_err(Into::into).cloned()
})
.map_err(ParseError::<()>::basic)
}
Expand All @@ -894,7 +894,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
Token::QuotedString(ref value) => Ok(value.clone()),
Token::Function(ref name) if name.eq_ignore_ascii_case("url") => {
self.parse_nested_block(|input| {
input.expect_string().map_err(Into::into).map(|s| s.clone())
input.expect_string().map_err(Into::into).cloned()
})
.map_err(ParseError::<()>::basic)
}
Expand Down
16 changes: 8 additions & 8 deletions src/rules_and_declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::parser::{parse_nested_block, parse_until_after, ParseUntilErrorBehavi
///
/// Typical usage is `input.try_parse(parse_important).is_ok()`
/// at the end of a `DeclarationParser::parse_value` implementation.
pub fn parse_important<'i, 't>(input: &mut Parser<'i, 't>) -> Result<(), BasicParseError<'i>> {
pub fn parse_important<'i>(input: &mut Parser<'i, '_>) -> Result<(), BasicParseError<'i>> {
input.expect_delim('!')?;
input.expect_ident_matching("important")
}
Expand Down Expand Up @@ -253,10 +253,10 @@ where
self.input.skip_whitespace();
let start = self.input.state();
match self.input.next_including_whitespace_and_comments().ok()? {
Token::CloseCurlyBracket |
Token::WhiteSpace(..) |
Token::Semicolon |
Token::Comment(..) => continue,
Token::CloseCurlyBracket
| Token::WhiteSpace(..)
| Token::Semicolon
| Token::Comment(..) => continue,
Token::AtKeyword(ref name) => {
let name = name.clone();
return Some(parse_at_rule(&start, name, self.input, &mut *self.parser));
Expand Down Expand Up @@ -294,7 +294,7 @@ where
&mut *self.parser,
Delimiter::Semicolon | Delimiter::CurlyBracketBlock,
) {
return Some(Ok(qual))
return Some(Ok(qual));
}
}

Expand Down Expand Up @@ -367,7 +367,7 @@ where
let start = self.input.state();
let at_keyword = match self.input.next_byte()? {
b'@' => match self.input.next_including_whitespace_and_comments() {
Ok(&Token::AtKeyword(ref name)) => Some(name.clone()),
Ok(Token::AtKeyword(name)) => Some(name.clone()),
_ => {
self.input.reset(&start);
None
Expand Down Expand Up @@ -503,5 +503,5 @@ where
input.expect_curly_bracket_block()?;
// Do this here so that we consume the `{` even if the prelude is `Err`.
let prelude = prelude?;
parse_nested_block(input, |input| parser.parse_block(prelude, &start, input))
parse_nested_block(input, |input| parser.parse_block(prelude, start, input))
}
27 changes: 13 additions & 14 deletions src/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use crate::match_byte;
use dtoa_short::{self, Notation};
use itoa;

use std::fmt::{self, Write};
use std::str;

Expand Down Expand Up @@ -49,10 +49,9 @@ where
dtoa_short::write(dest, value)?
};

if int_value.is_none() && value.fract() == 0. {
if !notation.decimal_point && !notation.scientific {
dest.write_str(".0")?;
}
if int_value.is_none() && value.fract() == 0. && !notation.decimal_point && !notation.scientific
{
dest.write_str(".0")?;
}
Ok(())
}
Expand All @@ -63,23 +62,23 @@ impl<'a> ToCss for Token<'a> {
W: fmt::Write,
{
match *self {
Token::Ident(ref value) => serialize_identifier(&**value, dest)?,
Token::Ident(ref value) => serialize_identifier(value, dest)?,
Token::AtKeyword(ref value) => {
dest.write_str("@")?;
serialize_identifier(&**value, dest)?;
serialize_identifier(value, dest)?;
}
Token::Hash(ref value) => {
dest.write_str("#")?;
serialize_name(value, dest)?;
}
Token::IDHash(ref value) => {
dest.write_str("#")?;
serialize_identifier(&**value, dest)?;
serialize_identifier(value, dest)?;
}
Token::QuotedString(ref value) => serialize_string(&**value, dest)?,
Token::QuotedString(ref value) => serialize_string(value, dest)?,
Token::UnquotedUrl(ref value) => {
dest.write_str("url(")?;
serialize_unquoted_url(&**value, dest)?;
serialize_unquoted_url(value, dest)?;
dest.write_str(")")?;
}
Token::Delim(value) => dest.write_char(value)?,
Expand Down Expand Up @@ -134,7 +133,7 @@ impl<'a> ToCss for Token<'a> {
Token::CDC => dest.write_str("-->")?,

Token::Function(ref name) => {
serialize_identifier(&**name, dest)?;
serialize_identifier(name, dest)?;
dest.write_str("(")?;
}
Token::ParenthesisBlock => dest.write_str("(")?,
Expand Down Expand Up @@ -167,7 +166,7 @@ fn hex_escape<W>(ascii_byte: u8, dest: &mut W) -> fmt::Result
where
W: fmt::Write,
{
static HEX_DIGITS: &'static [u8; 16] = b"0123456789abcdef";
static HEX_DIGITS: &[u8; 16] = b"0123456789abcdef";
let b3;
let b4;
let bytes = if ascii_byte > 0x0F {
Expand All @@ -179,7 +178,7 @@ where
b3 = [b'\\', HEX_DIGITS[ascii_byte as usize], b' '];
&b3[..]
};
dest.write_str(unsafe { str::from_utf8_unchecked(&bytes) })
dest.write_str(unsafe { str::from_utf8_unchecked(bytes) })
}

fn char_escape<W>(ascii_byte: u8, dest: &mut W) -> fmt::Result
Expand Down Expand Up @@ -240,7 +239,7 @@ where
dest.write_str(&value[chunk_start..i])?;
if let Some(escaped) = escaped {
dest.write_str(escaped)?;
} else if (b >= b'\x01' && b <= b'\x1F') || b == b'\x7F' {
} else if (b'\x01'..=b'\x1F').contains(&b) || b == b'\x7F' {
hex_escape(b, dest)?;
} else {
char_escape(b, dest)?;
Expand Down
Loading