style: Add diagnostics.

Bug: 1416282
Reviewed-by: xidorn
MozReview-Commit-ID: GTnFyZnXR84
This commit is contained in:
Emilio Cobos Álvarez 2018-06-10 01:08:43 +02:00
parent d65b29da27
commit 572a93142f
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 19 additions and 8 deletions

View file

@ -36,6 +36,7 @@ use std::slice;
/// (from left to right). Once the process is complete, callers should invoke /// (from left to right). Once the process is complete, callers should invoke
/// build(), which transforms the contents of the SelectorBuilder into a heap- /// build(), which transforms the contents of the SelectorBuilder into a heap-
/// allocated Selector and leaves the builder in a drained state. /// allocated Selector and leaves the builder in a drained state.
#[derive(Debug)]
pub struct SelectorBuilder<Impl: SelectorImpl> { pub struct SelectorBuilder<Impl: SelectorImpl> {
/// The entire sequence of simple selectors, from left to right, without combinators. /// The entire sequence of simple selectors, from left to right, without combinators.
/// ///
@ -104,7 +105,7 @@ impl<Impl: SelectorImpl> SelectorBuilder<Impl> {
parsed_slotted: bool, parsed_slotted: bool,
) -> ThinArc<SpecificityAndFlags, Component<Impl>> { ) -> ThinArc<SpecificityAndFlags, Component<Impl>> {
// Compute the specificity and flags. // Compute the specificity and flags.
let mut spec = SpecificityAndFlags(specificity(self.simple_selectors.iter())); let mut spec = SpecificityAndFlags(specificity(&*self, self.simple_selectors.iter()));
if parsed_pseudo { if parsed_pseudo {
spec.0 |= HAS_PSEUDO_BIT; spec.0 |= HAS_PSEUDO_BIT;
} }
@ -268,25 +269,35 @@ impl From<Specificity> for u32 {
} }
} }
fn specificity<Impl>(iter: slice::Iter<Component<Impl>>) -> u32 fn specificity<Impl>(builder: &SelectorBuilder<Impl>, iter: slice::Iter<Component<Impl>>) -> u32
where where
Impl: SelectorImpl, Impl: SelectorImpl,
{ {
complex_selector_specificity(iter).into() complex_selector_specificity(builder, iter).into()
} }
fn complex_selector_specificity<Impl>(mut iter: slice::Iter<Component<Impl>>) -> Specificity fn complex_selector_specificity<Impl>(
builder: &SelectorBuilder<Impl>,
mut iter: slice::Iter<Component<Impl>>,
) -> Specificity
where where
Impl: SelectorImpl, Impl: SelectorImpl,
{ {
fn simple_selector_specificity<Impl>( fn simple_selector_specificity<Impl>(
builder: &SelectorBuilder<Impl>,
simple_selector: &Component<Impl>, simple_selector: &Component<Impl>,
specificity: &mut Specificity, specificity: &mut Specificity,
) where ) where
Impl: SelectorImpl, Impl: SelectorImpl,
{ {
match *simple_selector { match *simple_selector {
Component::Combinator(..) => unreachable!(), Component::Combinator(ref combinator) => {
unreachable!(
"Found combinator {:?} in simple selectors vector? {:?}",
combinator,
builder,
);
}
// FIXME(emilio): Spec doesn't define any particular specificity for // FIXME(emilio): Spec doesn't define any particular specificity for
// ::slotted(), so apply the general rule for pseudos per: // ::slotted(), so apply the general rule for pseudos per:
// //
@ -326,7 +337,7 @@ where
}, },
Component::Negation(ref negated) => { Component::Negation(ref negated) => {
for ss in negated.iter() { for ss in negated.iter() {
simple_selector_specificity(&ss, specificity); simple_selector_specificity(builder, &ss, specificity);
} }
}, },
} }
@ -334,7 +345,7 @@ where
let mut specificity = Default::default(); let mut specificity = Default::default();
for simple_selector in &mut iter { for simple_selector in &mut iter {
simple_selector_specificity(&simple_selector, &mut specificity); simple_selector_specificity(builder, &simple_selector, &mut specificity);
} }
specificity specificity
} }

View file

@ -92,7 +92,7 @@ macro_rules! with_all_bounds {
/// NB: We need Clone so that we can derive(Clone) on struct with that /// NB: We need Clone so that we can derive(Clone) on struct with that
/// are parameterized on SelectorImpl. See /// are parameterized on SelectorImpl. See
/// <https://github.com/rust-lang/rust/issues/26925> /// <https://github.com/rust-lang/rust/issues/26925>
pub trait SelectorImpl: Clone + Sized + 'static { pub trait SelectorImpl: Clone + Debug + Sized + 'static {
type ExtraMatchingData: Sized + Default + 'static; type ExtraMatchingData: Sized + Default + 'static;
type AttrValue: $($InSelector)*; type AttrValue: $($InSelector)*;
type Identifier: $($InSelector)*; type Identifier: $($InSelector)*;