From 4ef0f39c7877ee98c0d7fe826badd63e2bb97d6d Mon Sep 17 00:00:00 2001 From: Cameron Zwarich Date: Tue, 30 Sep 2014 20:29:10 -0700 Subject: [PATCH 1/8] Remove a prefix from a method name by manually resolving methods --- components/layout/wrapper.rs | 10 ++++++++-- components/script/dom/node.rs | 2 +- components/style/node.rs | 3 +-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 4fdec61230c1..fe60532f3064 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -213,8 +213,14 @@ impl<'ln> LayoutNode<'ln> { /// Returns an iterator over this node's children. pub fn children(&self) -> LayoutNodeChildrenIterator<'ln> { + // FIXME(zwarich): Remove this when UFCS lands and there is a better way + // of disambiguating methods. + fn first_child(this: &T) -> Option { + this.first_child() + } + LayoutNodeChildrenIterator { - current_node: self.first_child(), + current_node: first_child(self), } } @@ -247,7 +253,7 @@ impl<'ln> TNode<'ln, LayoutElement<'ln>> for LayoutNode<'ln> { } } - fn tnode_first_child(&self) -> Option> { + fn first_child(&self) -> Option> { unsafe { self.node.first_child_ref().map(|node| self.new_with_this_lifetime(&node)) } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 85f7f27bc1c9..554f3686e034 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -2039,7 +2039,7 @@ impl<'a> style::TNode<'a, JSRef<'a, Element>> for JSRef<'a, Node> { (self as &NodeHelpers).parent_node().map(|node| *node.root()) } - fn tnode_first_child(&self) -> Option> { + fn first_child(&self) -> Option> { (self as &NodeHelpers).first_child().map(|node| *node.root()) } diff --git a/components/style/node.rs b/components/style/node.rs index 749e9fbe6ea4..d2624c241feb 100644 --- a/components/style/node.rs +++ b/components/style/node.rs @@ -11,8 +11,7 @@ use string_cache::{Atom, Namespace}; pub trait TNode<'a, E: TElement<'a>> : Clone { fn parent_node(&self) -> Option; - /// Name is prefixed to avoid a conflict with TLayoutNode. - fn tnode_first_child(&self) -> Option; + fn first_child(&self) -> Option; fn prev_sibling(&self) -> Option; fn next_sibling(&self) -> Option; fn is_document(&self) -> bool; From be9618d55bd48be45e55b2c49d0df12f953f1fe5 Mon Sep 17 00:00:00 2001 From: Cameron Zwarich Date: Tue, 30 Sep 2014 20:33:40 -0700 Subject: [PATCH 2/8] Add a lifetime parameter to the ElementHelper trait This refines the lifetime used in get_local_name / get_namespace and makes it independent of the lifetime on the &self parameter. --- components/script/dom/element.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index c734ad89161b..821ac1f99094 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -237,26 +237,26 @@ impl LayoutElementHelpers for JS { } } -pub trait ElementHelpers { +pub trait ElementHelpers<'a> { fn html_element_in_html_document(self) -> bool; - fn get_local_name<'a>(&'a self) -> &'a Atom; - fn get_namespace<'a>(&'a self) -> &'a Namespace; + fn get_local_name(&self) -> &'a Atom; + fn get_namespace(&self) -> &'a Namespace; fn summarize(self) -> Vec; fn is_void(self) -> bool; } -impl<'a> ElementHelpers for JSRef<'a, Element> { +impl<'a> ElementHelpers<'a> for JSRef<'a, Element> { fn html_element_in_html_document(self) -> bool { let node: JSRef = NodeCast::from_ref(self); self.namespace == ns!(HTML) && node.is_in_html_doc() } - fn get_local_name<'a>(&'a self) -> &'a Atom { - &self.deref().local_name + fn get_local_name(&self) -> &'a Atom { + &self.extended_deref().local_name } - fn get_namespace<'a>(&'a self) -> &'a Namespace { - &self.deref().namespace + fn get_namespace(&self) -> &'a Namespace { + &self.extended_deref().namespace } fn summarize(self) -> Vec { From e894499c17b920494c008c30566fc1465aab4671 Mon Sep 17 00:00:00 2001 From: Cameron Zwarich Date: Tue, 30 Sep 2014 20:36:38 -0700 Subject: [PATCH 3/8] Disambiguate methods without using trait objects --- components/script/dom/element.rs | 24 ++++++++++++++-- components/script/dom/node.rs | 48 ++++++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 821ac1f99094..a0d843a4dbaa 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -966,10 +966,22 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> { } } fn get_local_name<'b>(&'b self) -> &'b Atom { - (self as &ElementHelpers).get_local_name() + // FIXME(zwarich): Remove this when UFCS lands and there is a better way + // of disambiguating methods. + fn get_local_name<'a, T: ElementHelpers<'a>>(this: T) -> &'a Atom { + this.get_local_name() + } + + get_local_name(*self) } fn get_namespace<'b>(&'b self) -> &'b Namespace { - (self as &ElementHelpers).get_namespace() + // FIXME(zwarich): Remove this when UFCS lands and there is a better way + // of disambiguating methods. + fn get_namespace<'a, T: ElementHelpers<'a>>(this: T) -> &'a Namespace { + this.get_namespace() + } + + get_namespace(*self) } fn get_hover_state(&self) -> bool { let node: JSRef = NodeCast::from_ref(*self); @@ -993,6 +1005,12 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> { node.get_enabled_state() } fn has_class(&self, name: &str) -> bool { - (self as &AttributeHandlers).has_class(name) + // FIXME(zwarich): Remove this when UFCS lands and there is a better way + // of disambiguating methods. + fn has_class(this: T, name: &str) -> bool { + this.has_class(name) + } + + has_class(*self, name) } } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 554f3686e034..6067b9016139 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -2036,27 +2036,63 @@ impl<'a> VirtualMethods for JSRef<'a, Node> { impl<'a> style::TNode<'a, JSRef<'a, Element>> for JSRef<'a, Node> { fn parent_node(&self) -> Option> { - (self as &NodeHelpers).parent_node().map(|node| *node.root()) + // FIXME(zwarich): Remove this when UFCS lands and there is a better way + // of disambiguating methods. + fn parent_node<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> Option> { + this.parent_node() + } + + parent_node(*self).map(|node| *node.root()) } fn first_child(&self) -> Option> { - (self as &NodeHelpers).first_child().map(|node| *node.root()) + // FIXME(zwarich): Remove this when UFCS lands and there is a better way + // of disambiguating methods. + fn first_child<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> Option> { + this.first_child() + } + + first_child(*self).map(|node| *node.root()) } fn prev_sibling(&self) -> Option> { - (self as &NodeHelpers).prev_sibling().map(|node| *node.root()) + // FIXME(zwarich): Remove this when UFCS lands and there is a better way + // of disambiguating methods. + fn prev_sibling<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> Option> { + this.prev_sibling() + } + + prev_sibling(*self).map(|node| *node.root()) } fn next_sibling(&self) -> Option> { - (self as &NodeHelpers).next_sibling().map(|node| *node.root()) + // FIXME(zwarich): Remove this when UFCS lands and there is a better way + // of disambiguating methods. + fn next_sibling<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> Option> { + this.next_sibling() + } + + next_sibling(*self).map(|node| *node.root()) } fn is_document(&self) -> bool { - (self as &NodeHelpers).is_document() + // FIXME(zwarich): Remove this when UFCS lands and there is a better way + // of disambiguating methods. + fn is_document<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> bool { + this.is_document() + } + + is_document(*self) } fn is_element(&self) -> bool { - (self as &NodeHelpers).is_element() + // FIXME(zwarich): Remove this when UFCS lands and there is a better way + // of disambiguating methods. + fn is_element<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> bool { + this.is_element() + } + + is_element(*self) } fn as_element(&self) -> JSRef<'a, Element> { From ccc5d976f7c56d9f42c39667a5844318ef618df2 Mon Sep 17 00:00:00 2001 From: Cameron Zwarich Date: Tue, 30 Sep 2014 20:49:35 -0700 Subject: [PATCH 4/8] Refine a lifetime parameter on TElement's get_local_name --- components/layout/wrapper.rs | 4 ++-- components/script/dom/element.rs | 4 ++-- components/style/node.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index fe60532f3064..996e1070b1b0 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -395,12 +395,12 @@ impl<'le> LayoutElement<'le> { impl<'le> TElement<'le> for LayoutElement<'le> { #[inline] - fn get_local_name<'a>(&'a self) -> &'a Atom { + fn get_local_name(&self) -> &'le Atom { &self.element.local_name } #[inline] - fn get_namespace<'a>(&'a self) -> &'a Namespace { + fn get_namespace(&self) -> &'le Namespace { &self.element.namespace } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index a0d843a4dbaa..7709c86bc115 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -965,7 +965,7 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> { _ => None, } } - fn get_local_name<'b>(&'b self) -> &'b Atom { + fn get_local_name(&self) -> &'a Atom { // FIXME(zwarich): Remove this when UFCS lands and there is a better way // of disambiguating methods. fn get_local_name<'a, T: ElementHelpers<'a>>(this: T) -> &'a Atom { @@ -974,7 +974,7 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> { get_local_name(*self) } - fn get_namespace<'b>(&'b self) -> &'b Namespace { + fn get_namespace(&self) -> &'a Namespace { // FIXME(zwarich): Remove this when UFCS lands and there is a better way // of disambiguating methods. fn get_namespace<'a, T: ElementHelpers<'a>>(this: T) -> &'a Namespace { diff --git a/components/style/node.rs b/components/style/node.rs index d2624c241feb..7720f37c30a3 100644 --- a/components/style/node.rs +++ b/components/style/node.rs @@ -24,8 +24,8 @@ pub trait TNode<'a, E: TElement<'a>> : Clone { pub trait TElement<'a> { fn get_attr(&self, namespace: &Namespace, attr: &str) -> Option<&'a str>; fn get_link(&self) -> Option<&'a str>; - fn get_local_name<'b>(&'b self) -> &'b Atom; - fn get_namespace<'b>(&'b self) -> &'b Namespace; + fn get_local_name(&self) -> &'a Atom; + fn get_namespace(&self) -> &'a Namespace; fn get_hover_state(&self) -> bool; fn get_id(&self) -> Option; fn get_disabled_state(&self) -> bool; From 1581c383bb5171198004bcd29227d0b7de080225 Mon Sep 17 00:00:00 2001 From: Cameron Zwarich Date: Tue, 30 Sep 2014 21:25:46 -0700 Subject: [PATCH 5/8] Convert the remaining ElementHelpers methods to take self --- components/script/dom/element.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 7709c86bc115..030037521adb 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -239,8 +239,8 @@ impl LayoutElementHelpers for JS { pub trait ElementHelpers<'a> { fn html_element_in_html_document(self) -> bool; - fn get_local_name(&self) -> &'a Atom; - fn get_namespace(&self) -> &'a Namespace; + fn get_local_name(self) -> &'a Atom; + fn get_namespace(self) -> &'a Namespace; fn summarize(self) -> Vec; fn is_void(self) -> bool; } @@ -251,11 +251,11 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> { self.namespace == ns!(HTML) && node.is_in_html_doc() } - fn get_local_name(&self) -> &'a Atom { + fn get_local_name(self) -> &'a Atom { &self.extended_deref().local_name } - fn get_namespace(&self) -> &'a Namespace { + fn get_namespace(self) -> &'a Namespace { &self.extended_deref().namespace } From 63314208c0967c7f23b1387742f26d2f409a05f2 Mon Sep 17 00:00:00 2001 From: Cameron Zwarich Date: Tue, 30 Sep 2014 20:54:19 -0700 Subject: [PATCH 6/8] Add Copy bounds to TNode / TElement --- components/style/node.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/style/node.rs b/components/style/node.rs index 7720f37c30a3..cb267a719667 100644 --- a/components/style/node.rs +++ b/components/style/node.rs @@ -9,7 +9,7 @@ use selectors::AttrSelector; use string_cache::{Atom, Namespace}; -pub trait TNode<'a, E: TElement<'a>> : Clone { +pub trait TNode<'a, E: TElement<'a>> : Clone + Copy { fn parent_node(&self) -> Option; fn first_child(&self) -> Option; fn prev_sibling(&self) -> Option; @@ -21,7 +21,7 @@ pub trait TNode<'a, E: TElement<'a>> : Clone { fn is_html_element_in_html_document(&self) -> bool; } -pub trait TElement<'a> { +pub trait TElement<'a> : Copy { fn get_attr(&self, namespace: &Namespace, attr: &str) -> Option<&'a str>; fn get_link(&self) -> Option<&'a str>; fn get_local_name(&self) -> &'a Atom; From 79b4ec99b453011781c13d401514377be9b6f3cd Mon Sep 17 00:00:00 2001 From: Cameron Zwarich Date: Tue, 30 Sep 2014 21:00:07 -0700 Subject: [PATCH 7/8] Convert TNode / TElement to use self methods rather than &self --- components/layout/wrapper.rs | 36 ++++++++++++++++---------------- components/script/dom/element.rs | 32 ++++++++++++++-------------- components/script/dom/node.rs | 34 +++++++++++++++--------------- components/style/node.rs | 36 ++++++++++++++++---------------- 4 files changed, 69 insertions(+), 69 deletions(-) diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 996e1070b1b0..18fd74fca9b5 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -247,25 +247,25 @@ impl<'ln> LayoutNode<'ln> { } impl<'ln> TNode<'ln, LayoutElement<'ln>> for LayoutNode<'ln> { - fn parent_node(&self) -> Option> { + fn parent_node(self) -> Option> { unsafe { self.node.parent_node_ref().map(|node| self.new_with_this_lifetime(&node)) } } - fn first_child(&self) -> Option> { + fn first_child(self) -> Option> { unsafe { self.node.first_child_ref().map(|node| self.new_with_this_lifetime(&node)) } } - fn prev_sibling(&self) -> Option> { + fn prev_sibling(self) -> Option> { unsafe { self.node.prev_sibling_ref().map(|node| self.new_with_this_lifetime(&node)) } } - fn next_sibling(&self) -> Option> { + fn next_sibling(self) -> Option> { unsafe { self.node.next_sibling_ref().map(|node| self.new_with_this_lifetime(&node)) } @@ -273,7 +273,7 @@ impl<'ln> TNode<'ln, LayoutElement<'ln>> for LayoutNode<'ln> { /// If this is an element, accesses the element data. Fails if this is not an element node. #[inline] - fn as_element(&self) -> LayoutElement<'ln> { + fn as_element(self) -> LayoutElement<'ln> { unsafe { assert!(self.node.is_element_for_layout()); let elem: JS = self.node.transmute_copy(); @@ -284,15 +284,15 @@ impl<'ln> TNode<'ln, LayoutElement<'ln>> for LayoutNode<'ln> { } } - fn is_element(&self) -> bool { + fn is_element(self) -> bool { self.node_is_element() } - fn is_document(&self) -> bool { + fn is_document(self) -> bool { self.node_is_document() } - fn match_attr(&self, attr: &AttrSelector, test: |&str| -> bool) -> bool { + fn match_attr(self, attr: &AttrSelector, test: |&str| -> bool) -> bool { assert!(self.is_element()) let name = if self.is_html_element_in_html_document() { attr.lower_name.as_slice() @@ -310,7 +310,7 @@ impl<'ln> TNode<'ln, LayoutElement<'ln>> for LayoutNode<'ln> { } } - fn is_html_element_in_html_document(&self) -> bool { + fn is_html_element_in_html_document(self) -> bool { unsafe { self.is_element() && { let element: JS = self.node.transmute_copy(); @@ -395,21 +395,21 @@ impl<'le> LayoutElement<'le> { impl<'le> TElement<'le> for LayoutElement<'le> { #[inline] - fn get_local_name(&self) -> &'le Atom { + fn get_local_name(self) -> &'le Atom { &self.element.local_name } #[inline] - fn get_namespace(&self) -> &'le Namespace { + fn get_namespace(self) -> &'le Namespace { &self.element.namespace } #[inline] - fn get_attr(&self, namespace: &Namespace, name: &str) -> Option<&'le str> { + fn get_attr(self, namespace: &Namespace, name: &str) -> Option<&'le str> { unsafe { self.element.get_attr_val_for_layout(namespace, name) } } - fn get_link(&self) -> Option<&'le str> { + fn get_link(self) -> Option<&'le str> { // FIXME: This is HTML only. match self.element.node.type_id_for_layout() { // http://www.whatwg.org/specs/web-apps/current-work/multipage/selectors.html# @@ -423,30 +423,30 @@ impl<'le> TElement<'le> for LayoutElement<'le> { } } - fn get_hover_state(&self) -> bool { + fn get_hover_state(self) -> bool { unsafe { self.element.node.get_hover_state_for_layout() } } #[inline] - fn get_id(&self) -> Option { + fn get_id(self) -> Option { unsafe { self.element.get_attr_atom_for_layout(&ns!(""), "id") } } - fn get_disabled_state(&self) -> bool { + fn get_disabled_state(self) -> bool { unsafe { self.element.node.get_disabled_state_for_layout() } } - fn get_enabled_state(&self) -> bool { + fn get_enabled_state(self) -> bool { unsafe { self.element.node.get_enabled_state_for_layout() } } - fn has_class(&self, name: &str) -> bool { + fn has_class(self, name: &str) -> bool { unsafe { self.element.has_class_for_layout(name) } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 030037521adb..a993e24eb620 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -948,14 +948,14 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { } impl<'a> style::TElement<'a> for JSRef<'a, Element> { - fn get_attr(&self, namespace: &Namespace, attr: &str) -> Option<&'a str> { + fn get_attr(self, namespace: &Namespace, attr: &str) -> Option<&'a str> { self.get_attribute(namespace.clone(), attr).root().map(|attr| { unsafe { mem::transmute(attr.deref().value().as_slice()) } }) } - fn get_link(&self) -> Option<&'a str> { + fn get_link(self) -> Option<&'a str> { // FIXME: This is HTML only. - let node: JSRef = NodeCast::from_ref(*self); + let node: JSRef = NodeCast::from_ref(self); match node.type_id() { // http://www.whatwg.org/specs/web-apps/current-work/multipage/selectors.html# // selector-link @@ -965,29 +965,29 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> { _ => None, } } - fn get_local_name(&self) -> &'a Atom { + fn get_local_name(self) -> &'a Atom { // FIXME(zwarich): Remove this when UFCS lands and there is a better way // of disambiguating methods. fn get_local_name<'a, T: ElementHelpers<'a>>(this: T) -> &'a Atom { this.get_local_name() } - get_local_name(*self) + get_local_name(self) } - fn get_namespace(&self) -> &'a Namespace { + fn get_namespace(self) -> &'a Namespace { // FIXME(zwarich): Remove this when UFCS lands and there is a better way // of disambiguating methods. fn get_namespace<'a, T: ElementHelpers<'a>>(this: T) -> &'a Namespace { this.get_namespace() } - get_namespace(*self) + get_namespace(self) } - fn get_hover_state(&self) -> bool { - let node: JSRef = NodeCast::from_ref(*self); + fn get_hover_state(self) -> bool { + let node: JSRef = NodeCast::from_ref(self); node.get_hover_state() } - fn get_id<'a>(&self) -> Option { + fn get_id<'a>(self) -> Option { self.get_attribute(ns!(""), "id").map(|attr| { let attr = attr.root(); match *attr.value() { @@ -996,21 +996,21 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> { } }) } - fn get_disabled_state(&self) -> bool { - let node: JSRef = NodeCast::from_ref(*self); + fn get_disabled_state(self) -> bool { + let node: JSRef = NodeCast::from_ref(self); node.get_disabled_state() } - fn get_enabled_state(&self) -> bool { - let node: JSRef = NodeCast::from_ref(*self); + fn get_enabled_state(self) -> bool { + let node: JSRef = NodeCast::from_ref(self); node.get_enabled_state() } - fn has_class(&self, name: &str) -> bool { + fn has_class(self, name: &str) -> bool { // FIXME(zwarich): Remove this when UFCS lands and there is a better way // of disambiguating methods. fn has_class(this: T, name: &str) -> bool { this.has_class(name) } - has_class(*self, name) + has_class(self, name) } } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 6067b9016139..b533b5254fd9 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -2035,73 +2035,73 @@ impl<'a> VirtualMethods for JSRef<'a, Node> { } impl<'a> style::TNode<'a, JSRef<'a, Element>> for JSRef<'a, Node> { - fn parent_node(&self) -> Option> { + fn parent_node(self) -> Option> { // FIXME(zwarich): Remove this when UFCS lands and there is a better way // of disambiguating methods. fn parent_node<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> Option> { this.parent_node() } - parent_node(*self).map(|node| *node.root()) + parent_node(self).map(|node| *node.root()) } - fn first_child(&self) -> Option> { + fn first_child(self) -> Option> { // FIXME(zwarich): Remove this when UFCS lands and there is a better way // of disambiguating methods. fn first_child<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> Option> { this.first_child() } - first_child(*self).map(|node| *node.root()) + first_child(self).map(|node| *node.root()) } - fn prev_sibling(&self) -> Option> { + fn prev_sibling(self) -> Option> { // FIXME(zwarich): Remove this when UFCS lands and there is a better way // of disambiguating methods. fn prev_sibling<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> Option> { this.prev_sibling() } - prev_sibling(*self).map(|node| *node.root()) + prev_sibling(self).map(|node| *node.root()) } - fn next_sibling(&self) -> Option> { + fn next_sibling(self) -> Option> { // FIXME(zwarich): Remove this when UFCS lands and there is a better way // of disambiguating methods. fn next_sibling<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> Option> { this.next_sibling() } - next_sibling(*self).map(|node| *node.root()) + next_sibling(self).map(|node| *node.root()) } - fn is_document(&self) -> bool { + fn is_document(self) -> bool { // FIXME(zwarich): Remove this when UFCS lands and there is a better way // of disambiguating methods. fn is_document<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> bool { this.is_document() } - is_document(*self) + is_document(self) } - fn is_element(&self) -> bool { + fn is_element(self) -> bool { // FIXME(zwarich): Remove this when UFCS lands and there is a better way // of disambiguating methods. fn is_element<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> bool { this.is_element() } - is_element(*self) + is_element(self) } - fn as_element(&self) -> JSRef<'a, Element> { - let elem: Option> = ElementCast::to_ref(*self); + fn as_element(self) -> JSRef<'a, Element> { + let elem: Option> = ElementCast::to_ref(self); assert!(elem.is_some()); elem.unwrap() } - fn match_attr(&self, attr: &style::AttrSelector, test: |&str| -> bool) -> bool { + fn match_attr(self, attr: &style::AttrSelector, test: |&str| -> bool) -> bool { let name = { if self.is_html_element_in_html_document() { attr.lower_name.as_slice() @@ -2119,8 +2119,8 @@ impl<'a> style::TNode<'a, JSRef<'a, Element>> for JSRef<'a, Node> { } } - fn is_html_element_in_html_document(&self) -> bool { - let elem: Option> = ElementCast::to_ref(*self); + fn is_html_element_in_html_document(self) -> bool { + let elem: Option> = ElementCast::to_ref(self); assert!(elem.is_some()); elem.unwrap().html_element_in_html_document() } diff --git a/components/style/node.rs b/components/style/node.rs index cb267a719667..75d098563c23 100644 --- a/components/style/node.rs +++ b/components/style/node.rs @@ -10,25 +10,25 @@ use string_cache::{Atom, Namespace}; pub trait TNode<'a, E: TElement<'a>> : Clone + Copy { - fn parent_node(&self) -> Option; - fn first_child(&self) -> Option; - fn prev_sibling(&self) -> Option; - fn next_sibling(&self) -> Option; - fn is_document(&self) -> bool; - fn is_element(&self) -> bool; - fn as_element(&self) -> E; - fn match_attr(&self, attr: &AttrSelector, test: |&str| -> bool) -> bool; - fn is_html_element_in_html_document(&self) -> bool; + fn parent_node(self) -> Option; + fn first_child(self) -> Option; + fn prev_sibling(self) -> Option; + fn next_sibling(self) -> Option; + fn is_document(self) -> bool; + fn is_element(self) -> bool; + fn as_element(self) -> E; + fn match_attr(self, attr: &AttrSelector, test: |&str| -> bool) -> bool; + fn is_html_element_in_html_document(self) -> bool; } pub trait TElement<'a> : Copy { - fn get_attr(&self, namespace: &Namespace, attr: &str) -> Option<&'a str>; - fn get_link(&self) -> Option<&'a str>; - fn get_local_name(&self) -> &'a Atom; - fn get_namespace(&self) -> &'a Namespace; - fn get_hover_state(&self) -> bool; - fn get_id(&self) -> Option; - fn get_disabled_state(&self) -> bool; - fn get_enabled_state(&self) -> bool; - fn has_class(&self, name: &str) -> bool; + fn get_attr(self, namespace: &Namespace, attr: &str) -> Option<&'a str>; + fn get_link(self) -> Option<&'a str>; + fn get_local_name(self) -> &'a Atom; + fn get_namespace(self) -> &'a Namespace; + fn get_hover_state(self) -> bool; + fn get_id(self) -> Option; + fn get_disabled_state(self) -> bool; + fn get_enabled_state(self) -> bool; + fn has_class(self, name: &str) -> bool; } From 8b0361e2515aefda929f0f3d49b7910874a282fd Mon Sep 17 00:00:00 2001 From: Cameron Zwarich Date: Tue, 30 Sep 2014 21:20:14 -0700 Subject: [PATCH 8/8] Remove an unused lifetime parameter --- components/script/dom/element.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index a993e24eb620..2a3f53751f21 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -987,7 +987,7 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> { let node: JSRef = NodeCast::from_ref(self); node.get_hover_state() } - fn get_id<'a>(self) -> Option { + fn get_id(self) -> Option { self.get_attribute(ns!(""), "id").map(|attr| { let attr = attr.root(); match *attr.value() {