Skip to content
This repository was archived by the owner on May 28, 2024. It is now read-only.

Commit f283d1a

Browse files
committed
Make BorrowedNamespace generic.
1 parent 98fe8d5 commit f283d1a

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/matching.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::sync::Arc;
77
use bloom::BloomFilter;
88
use smallvec::VecLike;
99
use quickersort::sort_by;
10-
use string_cache::Atom;
10+
use string_cache::{self, Atom};
1111

1212
use parser::{CaseSensitivity, Combinator, CompoundSelector, LocalName};
1313
use parser::{SimpleSelector, Selector, SelectorImpl};
@@ -548,7 +548,8 @@ pub fn matches_simple_selector<E>(selector: &SimpleSelector<E::Impl>,
548548
element.get_local_name() == *name
549549
}
550550
SimpleSelector::Namespace(ref namespace) => {
551-
element.get_namespace() == *namespace
551+
// UFCS to work around https://github.com/rust-lang/rust/issues/34792
552+
PartialEq::<string_cache::Namespace>::eq(&element.get_namespace(), namespace)
552553
}
553554
// TODO: case-sensitivity depends on the document type and quirks mode
554555
SimpleSelector::ID(ref id) => {
@@ -681,7 +682,7 @@ fn matches_generic_nth_child<E>(element: &E,
681682

682683
if is_of_type {
683684
if element.get_local_name() == *sibling.get_local_name() &&
684-
element.get_namespace() == *sibling.get_namespace() {
685+
element.get_namespace() == sibling.get_namespace() {
685686
index += 1;
686687
}
687688
} else {

src/parser.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::hash::Hash;
1010
use std::sync::Arc;
1111

1212
use cssparser::{Token, Parser, parse_nth};
13-
use string_cache::{Atom, Namespace};
13+
use string_cache::{self, Atom, Namespace};
1414

1515
use HashMap;
1616

@@ -22,9 +22,14 @@ use HashMap;
2222
#[cfg(not(feature = "heap_size"))] pub trait MaybeHeapSizeOf {}
2323
#[cfg(not(feature = "heap_size"))] impl<T> MaybeHeapSizeOf for T {}
2424

25+
pub trait BorrowedNamespaceConstructor<'a> {
26+
type BorrowedNamespace: PartialEq<string_cache::Namespace> + PartialEq;
27+
}
28+
2529
/// This trait allows to define the parser implementation in regards
2630
/// of pseudo-classes/elements
27-
pub trait SelectorImpl {
31+
pub trait SelectorImpl
32+
where Self: for<'a> BorrowedNamespaceConstructor<'a> {
2833
type AttrValue: Clone + Debug + MaybeHeapSizeOf + PartialEq;
2934

3035
fn attr_string_from_cow_str(s: Cow<str>) -> Self::AttrValue;
@@ -675,7 +680,7 @@ pub mod tests {
675680
use std::borrow::Cow;
676681
use std::sync::Arc;
677682
use cssparser::Parser;
678-
use string_cache::Atom;
683+
use string_cache::{self, Atom};
679684
use super::*;
680685

681686
#[derive(PartialEq, Clone, Debug)]
@@ -693,6 +698,10 @@ pub mod tests {
693698
#[derive(PartialEq, Debug)]
694699
pub struct DummySelectorImpl;
695700

701+
impl<'a> BorrowedNamespaceConstructor<'a> for DummySelectorImpl {
702+
type BorrowedNamespace = string_cache::BorrowedNamespace<'a>;
703+
}
704+
696705
impl SelectorImpl for DummySelectorImpl {
697706
type AttrValue = String;
698707
type NonTSPseudoClass = PseudoClass;

src/tree.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
//! style.
77
88
use matching::ElementFlags;
9-
use parser::{AttrSelector, MaybeHeapSizeOf, SelectorImpl};
9+
use parser::{AttrSelector, MaybeHeapSizeOf, SelectorImpl, BorrowedNamespaceConstructor};
1010
use std::ascii::AsciiExt;
1111
use std::fmt::Debug;
12-
use string_cache::{Atom, BorrowedAtom, BorrowedNamespace};
12+
use string_cache::{Atom, BorrowedAtom};
1313

1414
/// The definition of whitespace per CSS Selectors Level 3 § 4.
1515
pub static SELECTOR_WHITESPACE: &'static [char] = &[' ', '\t', '\n', '\r', '\x0C'];
@@ -101,7 +101,7 @@ pub trait Element: MatchAttr + Sized {
101101

102102
fn is_html_element_in_html_document(&self) -> bool;
103103
fn get_local_name<'a>(&'a self) -> BorrowedAtom<'a>;
104-
fn get_namespace<'a>(&'a self) -> BorrowedNamespace<'a>;
104+
fn get_namespace<'a>(&'a self) -> <Self::Impl as BorrowedNamespaceConstructor<'a>>::BorrowedNamespace;
105105

106106
fn match_non_ts_pseudo_class(&self, pc: <Self::Impl as SelectorImpl>::NonTSPseudoClass) -> bool;
107107

0 commit comments

Comments
 (0)