From ee2d827d48f4276572bf7a1b429bf2aa61936ef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 7 Jan 2019 16:57:43 +0100 Subject: [PATCH] Bug 1517511, bug 1518098 - followup: Rustfmt so Servo's lints are happy. --- servo/components/style/gecko/conversions.rs | 29 ++++++-------- servo/components/style/gecko/values.rs | 12 ++++-- .../gecko_bindings/sugar/ns_css_value.rs | 11 ++--- .../style/stylesheets/viewport_rule.rs | 13 +++--- .../style/values/animated/length.rs | 4 +- servo/components/style/values/animated/svg.rs | 16 ++++---- .../style/values/computed/basic_shape.rs | 3 +- .../components/style/values/computed/image.rs | 10 ++++- .../style/values/computed/length.rs | 40 ++++++++----------- .../style/values/generics/transform.rs | 6 +-- .../components/style/values/specified/box.rs | 3 +- .../components/style/values/specified/grid.rs | 3 +- .../style/values/specified/image.rs | 12 +++--- .../style/values/specified/length.rs | 21 ++++------ 14 files changed, 85 insertions(+), 98 deletions(-) diff --git a/servo/components/style/gecko/conversions.rs b/servo/components/style/gecko/conversions.rs index 7e896b375695..89cce99beb09 100644 --- a/servo/components/style/gecko/conversions.rs +++ b/servo/components/style/gecko/conversions.rs @@ -80,8 +80,8 @@ impl From for LengthPercentageOrAuto { // disappear as we move more stuff to cbindgen. impl From for NonNegativeLengthPercentageOrAuto { fn from(other: nsStyleCoord_CalcValue) -> Self { - NonNegative( - LengthPercentageOrAuto::LengthPercentage(LengthPercentage::with_clamping_mode( + NonNegative(LengthPercentageOrAuto::LengthPercentage( + LengthPercentage::with_clamping_mode( Au(other.mLength).into(), if other.mHasPercent { Some(Percentage(other.mPercent)) @@ -90,8 +90,8 @@ impl From for NonNegativeLengthPercentageOrAuto { }, AllowedNumericType::NonNegative, /* was_calc = */ true, - )) - ) + ), + )) } } @@ -529,17 +529,15 @@ impl nsStyleImage { structs::NS_STYLE_GRADIENT_SHAPE_ELLIPTICAL => { let length_percentage_keyword = match gecko_gradient.mSize as u32 { structs::NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE => match ( - LengthPercentage::from_gecko_style_coord( - &gecko_gradient.mRadiusX, - ), - LengthPercentage::from_gecko_style_coord( - &gecko_gradient.mRadiusY, - ), + LengthPercentage::from_gecko_style_coord(&gecko_gradient.mRadiusX), + LengthPercentage::from_gecko_style_coord(&gecko_gradient.mRadiusY), ) { (Some(x), Some(y)) => Ellipse::Radii(x, y), _ => { - debug_assert!(false, - "mRadiusX, mRadiusY could not convert to LengthPercentage"); + debug_assert!( + false, + "mRadiusX, mRadiusY could not convert to LengthPercentage" + ); Ellipse::Radii( LengthPercentage::zero(), LengthPercentage::zero(), @@ -802,10 +800,9 @@ pub mod basic_shape { ), ), NonNegative( - LengthPercentage::from_gecko_style_coord(&other.data_at(index + 1)) - .expect( - " should be a length, percentage, or calc value", - ), + LengthPercentage::from_gecko_style_coord(&other.data_at(index + 1)).expect( + " should be a length, percentage, or calc value", + ), ), ) }; diff --git a/servo/components/style/gecko/values.rs b/servo/components/style/gecko/values.rs index 4937b019b5cf..2288db104a4d 100644 --- a/servo/components/style/gecko/values.rs +++ b/servo/components/style/gecko/values.rs @@ -149,7 +149,7 @@ impl GeckoStyleCoordConvertible for NumberOrPercentage { impl GeckoStyleCoordConvertible for LengthPercentage { fn to_gecko_style_coord(&self, coord: &mut T) { if self.was_calc { - return coord.set_value(CoordDataValue::Calc((*self).into())) + return coord.set_value(CoordDataValue::Calc((*self).into())); } debug_assert!(self.percentage.is_none() || self.unclamped_length() == Length::zero()); if let Some(p) = self.percentage { @@ -161,7 +161,9 @@ impl GeckoStyleCoordConvertible for LengthPercentage { fn from_gecko_style_coord(coord: &T) -> Option { match coord.as_value() { CoordDataValue::Coord(coord) => Some(LengthPercentage::new(Au(coord).into(), None)), - CoordDataValue::Percent(p) => Some(LengthPercentage::new(Au(0).into(), Some(Percentage(p)))), + CoordDataValue::Percent(p) => { + Some(LengthPercentage::new(Au(0).into(), Some(Percentage(p)))) + }, CoordDataValue::Calc(calc) => Some(calc.into()), _ => None, } @@ -192,7 +194,8 @@ impl GeckoStyleCoordConvertible for LengthPercentageOrAuto { fn from_gecko_style_coord(coord: &T) -> Option { match coord.as_value() { CoordDataValue::Auto => Some(LengthPercentageOrAuto::Auto), - _ => LengthPercentage::from_gecko_style_coord(coord).map(LengthPercentageOrAuto::LengthPercentage), + _ => LengthPercentage::from_gecko_style_coord(coord) + .map(LengthPercentageOrAuto::LengthPercentage), } } } @@ -208,7 +211,8 @@ impl GeckoStyleCoordConvertible for LengthPercentageOrNone { fn from_gecko_style_coord(coord: &T) -> Option { match coord.as_value() { CoordDataValue::None => Some(LengthPercentageOrNone::None), - _ => LengthPercentage::from_gecko_style_coord(coord).map(LengthPercentageOrNone::LengthPercentage), + _ => LengthPercentage::from_gecko_style_coord(coord) + .map(LengthPercentageOrNone::LengthPercentage), } } } diff --git a/servo/components/style/gecko_bindings/sugar/ns_css_value.rs b/servo/components/style/gecko_bindings/sugar/ns_css_value.rs index b8cc1f9c5c42..73657af3e354 100644 --- a/servo/components/style/gecko_bindings/sugar/ns_css_value.rs +++ b/servo/components/style/gecko_bindings/sugar/ns_css_value.rs @@ -70,7 +70,7 @@ impl nsCSSValue { /// Sets LengthPercentage value to this nsCSSValue. pub unsafe fn set_length_percentage(&mut self, lp: LengthPercentage) { if lp.was_calc { - return bindings::Gecko_CSSValue_SetCalc(self, lp.into()) + return bindings::Gecko_CSSValue_SetCalc(self, lp.into()); } debug_assert!(lp.percentage.is_none() || lp.unclamped_length() == Length::zero()); if let Some(p) = lp.percentage { @@ -93,17 +93,12 @@ impl nsCSSValue { pub unsafe fn get_length_percentage(&self) -> LengthPercentage { match self.mUnit { nsCSSUnit::eCSSUnit_Pixel => { - LengthPercentage::new( - Length::new(bindings::Gecko_CSSValue_GetNumber(self)), - None, - ) + LengthPercentage::new(Length::new(bindings::Gecko_CSSValue_GetNumber(self)), None) }, nsCSSUnit::eCSSUnit_Percent => LengthPercentage::new_percent(Percentage( bindings::Gecko_CSSValue_GetPercentage(self), )), - nsCSSUnit::eCSSUnit_Calc => { - bindings::Gecko_CSSValue_GetCalc(self).into() - }, + nsCSSUnit::eCSSUnit_Calc => bindings::Gecko_CSSValue_GetCalc(self).into(), _ => panic!("Unexpected unit"), } } diff --git a/servo/components/style/stylesheets/viewport_rule.rs b/servo/components/style/stylesheets/viewport_rule.rs index ce63ffbfc472..862399e065c1 100644 --- a/servo/components/style/stylesheets/viewport_rule.rs +++ b/servo/components/style/stylesheets/viewport_rule.rs @@ -18,7 +18,9 @@ use crate::shared_lock::{SharedRwLockReadGuard, StylesheetGuards, ToCssWithGuard use crate::str::CssStringWriter; use crate::stylesheets::{Origin, StylesheetInDocument}; use crate::values::computed::{Context, ToComputedValue}; -use crate::values::specified::{self, LengthPercentageOrAuto, NoCalcLength, ViewportPercentageLength}; +use crate::values::specified::{ + self, LengthPercentageOrAuto, NoCalcLength, ViewportPercentageLength, +}; use app_units::Au; use cssparser::CowRcStr; use cssparser::{parse_important, AtRuleParser, DeclarationListParser, DeclarationParser, Parser}; @@ -158,7 +160,7 @@ impl FromMeta for ViewportLength { macro_rules! specified { ($value:expr) => { ViewportLength::Specified(LengthPercentageOrAuto::LengthPercentage( - specified::LengthPercentage::Length($value) + specified::LengthPercentage::Length($value), )) }; } @@ -755,9 +757,10 @@ impl MaybeNew for ViewportConstraints { match *$value { ViewportLength::Specified(ref length) => match *length { LengthPercentageOrAuto::Auto => None, - LengthPercentageOrAuto::LengthPercentage(ref lop) => Some(lop - .to_computed_value(&context) - .to_used_value(initial_viewport.$dimension)), + LengthPercentageOrAuto::LengthPercentage(ref lop) => Some( + lop.to_computed_value(&context) + .to_used_value(initial_viewport.$dimension), + ), }, ViewportLength::ExtendToZoom => { // $extend_to will be 'None' if 'extend-to-zoom' is 'auto' diff --git a/servo/components/style/values/animated/length.rs b/servo/components/style/values/animated/length.rs index 18360fad46bb..672c4117b00d 100644 --- a/servo/components/style/values/animated/length.rs +++ b/servo/components/style/values/animated/length.rs @@ -27,7 +27,9 @@ impl Animate for LengthPercentage { .unclamped_length() .animate(&other.unclamped_length(), procedure)?; let percentage = animate_percentage_half(self.percentage, other.percentage)?; - let is_calc = self.was_calc || other.was_calc || self.percentage.is_some() != other.percentage.is_some(); + let is_calc = self.was_calc || + other.was_calc || + self.percentage.is_some() != other.percentage.is_some(); Ok(Self::with_clamping_mode( length, percentage, diff --git a/servo/components/style/values/animated/svg.rs b/servo/components/style/values/animated/svg.rs index 4f181981d911..af627bba7849 100644 --- a/servo/components/style/values/animated/svg.rs +++ b/servo/components/style/values/animated/svg.rs @@ -32,16 +32,14 @@ fn to_number_or_percentage( value: &SvgLengthPercentageOrNumber, ) -> Result { Ok(match *value { - SvgLengthPercentageOrNumber::LengthPercentage(ref l) => { - match l.percentage { - Some(p) => { - if l.unclamped_length().px() != 0. { - return Err(()); - } - NumberOrPercentage::Percentage(p) + SvgLengthPercentageOrNumber::LengthPercentage(ref l) => match l.percentage { + Some(p) => { + if l.unclamped_length().px() != 0. { + return Err(()); } - None => NumberOrPercentage::Number(l.length().px()) - } + NumberOrPercentage::Percentage(p) + }, + None => NumberOrPercentage::Number(l.length().px()), }, SvgLengthPercentageOrNumber::Number(ref n) => NumberOrPercentage::Number(*n), }) diff --git a/servo/components/style/values/computed/basic_shape.rs b/servo/components/style/values/computed/basic_shape.rs index 9b4be5388545..28067fb0c81f 100644 --- a/servo/components/style/values/computed/basic_shape.rs +++ b/servo/components/style/values/computed/basic_shape.rs @@ -34,8 +34,7 @@ pub type BasicShape = generic::BasicShape< pub type InsetRect = generic::InsetRect; /// A computed circle. -pub type Circle = - generic::Circle; +pub type Circle = generic::Circle; /// A computed ellipse. pub type Ellipse = diff --git a/servo/components/style/values/computed/image.rs b/servo/components/style/values/computed/image.rs index 749c2e44e3ac..a77da59dda3c 100644 --- a/servo/components/style/values/computed/image.rs +++ b/servo/components/style/values/computed/image.rs @@ -71,10 +71,16 @@ impl generic::LineDirection for LineDirection { LineDirection::Vertical(Y::Top) if compat_mode != CompatMode::Modern => true, LineDirection::Corner(..) => false, #[cfg(feature = "gecko")] - LineDirection::MozPosition(Some(Position { ref vertical, ref horizontal }), None) => { + LineDirection::MozPosition( + Some(Position { + ref vertical, + ref horizontal, + }), + None, + ) => { // `50% 0%` is the default value for line direction. horizontal.as_percentage().map_or(false, |p| p.0 == 0.5) && - vertical.as_percentage().map_or(false, |p| p.0 == 0.0) + vertical.as_percentage().map_or(false, |p| p.0 == 0.0) }, _ => false, } diff --git a/servo/components/style/values/computed/length.rs b/servo/components/style/values/computed/length.rs index 65f19d117ae8..daf14ea19e34 100644 --- a/servo/components/style/values/computed/length.rs +++ b/servo/components/style/values/computed/length.rs @@ -5,7 +5,7 @@ //! `` computed values, and related ones. use super::{Context, Number, Percentage, ToComputedValue}; -use crate::values::animated::{ToAnimatedValue}; +use crate::values::animated::ToAnimatedValue; use crate::values::distance::{ComputeSquaredDistance, SquaredDistance}; use crate::values::generics::length::MaxLength as GenericMaxLength; use crate::values::generics::length::MozLength as GenericMozLength; @@ -170,7 +170,6 @@ impl LengthPercentage { self.length } - /// Return the percentage value as CSSFloat. #[inline] pub fn percentage(&self) -> CSSFloat { @@ -380,7 +379,7 @@ impl LengthPercentage { self.percentage, AllowedNumericType::NonNegative, self.was_calc, - ) + ); } debug_assert!(self.percentage.is_none() || self.unclamped_length() == Length::zero()); @@ -410,32 +409,25 @@ impl ToComputedValue for specified::LengthPercentage { specified::LengthPercentage::Length(ref value) => { LengthPercentage::new(value.to_computed_value(context), None) }, - specified::LengthPercentage::Percentage(value) => { - LengthPercentage::new_percent(value) - }, - specified::LengthPercentage::Calc(ref calc) => { - (**calc).to_computed_value(context) - }, + specified::LengthPercentage::Percentage(value) => LengthPercentage::new_percent(value), + specified::LengthPercentage::Calc(ref calc) => (**calc).to_computed_value(context), } } fn from_computed_value(computed: &LengthPercentage) -> Self { let length = computed.unclamped_length(); if let Some(p) = computed.as_percentage() { - return specified::LengthPercentage::Percentage(p) + return specified::LengthPercentage::Percentage(p); } let percentage = computed.percentage; - if percentage.is_none() && - computed.clamping_mode.clamp(length.px()) == length.px() { - return specified::LengthPercentage::Length( - ToComputedValue::from_computed_value(&length) - ) + if percentage.is_none() && computed.clamping_mode.clamp(length.px()) == length.px() { + return specified::LengthPercentage::Length(ToComputedValue::from_computed_value( + &length, + )); } - specified::LengthPercentage::Calc(Box::new( - ToComputedValue::from_computed_value(computed), - )) + specified::LengthPercentage::Calc(Box::new(ToComputedValue::from_computed_value(computed))) } } @@ -448,7 +440,9 @@ impl IsZeroLength for LengthPercentage { #[allow(missing_docs)] #[css(derive_debug)] -#[derive(Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToAnimatedZero, ToCss)] +#[derive( + Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToAnimatedZero, ToCss, +)] pub enum LengthPercentageOrAuto { LengthPercentage(LengthPercentage), Auto, @@ -522,9 +516,7 @@ impl ToComputedValue for specified::LengthPercentageOrAuto { fn to_computed_value(&self, context: &Context) -> LengthPercentageOrAuto { match *self { specified::LengthPercentageOrAuto::LengthPercentage(ref value) => { - LengthPercentageOrAuto::LengthPercentage( - value.to_computed_value(context), - ) + LengthPercentageOrAuto::LengthPercentage(value.to_computed_value(context)) }, specified::LengthPercentageOrAuto::Auto => LengthPercentageOrAuto::Auto, } @@ -545,7 +537,9 @@ impl ToComputedValue for specified::LengthPercentageOrAuto { #[allow(missing_docs)] #[css(derive_debug)] -#[derive(Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToAnimatedZero, ToCss)] +#[derive( + Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToAnimatedZero, ToCss, +)] pub enum LengthPercentageOrNone { LengthPercentage(LengthPercentage), None, diff --git a/servo/components/style/values/generics/transform.rs b/servo/components/style/values/generics/transform.rs index 87f26efa0d9d..4591f3addd28 100644 --- a/servo/components/style/values/generics/transform.rs +++ b/servo/components/style/values/generics/transform.rs @@ -191,8 +191,7 @@ pub enum TransformOperation { #[allow(missing_docs)] #[css(comma, function = "interpolatematrix")] InterpolateMatrix { - from_list: - Transform>, + from_list: Transform>, to_list: Transform>, progress: computed::Percentage, }, @@ -200,8 +199,7 @@ pub enum TransformOperation { #[allow(missing_docs)] #[css(comma, function = "accumulatematrix")] AccumulateMatrix { - from_list: - Transform>, + from_list: Transform>, to_list: Transform>, count: Integer, }, diff --git a/servo/components/style/values/specified/box.rs b/servo/components/style/values/specified/box.rs index 62d1ba50333a..30111170bc0a 100644 --- a/servo/components/style/values/specified/box.rs +++ b/servo/components/style/values/specified/box.rs @@ -278,8 +278,7 @@ impl Parse for VerticalAlign { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(lp) = - input.try(|i| LengthPercentage::parse_quirky(context, i, AllowQuirks::Yes)) + if let Ok(lp) = input.try(|i| LengthPercentage::parse_quirky(context, i, AllowQuirks::Yes)) { return Ok(GenericVerticalAlign::Length(lp)); } diff --git a/servo/components/style/values/specified/grid.rs b/servo/components/style/values/specified/grid.rs index 55a977baf8c0..b3e18e66e8ec 100644 --- a/servo/components/style/values/specified/grid.rs +++ b/servo/components/style/values/specified/grid.rs @@ -73,8 +73,7 @@ impl Parse for TrackSize { } input.expect_function_matching("fit-content")?; - let lp = - input.parse_nested_block(|i| LengthPercentage::parse_non_negative(context, i))?; + let lp = input.parse_nested_block(|i| LengthPercentage::parse_non_negative(context, i))?; Ok(TrackSize::FitContent(lp)) } } diff --git a/servo/components/style/values/specified/image.rs b/servo/components/style/values/specified/image.rs index 42b090686ca7..2dc56f8ad3fc 100644 --- a/servo/components/style/values/specified/image.rs +++ b/servo/components/style/values/specified/image.rs @@ -698,16 +698,16 @@ impl generic::LineDirection for LineDirection { // These percentage values can also be keywords. let x = match *x { OriginComponent::Center => true, - OriginComponent::Length(LengthPercentage::Percentage( - ComputedPercentage(val), - )) => val == 0.5, + OriginComponent::Length(LengthPercentage::Percentage(ComputedPercentage( + val, + ))) => val == 0.5, _ => false, }; let y = match *y { OriginComponent::Side(Y::Top) => true, - OriginComponent::Length(LengthPercentage::Percentage( - ComputedPercentage(val), - )) => val == 0.0, + OriginComponent::Length(LengthPercentage::Percentage(ComputedPercentage( + val, + ))) => val == 0.0, _ => false, }; x && y diff --git a/servo/components/style/values/specified/length.rs b/servo/components/style/values/specified/length.rs index 18969f0dcf7a..e83abebc37ca 100644 --- a/servo/components/style/values/specified/length.rs +++ b/servo/components/style/values/specified/length.rs @@ -922,12 +922,9 @@ impl LengthPercentageOrAuto { return Ok(LengthPercentageOrAuto::Auto); } - Ok(LengthPercentageOrAuto::LengthPercentage(LengthPercentage::parse_internal( - context, - input, - num_context, - allow_quirks, - )?)) + Ok(LengthPercentageOrAuto::LengthPercentage( + LengthPercentage::parse_internal(context, input, num_context, allow_quirks)?, + )) } /// Parse a non-negative length, percentage, or auto. @@ -1052,12 +1049,9 @@ impl LengthPercentageOrNone { return Ok(LengthPercentageOrNone::None); } - Ok(LengthPercentageOrNone::LengthPercentage(LengthPercentage::parse_internal( - context, - input, - num_context, - allow_quirks, - )?)) + Ok(LengthPercentageOrNone::LengthPercentage( + LengthPercentage::parse_internal(context, input, num_context, allow_quirks)?, + )) } /// Parse a non-negative LengthPercentageOrNone. @@ -1117,8 +1111,7 @@ impl Parse for NonNegativeLengthPercentage { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - LengthPercentage::parse_non_negative(context, input) - .map(NonNegative::) + LengthPercentage::parse_non_negative(context, input).map(NonNegative::) } }