diff --git a/components/selectors/parser.rs b/components/selectors/parser.rs index d354b01074b..0f7cb9c6055 100644 --- a/components/selectors/parser.rs +++ b/components/selectors/parser.rs @@ -2043,7 +2043,10 @@ where // given selector is allowed to match a featureless element, // it must do so while ignoring the default namespace. // - if !matches!(result, SimpleSelectorParseResult::SimpleSelector(Component::Host(..))) { + if !matches!( + result, + SimpleSelectorParseResult::SimpleSelector(Component::Host(..)) + ) { builder.push_simple_selector(Component::DefaultNamespace(url)); } } diff --git a/components/style/counter_style/mod.rs b/components/style/counter_style/mod.rs index bffedd845e3..9c4be49bb91 100644 --- a/components/style/counter_style/mod.rs +++ b/components/style/counter_style/mod.rs @@ -408,7 +408,9 @@ impl ToCss for System { } /// -#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToCss, ToShmem)] +#[derive( + Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToCss, ToShmem, +)] #[repr(u8)] pub enum Symbol { /// @@ -554,7 +556,9 @@ impl Parse for Fallback { } /// -#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToCss, ToShmem)] +#[derive( + Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToCss, ToShmem, +)] #[repr(C)] pub struct Symbols(#[css(iterable)] pub crate::OwnedSlice); diff --git a/components/style/custom_properties.rs b/components/style/custom_properties.rs index d977870629b..d0af57886db 100644 --- a/components/style/custom_properties.rs +++ b/components/style/custom_properties.rs @@ -582,7 +582,7 @@ impl<'a> CustomPropertiesBuilder<'a> { // Don't touch the map, this has the same effect as // making it compute to the inherited one. return; - } + }, } } else { (*unparsed_value).clone() @@ -848,7 +848,7 @@ fn substitute_all( match result { Ok(computed_value) => { context.map.insert(name, Arc::new(computed_value)); - } + }, Err(..) => { // This is invalid, reset it to the unset (inherited) value. let inherited = context.inherited.and_then(|m| m.get(&name)).cloned(); @@ -860,7 +860,7 @@ fn substitute_all( context.map.remove(&name); }, }; - } + }, } // All resolved, so return the signal value. diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs index f4c994bb1c7..ea3700a3235 100644 --- a/components/style/gecko/conversions.rs +++ b/components/style/gecko/conversions.rs @@ -10,7 +10,7 @@ #![allow(unsafe_code)] -use crate::gecko_bindings::structs::{Matrix4x4Components, nsresult}; +use crate::gecko_bindings::structs::{nsresult, Matrix4x4Components}; use crate::stylesheets::RulesMutateError; use crate::values::computed::transform::Matrix3D; diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index 1724f1605e4..27cb666fc6f 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -318,7 +318,9 @@ impl Device { let mut right = 0.0; let mut bottom = 0.0; let mut left = 0.0; - unsafe { bindings::Gecko_GetSafeAreaInsets(pc, &mut top, &mut right, &mut bottom, &mut left) }; + unsafe { + bindings::Gecko_GetSafeAreaInsets(pc, &mut top, &mut right, &mut bottom, &mut left) + }; SideOffsets2D::new(top, right, bottom, left) } } diff --git a/components/style/gecko/selector_parser.rs b/components/style/gecko/selector_parser.rs index c3b85dbf7fa..3c944bbc6eb 100644 --- a/components/style/gecko/selector_parser.rs +++ b/components/style/gecko/selector_parser.rs @@ -173,7 +173,7 @@ impl NonTSPseudoClass { #[inline] fn is_enabled_in_content(&self) -> bool { if matches!(*self, NonTSPseudoClass::FocusVisible) { - return static_prefs::pref!("layout.css.focus-visible.enabled") + return static_prefs::pref!("layout.css.focus-visible.enabled"); } !self.has_any_flag(NonTSPseudoClassFlag::PSEUDO_CLASS_ENABLED_IN_UA_SHEETS_AND_CHROME) } diff --git a/components/style/gecko/snapshot_helpers.rs b/components/style/gecko/snapshot_helpers.rs index f65fe55d8ff..bd905870353 100644 --- a/components/style/gecko/snapshot_helpers.rs +++ b/components/style/gecko/snapshot_helpers.rs @@ -93,13 +93,7 @@ pub(super) fn each_exported_part( None => return, }; let mut length = 0; - let atoms = unsafe { - bindings::Gecko_Element_ExportedParts( - attr, - name.as_ptr(), - &mut length, - ) - }; + let atoms = unsafe { bindings::Gecko_Element_ExportedParts(attr, name.as_ptr(), &mut length) }; if atoms.is_null() { return; } diff --git a/components/style/gecko_string_cache/namespace.rs b/components/style/gecko_string_cache/namespace.rs index dd3b52d2506..72de229f1d7 100644 --- a/components/style/gecko_string_cache/namespace.rs +++ b/components/style/gecko_string_cache/namespace.rs @@ -24,7 +24,18 @@ macro_rules! ns { } /// A Gecko namespace is just a wrapped atom. -#[derive(Clone, Debug, Default, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)] +#[derive( + Clone, + Debug, + Default, + Eq, + Hash, + MallocSizeOf, + PartialEq, + ToComputedValue, + ToResolvedValue, + ToShmem, +)] #[repr(transparent)] pub struct Namespace(pub Atom); diff --git a/components/style/rule_collector.rs b/components/style/rule_collector.rs index 26a85d9dc2a..1550a0368a4 100644 --- a/components/style/rule_collector.rs +++ b/components/style/rule_collector.rs @@ -148,7 +148,8 @@ where self.context.current_host = host.map(|e| e.opaque()); f(self); if start != self.rules.len() { - self.rules[start..].sort_unstable_by_key(|block| (block.specificity, block.source_order())); + self.rules[start..] + .sort_unstable_by_key(|block| (block.specificity, block.source_order())); } self.context.current_host = old_host; self.in_sort_scope = false; @@ -214,11 +215,7 @@ where } #[inline] - fn collect_rules_in_list( - &mut self, - part_rules: &[Rule], - cascade_level: CascadeLevel, - ) { + fn collect_rules_in_list(&mut self, part_rules: &[Rule], cascade_level: CascadeLevel) { debug_assert!(self.in_sort_scope, "Rules gotta be sorted"); SelectorMap::get_matching_rules( self.element, @@ -231,11 +228,7 @@ where } #[inline] - fn collect_rules_in_map( - &mut self, - map: &SelectorMap, - cascade_level: CascadeLevel, - ) { + fn collect_rules_in_map(&mut self, map: &SelectorMap, cascade_level: CascadeLevel) { debug_assert!(self.in_sort_scope, "Rules gotta be sorted"); map.get_all_matching_rules( self.element, @@ -413,10 +406,7 @@ where self.in_tree(containing_host, |collector| { for p in &parts { if let Some(part_rules) = part_rules.get(p) { - collector.collect_rules_in_list( - part_rules, - cascade_level, - ); + collector.collect_rules_in_list(part_rules, cascade_level); } } }); diff --git a/components/style/style_adjuster.rs b/components/style/style_adjuster.rs index 6fd5a0ace73..c2a15f7fa0e 100644 --- a/components/style/style_adjuster.rs +++ b/components/style/style_adjuster.rs @@ -229,10 +229,10 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { if !display.is_contents() { if !self - .style - .get_text() - .clone_text_decoration_line() - .is_empty() + .style + .get_text() + .clone_text_decoration_line() + .is_empty() { self.style .add_flags(ComputedValueFlags::HAS_TEXT_DECORATION_LINES); diff --git a/components/style/stylesheets/mod.rs b/components/style/stylesheets/mod.rs index 9d007e45ad7..daf97f20e3c 100644 --- a/components/style/stylesheets/mod.rs +++ b/components/style/stylesheets/mod.rs @@ -58,8 +58,8 @@ pub use self::rule_parser::{InsertRuleContext, State, TopLevelRuleParser}; pub use self::rules_iterator::{AllRules, EffectiveRules}; pub use self::rules_iterator::{NestedRuleIterationCondition, RulesIterator}; pub use self::style_rule::StyleRule; +pub use self::stylesheet::{AllowImportRules, SanitizationData, SanitizationKind}; pub use self::stylesheet::{DocumentStyleSheet, Namespaces, Stylesheet}; -pub use self::stylesheet::{SanitizationData, SanitizationKind, AllowImportRules}; pub use self::stylesheet::{StylesheetContents, StylesheetInDocument, UserAgentStylesheets}; pub use self::supports_rule::SupportsRule; pub use self::viewport_rule::ViewportRule; diff --git a/components/style/stylesheets/rule_list.rs b/components/style/stylesheets/rule_list.rs index 4b6ac3e0a57..d84a738bca0 100644 --- a/components/style/stylesheets/rule_list.rs +++ b/components/style/stylesheets/rule_list.rs @@ -10,7 +10,7 @@ use crate::str::CssStringWriter; use crate::stylesheets::loader::StylesheetLoader; use crate::stylesheets::rule_parser::{InsertRuleContext, State}; use crate::stylesheets::stylesheet::StylesheetContents; -use crate::stylesheets::{CssRule, RulesMutateError, AllowImportRules}; +use crate::stylesheets::{AllowImportRules, CssRule, RulesMutateError}; #[cfg(feature = "gecko")] use malloc_size_of::{MallocShallowSizeOf, MallocSizeOfOps}; use servo_arc::{Arc, RawOffsetArc}; diff --git a/components/style/traversal.rs b/components/style/traversal.rs index 3811597084b..48e42656e86 100644 --- a/components/style/traversal.rs +++ b/components/style/traversal.rs @@ -694,9 +694,7 @@ where if let Some(ref values) = data.styles.primary { for image in &values.get_background().background_image.0 { let (name, arguments) = match *image { - Image::PaintWorklet(ref worklet) => { - (&worklet.name, &worklet.arguments) - }, + Image::PaintWorklet(ref worklet) => (&worklet.name, &worklet.arguments), _ => continue, }; let painter = match context.shared.registered_speculative_painters.get(name) { diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs index bafcf620530..cd1dc2888e8 100644 --- a/components/style/values/computed/font.rs +++ b/components/style/values/computed/font.rs @@ -227,7 +227,9 @@ impl ToCss for FontFamily { } } -#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)] +#[derive( + Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem, +)] #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] /// The name of a font family of choice pub struct FamilyName { @@ -270,7 +272,9 @@ impl ToCss for FamilyName { } } -#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)] +#[derive( + Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem, +)] #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] /// Font family names must either be given quoted as strings, /// or unquoted as a sequence of one or more identifiers. @@ -285,7 +289,9 @@ pub enum FontFamilyNameSyntax { Identifiers, } -#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToCss, ToComputedValue, ToResolvedValue, ToShmem)] +#[derive( + Clone, Debug, Eq, MallocSizeOf, PartialEq, ToCss, ToComputedValue, ToResolvedValue, ToShmem, +)] #[cfg_attr(feature = "servo", derive(Deserialize, Serialize, Hash))] /// A set of faces that vary in weight, width or slope. pub enum SingleFontFamily { @@ -301,7 +307,18 @@ pub enum SingleFontFamily { /// `gfxPlatformFontList.h`s ranged array and `gfxFontFamilyList`'s /// sSingleGenerics are updated as well. #[derive( - Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, Parse, ToCss, ToComputedValue, ToResolvedValue, ToShmem, + Clone, + Copy, + Debug, + Eq, + Hash, + MallocSizeOf, + PartialEq, + Parse, + ToCss, + ToComputedValue, + ToResolvedValue, + ToShmem, )] #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] #[repr(u8)] @@ -427,7 +444,9 @@ impl SingleFontFamily { } #[cfg(feature = "servo")] -#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)] +#[derive( + Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem, +)] /// A list of SingleFontFamily pub struct FontFamilyList(Box<[SingleFontFamily]>); diff --git a/components/style/values/computed/image.rs b/components/style/values/computed/image.rs index 4e16c2311d8..a2b59809021 100644 --- a/components/style/values/computed/image.rs +++ b/components/style/values/computed/image.rs @@ -13,7 +13,8 @@ use crate::values::computed::url::ComputedImageUrl; use crate::values::computed::NumberOrPercentage; use crate::values::computed::{Angle, Color, Context}; use crate::values::computed::{ - AngleOrPercentage, LengthPercentage, NonNegativeLength, NonNegativeLengthPercentage, ToComputedValue, + AngleOrPercentage, LengthPercentage, NonNegativeLength, NonNegativeLengthPercentage, + ToComputedValue, }; use crate::values::generics::image::{self as generic, GradientCompatMode}; use crate::values::specified::image::LineDirection as SpecifiedLineDirection; diff --git a/components/style/values/computed/length_percentage.rs b/components/style/values/computed/length_percentage.rs index 906f002ec3a..1889481ad84 100644 --- a/components/style/values/computed/length_percentage.rs +++ b/components/style/values/computed/length_percentage.rs @@ -34,8 +34,8 @@ use crate::Zero; use app_units::Au; use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; use serde::{Deserialize, Serialize}; -use std::fmt::{self, Write}; use std::borrow::Cow; +use std::fmt::{self, Write}; use style_traits::values::specified::AllowedNumericType; use style_traits::{CssWriter, ToCss}; @@ -202,7 +202,9 @@ impl LengthPercentage { fn to_calc_node(&self) -> Cow { match self.unpack() { Unpacked::Length(l) => Cow::Owned(CalcNode::Leaf(CalcLengthPercentageLeaf::Length(l))), - Unpacked::Percentage(p) => Cow::Owned(CalcNode::Leaf(CalcLengthPercentageLeaf::Percentage(p))), + Unpacked::Percentage(p) => { + Cow::Owned(CalcNode::Leaf(CalcLengthPercentageLeaf::Percentage(p))) + }, Unpacked::Calc(p) => Cow::Borrowed(&p.node), } } @@ -241,20 +243,20 @@ impl LengthPercentage { let mut node = v.to_calc_node().into_owned(); node.negate(); - let new_node = CalcNode::Sum(vec![ - CalcNode::Leaf(CalcLengthPercentageLeaf::Percentage(Percentage::hundred())), - node, - ].into()); + let new_node = CalcNode::Sum( + vec![ + CalcNode::Leaf(CalcLengthPercentageLeaf::Percentage(Percentage::hundred())), + node, + ] + .into(), + ); Self::new_calc(new_node, clamping_mode) } /// Constructs a `calc()` value. #[inline] - pub fn new_calc( - mut node: CalcNode, - clamping_mode: AllowedNumericType, - ) -> Self { + pub fn new_calc(mut node: CalcNode, clamping_mode: AllowedNumericType) -> Self { node.simplify_and_sort(); match node { @@ -267,13 +269,11 @@ impl LengthPercentage { Self::new_percent(Percentage(clamping_mode.clamp(p.0))) }, } - } - _ => { - Self::new_calc_unchecked(Box::new(CalcLengthPercentage { - clamping_mode, - node, - })) - } + }, + _ => Self::new_calc_unchecked(Box::new(CalcLengthPercentage { + clamping_mode, + node, + })), } } @@ -456,7 +456,7 @@ impl LengthPercentage { UnpackedMut::Calc(ref mut c) => { c.clamping_mode = AllowedNumericType::NonNegative; self - } + }, } } } @@ -577,7 +577,17 @@ impl<'de> Deserialize<'de> for LengthPercentage { } /// The leaves of a `` calc expression. -#[derive(Clone, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize, ToAnimatedZero, ToCss, ToResolvedValue)] +#[derive( + Clone, + Debug, + Deserialize, + MallocSizeOf, + PartialEq, + Serialize, + ToAnimatedZero, + ToCss, + ToResolvedValue, +)] #[allow(missing_docs)] #[repr(u8)] pub enum CalcLengthPercentageLeaf { @@ -609,8 +619,10 @@ impl PartialOrd for CalcLengthPercentageLeaf { match *self { Length(..) | Percentage(..) => {}, } - unsafe { debug_unreachable!("Forgot a branch?"); } - } + unsafe { + debug_unreachable!("Forgot a branch?"); + } + }, } } } @@ -670,7 +682,9 @@ impl calc::CalcNodeLeaf for CalcLengthPercentageLeaf { pub type CalcNode = calc::GenericCalcNode; /// The representation of a calc() function with mixed lengths and percentages. -#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize, ToAnimatedZero, ToResolvedValue, ToCss)] +#[derive( + Clone, Debug, Deserialize, MallocSizeOf, Serialize, ToAnimatedZero, ToResolvedValue, ToCss, +)] #[repr(C)] pub struct CalcLengthPercentage { #[animation(constant)] @@ -684,12 +698,15 @@ impl CalcLengthPercentage { #[inline] fn resolve(&self, basis: Length) -> Length { // unwrap() is fine because the conversion below is infallible. - let px = self.node.resolve(|l| { - Ok(match *l { - CalcLengthPercentageLeaf::Length(l) => l.px(), - CalcLengthPercentageLeaf::Percentage(ref p) => basis.px() * p.0, + let px = self + .node + .resolve(|l| { + Ok(match *l { + CalcLengthPercentageLeaf::Length(l) => l.px(), + CalcLengthPercentageLeaf::Percentage(ref p) => basis.px() * p.0, + }) }) - }).unwrap(); + .unwrap(); Length::new(self.clamping_mode.clamp(px)) } } @@ -726,24 +743,16 @@ impl specified::CalcLengthPercentage { use crate::values::specified::calc::Leaf; use crate::values::specified::length::NoCalcLength; - let node = self.node.map_leaves(|leaf| { - match *leaf { - Leaf::Percentage(p) => CalcLengthPercentageLeaf::Percentage(Percentage(p)), - Leaf::Length(l) => { - CalcLengthPercentageLeaf::Length(match l { - NoCalcLength::Absolute(ref abs) => { - zoom_fn(abs.to_computed_value(context)) - }, - NoCalcLength::FontRelative(ref fr) => { - fr.to_computed_value(context, base_size) - }, - other => other.to_computed_value(context), - }) - }, - Leaf::Number(..) | - Leaf::Angle(..) | - Leaf::Time(..) => unreachable!("Shouldn't have parsed"), - } + let node = self.node.map_leaves(|leaf| match *leaf { + Leaf::Percentage(p) => CalcLengthPercentageLeaf::Percentage(Percentage(p)), + Leaf::Length(l) => CalcLengthPercentageLeaf::Length(match l { + NoCalcLength::Absolute(ref abs) => zoom_fn(abs.to_computed_value(context)), + NoCalcLength::FontRelative(ref fr) => fr.to_computed_value(context, base_size), + other => other.to_computed_value(context), + }), + Leaf::Number(..) | Leaf::Angle(..) | Leaf::Time(..) => { + unreachable!("Shouldn't have parsed") + }, }); LengthPercentage::new_calc(node, self.clamping_mode) @@ -788,12 +797,12 @@ impl specified::CalcLengthPercentage { specified::CalcLengthPercentage { clamping_mode: computed.clamping_mode, - node: computed.node.map_leaves(|l| { - match l { - CalcLengthPercentageLeaf::Length(ref l) => Leaf::Length(NoCalcLength::from_px(l.px())), - CalcLengthPercentageLeaf::Percentage(ref p) => Leaf::Percentage(p.0), - } - }) + node: computed.node.map_leaves(|l| match l { + CalcLengthPercentageLeaf::Length(ref l) => { + Leaf::Length(NoCalcLength::from_px(l.px())) + }, + CalcLengthPercentageLeaf::Percentage(ref p) => Leaf::Percentage(p.0), + }), } } } @@ -819,7 +828,10 @@ impl Animate for LengthPercentage { one.mul_by(l as f32); other.mul_by(r as f32); - Self::new_calc(CalcNode::Sum(vec![one, other].into()), AllowedNumericType::All) + Self::new_calc( + CalcNode::Sum(vec![one, other].into()), + AllowedNumericType::All, + ) }, }) } diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index ec9424468c9..2a7a200dc95 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -21,9 +21,9 @@ use crate::media_queries::Device; use crate::properties; use crate::properties::{ComputedValues, LonghandId, StyleBuilder}; use crate::rule_cache::RuleCacheConditions; -use crate::{ArcSlice, Atom}; #[cfg(feature = "servo")] use crate::Prefix; +use crate::{ArcSlice, Atom}; use euclid::default::Size2D; use servo_arc::Arc; use std::cell::RefCell; diff --git a/components/style/values/computed/position.rs b/components/style/values/computed/position.rs index eb6463c2e10..3eff231de88 100644 --- a/components/style/values/computed/position.rs +++ b/components/style/values/computed/position.rs @@ -61,7 +61,7 @@ impl GenericPositionComponent for LengthPercentage { fn is_center(&self) -> bool { match self.to_percentage() { Some(Percentage(per)) => per == 0.5, - _ => false + _ => false, } } } diff --git a/components/style/values/generics/basic_shape.rs b/components/style/values/generics/basic_shape.rs index 111af31bfeb..745d6e07bbf 100644 --- a/components/style/values/generics/basic_shape.rs +++ b/components/style/values/generics/basic_shape.rs @@ -114,7 +114,10 @@ pub enum GenericClipPath { Url(U), #[css(function)] Path(Path), - Shape(Box, #[css(skip_if = "is_default")] ShapeGeometryBox), + Shape( + Box, + #[css(skip_if = "is_default")] ShapeGeometryBox, + ), #[animation(error)] Box(ShapeGeometryBox), } diff --git a/components/style/values/generics/calc.rs b/components/style/values/generics/calc.rs index f5014a7ad08..074dd97f4d0 100644 --- a/components/style/values/generics/calc.rs +++ b/components/style/values/generics/calc.rs @@ -7,14 +7,25 @@ //! [calc]: https://drafts.csswg.org/css-values/#calc-notation use crate::Zero; -use style_traits::{CssWriter, ToCss}; -use std::fmt::{self, Write}; -use std::{cmp, mem}; -use std::ops::Add; use smallvec::SmallVec; +use std::fmt::{self, Write}; +use std::ops::Add; +use std::{cmp, mem}; +use style_traits::{CssWriter, ToCss}; /// Whether we're a `min` or `max` function. -#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize, ToAnimatedZero, ToResolvedValue, ToShmem)] +#[derive( + Clone, + Copy, + Debug, + Deserialize, + MallocSizeOf, + PartialEq, + Serialize, + ToAnimatedZero, + ToResolvedValue, + ToShmem, +)] #[repr(u8)] pub enum MinMaxOp { /// `min()` @@ -50,7 +61,17 @@ pub enum SortKey { /// FIXME: This would be much more elegant if we used `Self` in the types below, /// but we can't because of https://github.com/serde-rs/serde/issues/1565. #[repr(u8)] -#[derive(Clone, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize, ToAnimatedZero, ToResolvedValue, ToShmem)] +#[derive( + Clone, + Debug, + Deserialize, + MallocSizeOf, + PartialEq, + Serialize, + ToAnimatedZero, + ToResolvedValue, + ToShmem, +)] pub enum GenericCalcNode { /// A leaf node. Leaf(L), @@ -73,7 +94,7 @@ pub enum GenericCalcNode { pub use self::GenericCalcNode as CalcNode; /// A trait that represents all the stuff a valid leaf of a calc expression. -pub trait CalcNodeLeaf : Clone + Sized + PartialOrd + PartialEq + ToCss { +pub trait CalcNodeLeaf: Clone + Sized + PartialOrd + PartialEq + ToCss { /// Whether this value is known-negative. fn is_negative(&self) -> bool; @@ -111,7 +132,9 @@ impl CalcNode { /// Tries to merge one sum to another, that is, perform `x` + `y`. fn try_sum_in_place(&mut self, other: &Self) -> Result<(), ()> { match (self, other) { - (&mut CalcNode::Leaf(ref mut one), &CalcNode::Leaf(ref other)) => one.try_sum_in_place(other), + (&mut CalcNode::Leaf(ref mut one), &CalcNode::Leaf(ref other)) => { + one.try_sum_in_place(other) + }, _ => Err(()), } } @@ -139,25 +162,35 @@ impl CalcNode { O: CalcNodeLeaf, F: FnMut(&L) -> O, { - children.iter().map(|c| c.map_leaves_internal(map)).collect() + children + .iter() + .map(|c| c.map_leaves_internal(map)) + .collect() } match *self { Self::Leaf(ref l) => CalcNode::Leaf(map(l)), Self::Sum(ref c) => CalcNode::Sum(map_children(c, map)), Self::MinMax(ref c, op) => CalcNode::MinMax(map_children(c, map), op), - Self::Clamp { ref min, ref center, ref max } => { + Self::Clamp { + ref min, + ref center, + ref max, + } => { let min = Box::new(min.map_leaves_internal(map)); let center = Box::new(center.map_leaves_internal(map)); let max = Box::new(max.map_leaves_internal(map)); CalcNode::Clamp { min, center, max } - } + }, } } /// Resolves the expression returning a value of `O`, given a function to /// turn a leaf into the relevant value. - pub fn resolve(&self, mut leaf_to_output_fn: impl FnMut(&L) -> Result) -> Result + pub fn resolve( + &self, + mut leaf_to_output_fn: impl FnMut(&L) -> Result, + ) -> Result where O: PartialOrd + PartialEq + Add + Zero, { @@ -192,7 +225,11 @@ impl CalcNode { } result }, - Self::Clamp { ref min, ref center, ref max } => { + Self::Clamp { + ref min, + ref center, + ref max, + } => { let min = min.resolve_internal(leaf_to_output_fn)?; let center = center.resolve_internal(leaf_to_output_fn)?; let max = max.resolve_internal(leaf_to_output_fn)?; @@ -432,7 +469,7 @@ impl CalcNode { }, Self::Leaf(ref mut l) => { l.simplify(); - } + }, } } diff --git a/components/style/values/generics/image.rs b/components/style/values/generics/image.rs index 28eba90bd4c..42d541dc6f2 100644 --- a/components/style/values/generics/image.rs +++ b/components/style/values/generics/image.rs @@ -341,8 +341,16 @@ where W: Write, { let (compat_mode, repeating) = match *self { - Gradient::Linear { compat_mode, repeating, .. } => (compat_mode, repeating), - Gradient::Radial { compat_mode, repeating, .. } => (compat_mode, repeating), + Gradient::Linear { + compat_mode, + repeating, + .. + } => (compat_mode, repeating), + Gradient::Radial { + compat_mode, + repeating, + .. + } => (compat_mode, repeating), Gradient::Conic { repeating, .. } => (GradientCompatMode::Modern, repeating), }; @@ -357,7 +365,12 @@ where } match *self { - Gradient::Linear { ref direction, ref items, compat_mode, .. } => { + Gradient::Linear { + ref direction, + ref items, + compat_mode, + .. + } => { dest.write_str("linear-gradient(")?; let mut skip_comma = if !direction.points_downwards(compat_mode) { direction.to_css(dest, compat_mode)?; @@ -373,7 +386,13 @@ where item.to_css(dest)?; } }, - Gradient::Radial { ref shape, ref position, ref items, compat_mode, .. } => { + Gradient::Radial { + ref shape, + ref position, + ref items, + compat_mode, + .. + } => { dest.write_str("radial-gradient(")?; let omit_shape = match *shape { EndingShape::Ellipse(Ellipse::Extent(ShapeExtent::Cover)) | @@ -412,7 +431,12 @@ where item.to_css(dest)?; } }, - Gradient::Conic { ref angle, ref position, ref items, .. } => { + Gradient::Conic { + ref angle, + ref position, + ref items, + .. + } => { dest.write_str("conic-gradient(")?; let omit_angle = angle.is_zero(); let omit_position = position.is_center(); diff --git a/components/style/values/specified/basic_shape.rs b/components/style/values/specified/basic_shape.rs index 0811fb627a7..b1782c5b294 100644 --- a/components/style/values/specified/basic_shape.rs +++ b/components/style/values/specified/basic_shape.rs @@ -126,12 +126,7 @@ impl Parse for ClipPath { return Ok(ClipPath::Url(url)); } - parse_shape_or_box( - context, - input, - ClipPath::Shape, - ClipPath::Box, - ) + parse_shape_or_box(context, input, ClipPath::Shape, ClipPath::Box) } } @@ -152,12 +147,7 @@ impl Parse for ShapeOutside { return Ok(ShapeOutside::Image(image)); } - parse_shape_or_box( - context, - input, - ShapeOutside::Shape, - ShapeOutside::Box, - ) + parse_shape_or_box(context, input, ShapeOutside::Shape, ShapeOutside::Box) } } diff --git a/components/style/values/specified/calc.rs b/components/style/values/specified/calc.rs index 5ee3a11f12a..9947fc7a8cc 100644 --- a/components/style/values/specified/calc.rs +++ b/components/style/values/specified/calc.rs @@ -15,8 +15,8 @@ use crate::values::specified::{self, Angle, Time}; use crate::values::{CSSFloat, CSSInteger}; use cssparser::{AngleOrNumber, CowRcStr, NumberOrPercentage, Parser, Token}; use smallvec::SmallVec; -use std::fmt::{self, Write}; use std::cmp; +use std::fmt::{self, Write}; use style_traits::values::specified::AllowedNumericType; use style_traits::{CssWriter, ParseError, SpecifiedValueInfo, StyleParseErrorKind, ToCss}; @@ -116,8 +116,10 @@ impl PartialOrd for Leaf { match *self { Length(..) | Percentage(..) | Angle(..) | Time(..) | Number(..) => {}, } - unsafe { debug_unreachable!("Forgot a branch?"); } - } + unsafe { + debug_unreachable!("Forgot a branch?"); + } + }, } } } @@ -126,8 +128,7 @@ impl generic::CalcNodeLeaf for Leaf { fn is_negative(&self) -> bool { match *self { Self::Length(ref l) => l.is_negative(), - Self::Percentage(n) | - Self::Number(n) => n < 0., + Self::Percentage(n) | Self::Number(n) => n < 0., Self::Angle(ref a) => a.degrees() < 0., Self::Time(ref t) => t.seconds() < 0., } @@ -215,8 +216,10 @@ impl generic::CalcNodeLeaf for Leaf { match *other { Number(..) | Percentage(..) | Angle(..) | Time(..) | Length(..) => {}, } - unsafe { debug_unreachable!(); } - } + unsafe { + debug_unreachable!(); + } + }, } Ok(()) @@ -252,11 +255,9 @@ impl CalcNode { value, ref unit, .. }, CalcUnit::LengthPercentage, - ) => { - match NoCalcLength::parse_dimension(context, value, unit) { - Ok(l) => Ok(CalcNode::Leaf(Leaf::Length(l))), - Err(()) => Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)), - } + ) => match NoCalcLength::parse_dimension(context, value, unit) { + Ok(l) => Ok(CalcNode::Leaf(Leaf::Length(l))), + Err(()) => Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)), }, ( &Token::Dimension { @@ -266,7 +267,9 @@ impl CalcNode { ) => { match Angle::parse_dimension(value, unit, /* from_calc = */ true) { Ok(a) => Ok(CalcNode::Leaf(Leaf::Angle(a))), - Err(()) => Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)), + Err(()) => { + Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)) + }, } }, ( @@ -277,7 +280,9 @@ impl CalcNode { ) => { match Time::parse_dimension(value, unit, /* from_calc = */ true) { Ok(t) => Ok(CalcNode::Leaf(Leaf::Time(t))), - Err(()) => Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)), + Err(()) => { + Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)) + }, } }, (&Token::Percentage { unit_value, .. }, CalcUnit::LengthPercentage) | @@ -328,10 +333,9 @@ impl CalcNode { // // Consider adding an API to cssparser to specify the // initial vector capacity? - let arguments = input - .parse_comma_separated(|input| { - Self::parse_argument(context, input, expected_unit) - })?; + let arguments = input.parse_comma_separated(|input| { + Self::parse_argument(context, input, expected_unit) + })?; let op = match function { MathFunction::Min => MinMaxOp::Min, @@ -474,43 +478,35 @@ impl CalcNode { /// Tries to simplify this expression into a `