Skip to content

Commit

Permalink
Require Clone for SelectorImpl so that all the types that are paramet…
Browse files Browse the repository at this point in the history
…erized on it can derive(Clone).

It's not clear to me why this is a requirement, but it seems to be one.

MozReview-Commit-ID: JM0DKjHHfT
  • Loading branch information
bholley committed Apr 27, 2017
1 parent 2df9dc2 commit 32c624e
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions components/selectors/parser.rs
Expand Up @@ -42,7 +42,11 @@ macro_rules! with_all_bounds {

/// This trait allows to define the parser implementation in regards
/// of pseudo-classes/elements
pub trait SelectorImpl: Sized {
///
/// NB: We need Clone so that we can derive(Clone) on struct with that
/// are parameterized on SelectorImpl. See
/// https://github.com/rust-lang/rust/issues/26925
pub trait SelectorImpl: Clone + Sized {
type AttrValue: $($InSelector)*;
type Identifier: $($InSelector)* + PrecomputedHash;
type ClassName: $($InSelector)* + PrecomputedHash;
Expand Down Expand Up @@ -321,22 +325,12 @@ impl<Impl: SelectorImpl> ComplexSelector<Impl> {
}
}

#[derive(Clone)]
pub struct SelectorIter<'a, Impl: 'a + SelectorImpl> {
iter: Rev<slice::Iter<'a, Component<Impl>>>,
next_combinator: Option<Combinator>,
}

// NB: Deriving this doesn't work for some reason, because it expects Impl to
// implement Clone.
impl<'a, Impl: 'a + SelectorImpl> Clone for SelectorIter<'a, Impl> {
fn clone(&self) -> Self {
SelectorIter {
iter: self.iter.clone(),
next_combinator: self.next_combinator.clone(),
}
}
}

impl<'a, Impl: 'a + SelectorImpl> SelectorIter<'a, Impl> {
/// Prepares this iterator to point to the next sequence to the left,
/// returning the combinator if the sequence was found.
Expand Down

0 comments on commit 32c624e

Please sign in to comment.