Run rustfmt on selectors, servo_arc, and style.

This was generated with:

./mach cargo fmt --package selectors &&
./mach cargo fmt --package servo_arc &&
./mach cargo fmt --package style

Using rustfmt 0.4.1-nightly (a4462d1 2018-03-26)
This commit is contained in:
Bobby Holley 2018-04-10 17:35:15 -07:00
parent f7ae1a37e3
commit c99bcdd4b8
181 changed files with 9981 additions and 7933 deletions

View file

@ -10,7 +10,7 @@ use cssparser::parse_important;
#[cfg(feature = "gecko")]
use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
use parser::ParserContext;
use properties::{PropertyId, PropertyDeclaration, SourcePropertyDeclaration};
use properties::{PropertyDeclaration, PropertyId, SourcePropertyDeclaration};
use selectors::parser::SelectorParseErrorKind;
use servo_arc::Arc;
use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked};
@ -111,33 +111,38 @@ impl SupportsCondition {
let (keyword, wrapper) = match input.next() {
Err(_) => {
// End of input
return Ok(in_parens)
}
return Ok(in_parens);
},
Ok(&Token::Ident(ref ident)) => {
match_ignore_ascii_case! { &ident,
"and" => ("and", SupportsCondition::And as fn(_) -> _),
"or" => ("or", SupportsCondition::Or as fn(_) -> _),
_ => return Err(location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone())))
}
}
Ok(t) => return Err(location.new_unexpected_token_error(t.clone()))
},
Ok(t) => return Err(location.new_unexpected_token_error(t.clone())),
};
let mut conditions = Vec::with_capacity(2);
conditions.push(in_parens);
loop {
conditions.push(SupportsCondition::parse_in_parens(input)?);
if input.try(|input| input.expect_ident_matching(keyword)).is_err() {
if input
.try(|input| input.expect_ident_matching(keyword))
.is_err()
{
// Did not find the expected keyword.
// If we found some other token,
// it will be rejected by `Parser::parse_entirely` somewhere up the stack.
return Ok(wrapper(conditions))
return Ok(wrapper(conditions));
}
}
}
/// <https://drafts.csswg.org/css-conditional-3/#supports_condition_in_parens>
fn parse_in_parens<'i, 't>(input: &mut Parser<'i, 't>) -> Result<SupportsCondition, ParseError<'i>> {
fn parse_in_parens<'i, 't>(
input: &mut Parser<'i, 't>,
) -> Result<SupportsCondition, ParseError<'i>> {
// Whitespace is normally taken care of in `Parser::next`,
// but we want to not include it in `pos` for the SupportsCondition::FutureSyntax cases.
while input.try(Parser::expect_whitespace).is_ok() {}
@ -146,13 +151,12 @@ impl SupportsCondition {
// FIXME: remove clone() when lifetimes are non-lexical
match input.next()?.clone() {
Token::ParenthesisBlock => {
let nested = input.try(|input| {
input.parse_nested_block(|i| parse_condition_or_declaration(i))
});
let nested = input
.try(|input| input.parse_nested_block(|i| parse_condition_or_declaration(i)));
if nested.is_ok() {
return nested;
}
}
},
Token::Function(ident) => {
// Although this is an internal syntax, it is not necessary to check
// parsing context as far as we accept any unexpected token as future
@ -165,18 +169,19 @@ impl SupportsCondition {
.map(|s| s.to_string())
.map_err(CssParseError::<()>::from)
}).and_then(|s| {
CString::new(s)
.map_err(|_| location.new_custom_error(()))
})
CString::new(s).map_err(|_| location.new_custom_error(()))
})
}) {
return Ok(SupportsCondition::MozBoolPref(name));
}
}
}
},
t => return Err(location.new_unexpected_token_error(t)),
}
input.parse_nested_block(|i| consume_any_value(i))?;
Ok(SupportsCondition::FutureSyntax(input.slice_from(pos).to_owned()))
Ok(SupportsCondition::FutureSyntax(
input.slice_from(pos).to_owned(),
))
}
/// Evaluate a supports condition
@ -188,7 +193,7 @@ impl SupportsCondition {
SupportsCondition::Or(ref vec) => vec.iter().any(|c| c.eval(cx)),
SupportsCondition::Declaration(ref decl) => decl.eval(cx),
SupportsCondition::MozBoolPref(ref name) => eval_moz_bool_pref(name, cx),
SupportsCondition::FutureSyntax(_) => false
SupportsCondition::FutureSyntax(_) => false,
}
}
}
@ -210,8 +215,9 @@ fn eval_moz_bool_pref(_: &CStr, _: &ParserContext) -> bool {
/// supports_condition | declaration
/// <https://drafts.csswg.org/css-conditional/#dom-css-supports-conditiontext-conditiontext>
pub fn parse_condition_or_declaration<'i, 't>(input: &mut Parser<'i, 't>)
-> Result<SupportsCondition, ParseError<'i>> {
pub fn parse_condition_or_declaration<'i, 't>(
input: &mut Parser<'i, 't>,
) -> Result<SupportsCondition, ParseError<'i>> {
if let Ok(condition) = input.try(SupportsCondition::parse) {
Ok(SupportsCondition::Parenthesized(Box::new(condition)))
} else {
@ -228,12 +234,12 @@ impl ToCss for SupportsCondition {
SupportsCondition::Not(ref cond) => {
dest.write_str("not ")?;
cond.to_css(dest)
}
},
SupportsCondition::Parenthesized(ref cond) => {
dest.write_str("(")?;
cond.to_css(dest)?;
dest.write_str(")")
}
},
SupportsCondition::And(ref vec) => {
let mut first = true;
for cond in vec {
@ -244,7 +250,7 @@ impl ToCss for SupportsCondition {
cond.to_css(dest)?;
}
Ok(())
}
},
SupportsCondition::Or(ref vec) => {
let mut first = true;
for cond in vec {
@ -255,19 +261,19 @@ impl ToCss for SupportsCondition {
cond.to_css(dest)?;
}
Ok(())
}
},
SupportsCondition::Declaration(ref decl) => {
dest.write_str("(")?;
decl.to_css(dest)?;
dest.write_str(")")
}
},
SupportsCondition::MozBoolPref(ref name) => {
dest.write_str("-moz-bool-pref(")?;
let name = str::from_utf8(name.as_bytes())
.expect("Should be parsed from valid UTF-8");
let name =
str::from_utf8(name.as_bytes()).expect("Should be parsed from valid UTF-8");
name.to_css(dest)?;
dest.write_str(")")
}
},
SupportsCondition::FutureSyntax(ref s) => dest.write_str(&s),
}
}
@ -309,20 +315,21 @@ impl Declaration {
let mut input = ParserInput::new(&self.0);
let mut input = Parser::new(&mut input);
input.parse_entirely(|input| -> Result<(), CssParseError<()>> {
let prop = input.expect_ident_cloned().unwrap();
input.expect_colon().unwrap();
input
.parse_entirely(|input| -> Result<(), CssParseError<()>> {
let prop = input.expect_ident_cloned().unwrap();
input.expect_colon().unwrap();
let id = PropertyId::parse(&prop)
.map_err(|_| input.new_custom_error(()))?;
let id = PropertyId::parse(&prop).map_err(|_| input.new_custom_error(()))?;
let mut declarations = SourcePropertyDeclaration::new();
input.parse_until_before(Delimiter::Bang, |input| {
PropertyDeclaration::parse_into(&mut declarations, id, prop, &context, input)
.map_err(|_| input.new_custom_error(()))
})?;
let _ = input.try(parse_important);
Ok(())
}).is_ok()
let mut declarations = SourcePropertyDeclaration::new();
input.parse_until_before(Delimiter::Bang, |input| {
PropertyDeclaration::parse_into(&mut declarations, id, prop, &context, input)
.map_err(|_| input.new_custom_error(()))
})?;
let _ = input.try(parse_important);
Ok(())
})
.is_ok()
}
}