From a272a506353d22b5e2afb8a29681e0827865922b Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 8 Oct 2012 17:56:42 -0700 Subject: [PATCH] Eliminate warnings in util::tree --- src/servo/css/resolve/apply.rs | 4 ++-- src/servo/css/styles.rs | 2 +- src/servo/dom/node.rs | 22 +++++++++++----------- src/servo/layout/box.rs | 10 +++++----- src/servo/layout/box_builder.rs | 4 ++-- src/servo/layout/flow.rs | 6 +++--- src/servo/util/color.rs | 22 +++++++++++----------- src/servo/util/tree.rs | 20 ++++++++++---------- 8 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/servo/css/resolve/apply.rs b/src/servo/css/resolve/apply.rs index 0a3f198cf92..fa3076bbd46 100644 --- a/src/servo/css/resolve/apply.rs +++ b/src/servo/css/resolve/apply.rs @@ -108,8 +108,8 @@ impl StyleApplicator { fn apply_css_style(layout_ctx: &LayoutContext) { let reflow = copy self.reflow; - do NodeTree.each_child(self.node) |child| { - inheritance_wrapper(layout_ctx, child, reflow); true + do NodeTree.each_child(&self.node) |child| { + inheritance_wrapper(layout_ctx, *child, reflow); true } } diff --git a/src/servo/css/styles.rs b/src/servo/css/styles.rs index 84bb7fa8321..efae44c1b37 100644 --- a/src/servo/css/styles.rs +++ b/src/servo/css/styles.rs @@ -146,7 +146,7 @@ impl Node : StyleMethods { let mut i = 0u; // Compute the styles of each of our children in parallel - for NodeTree.each_child(self) |kid| { + for NodeTree.each_child(&self) |kid| { i = i + 1u; let new_styles = clone(&styles); diff --git a/src/servo/dom/node.rs b/src/servo/dom/node.rs index 99468ede6fa..27000617dac 100644 --- a/src/servo/dom/node.rs +++ b/src/servo/dom/node.rs @@ -27,8 +27,8 @@ enum NodeData = { enum NodeTree { NodeTree } impl NodeTree : tree::ReadMethods { - fn each_child(node: Node, f: fn(Node) -> bool) { - tree::each_child(self, node, f) + fn each_child(node: &Node, f: fn(&Node) -> bool) { + tree::each_child(&self, node, f) } fn with_tree_fields(&&n: Node, f: fn(tree::Tree) -> R) -> R { @@ -39,11 +39,11 @@ impl NodeTree : tree::ReadMethods { impl Node { fn traverse_preorder(preorder_cb: &fn(Node)) { preorder_cb(self); - do NodeTree.each_child(self) |child| { child.traverse_preorder(preorder_cb); true } + do NodeTree.each_child(&self) |child| { child.traverse_preorder(preorder_cb); true } } fn traverse_postorder(postorder_cb: &fn(Node)) { - do NodeTree.each_child(self) |child| { child.traverse_postorder(postorder_cb); true } + do NodeTree.each_child(&self) |child| { child.traverse_postorder(postorder_cb); true } postorder_cb(self); } } @@ -77,7 +77,7 @@ impl Node : DebugMethods { s += self.debug_str(); debug!("%s", s); - for NodeTree.each_child(*self) |kid| { + for NodeTree.each_child(self) |kid| { kid.dump_indent(indent + 1u) } } @@ -153,12 +153,12 @@ impl NodeScope : NodeScopeExtensions { #[allow(non_implicitly_copyable_typarams)] impl NodeScope : tree::ReadMethods { - fn each_child(node: Node, f: fn(Node) -> bool) { - tree::each_child(self, node, f) + fn each_child(node: &Node, f: fn(&Node) -> bool) { + tree::each_child(&self, node, f) } - fn get_parent(node: Node) -> Option { - tree::get_parent(self, node) + fn get_parent(node: &Node) -> Option { + tree::get_parent(&self, node) } fn with_tree_fields(node: Node, f: fn(tree::Tree) -> R) -> R { @@ -168,8 +168,8 @@ impl NodeScope : tree::ReadMethods { #[allow(non_implicitly_copyable_typarams)] impl NodeScope : tree::WriteMethods { - fn add_child(node: Node, child: Node) { - tree::add_child(self, node, child) + fn add_child(+node: Node, +child: Node) { + tree::add_child(&self, node, child) } fn with_tree_fields(node: Node, f: fn(tree::Tree) -> R) -> R { diff --git a/src/servo/layout/box.rs b/src/servo/layout/box.rs index b5245769f1e..781e913f194 100644 --- a/src/servo/layout/box.rs +++ b/src/servo/layout/box.rs @@ -304,8 +304,8 @@ trait ImageBoxMethods { pub enum RenderBoxTree { RenderBoxTree } impl RenderBoxTree : tree::ReadMethods<@RenderBox> { - fn each_child(node: @RenderBox, f: fn(&&box: @RenderBox) -> bool) { - tree::each_child(self, node, f) + fn each_child(node: @RenderBox, f: fn(box: @RenderBox) -> bool) { + tree::each_child(&self, &node, |box| f(*box) ) } fn with_tree_fields(&&b: @RenderBox, f: fn(tree::Tree<@RenderBox>) -> R) -> R { @@ -316,7 +316,7 @@ impl RenderBoxTree : tree::ReadMethods<@RenderBox> { impl RenderBoxTree : tree::WriteMethods<@RenderBox> { fn add_child(parent: @RenderBox, child: @RenderBox) { assert !core::box::ptr_eq(parent, child); - tree::add_child(self, parent, child) + tree::add_child(&self, parent, child) } fn with_tree_fields(&&b: @RenderBox, f: fn(tree::Tree<@RenderBox>) -> R) -> R { @@ -384,8 +384,8 @@ mod test { fn flat_bounds(root: @RenderBox) -> ~[Rect] { let mut r = ~[]; - for tree::each_child(RenderBoxTree, root) |c| { - push_all(&mut r, flat_bounds(c)); + for tree::each_child(&RenderBoxTree, &root) |c| { + push_all(&mut r, flat_bounds(*c)); } push(&mut r, copy root.d().position); diff --git a/src/servo/layout/box_builder.rs b/src/servo/layout/box_builder.rs index 1bad0e4c497..5e901ae5a11 100644 --- a/src/servo/layout/box_builder.rs +++ b/src/servo/layout/box_builder.rs @@ -126,8 +126,8 @@ impl LayoutTreeBuilder { } // recurse // TODO: don't set parent box unless this is an inline flow? - do NodeTree.each_child(cur_node) |child_node| { - self.construct_recursively(layout_ctx, child_node, next_ctx, Some(new_box)); true + do NodeTree.each_child(&cur_node) |child_node| { + self.construct_recursively(layout_ctx, *child_node, next_ctx, Some(new_box)); true } // Fixup any irregularities, such as split inlines (CSS 2.1 Section 9.2.1.1) diff --git a/src/servo/layout/flow.rs b/src/servo/layout/flow.rs index abab04c44e5..9020658d0f1 100644 --- a/src/servo/layout/flow.rs +++ b/src/servo/layout/flow.rs @@ -213,8 +213,8 @@ impl FlowContext { enum FlowTree { FlowTree } impl FlowTree : tree::ReadMethods<@FlowContext> { - fn each_child(ctx: @FlowContext, f: fn(&&box: @FlowContext) -> bool) { - tree::each_child(self, ctx, f) + fn each_child(ctx: @FlowContext, f: fn(box: @FlowContext) -> bool) { + tree::each_child(&self, &ctx, |box| f(*box) ) } fn with_tree_fields(&&box: @FlowContext, f: fn(tree::Tree<@FlowContext>) -> R) -> R { @@ -225,7 +225,7 @@ impl FlowTree : tree::ReadMethods<@FlowContext> { impl FlowTree : tree::WriteMethods<@FlowContext> { fn add_child(parent: @FlowContext, child: @FlowContext) { assert !core::box::ptr_eq(parent, child); - tree::add_child(self, parent, child) + tree::add_child(&self, parent, child) } fn with_tree_fields(&&box: @FlowContext, f: fn(tree::Tree<@FlowContext>) -> R) -> R { diff --git a/src/servo/util/color.rs b/src/servo/util/color.rs index 2a5cd5d063a..10d4f4aa956 100644 --- a/src/servo/util/color.rs +++ b/src/servo/util/color.rs @@ -69,13 +69,13 @@ impl Color { mod parsing { export parse_color; - fn fail_unrecognized(col : ~str) -> Option { + fn fail_unrecognized(col : &str) -> Option { warn!("Unrecognized color %s", col); return None; } /** Match an exact color keyword. */ - fn parse_by_name(color : ~str) -> Option { + fn parse_by_name(color : &str) -> Option { let col = match color.to_lower() { ~"black" => black(), ~"silver" => silver(), @@ -101,7 +101,7 @@ mod parsing { } /** Parses a color specification in the form rgb(foo,bar,baz) */ - fn parse_rgb(color : ~str) -> Option { + fn parse_rgb(color : &str) -> Option { // Shave off the rgb( and the ) let only_colors = color.substr(4u, color.len() - 5u); @@ -117,7 +117,7 @@ mod parsing { } /** Parses a color specification in the form rgba(foo,bar,baz,qux) */ - fn parse_rgba(color : ~str) -> Option { + fn parse_rgba(color : &str) -> Option { // Shave off the rgba( and the ) let only_vals = color.substr(5u, color.len() - 6u); @@ -133,7 +133,7 @@ mod parsing { } /** Parses a color specification in the form hsl(foo,bar,baz) */ - fn parse_hsl(color : ~str) -> Option { + fn parse_hsl(color : &str) -> Option { // Shave off the hsl( and the ) let only_vals = color.substr(4u, color.len() - 5u); @@ -149,7 +149,7 @@ mod parsing { } /** Parses a color specification in the form hsla(foo,bar,baz,qux) */ - fn parse_hsla(color : ~str) -> Option { + fn parse_hsla(color : &str) -> Option { // Shave off the hsla( and the ) let only_vals = color.substr(5u, color.len() - 6u); @@ -166,12 +166,12 @@ mod parsing { // Currently colors are supported in rgb(a,b,c) form and also by // keywords for several common colors. // TODO: extend this - fn parse_color(color : ~str) -> Option { + fn parse_color(color : &str) -> Option { match color { - c if c.starts_with(~"rgb(") => parse_rgb(c), - c if c.starts_with(~"rgba(") => parse_rgba(c), - c if c.starts_with(~"hsl(") => parse_hsl(c), - c if c.starts_with(~"hsla(") => parse_hsla(c), + c if c.starts_with("rgb(") => parse_rgb(c), + c if c.starts_with("rgba(") => parse_rgba(c), + c if c.starts_with("hsl(") => parse_hsl(c), + c if c.starts_with("hsla(") => parse_hsla(c), c => parse_by_name(c) } } diff --git a/src/servo/util/tree.rs b/src/servo/util/tree.rs index eaf220aea6b..5e316b9f9c8 100644 --- a/src/servo/util/tree.rs +++ b/src/servo/util/tree.rs @@ -20,14 +20,14 @@ pub trait WriteMethods { fn with_tree_fields(T, f: fn(Tree) -> R) -> R; } -pub fn each_child>(ops: O, node: T, f: fn(T) -> bool) { - let mut p = ops.with_tree_fields(node, |f| f.first_child); +pub fn each_child>(ops: &O, node: &T, f: fn(&T) -> bool) { + let mut p = ops.with_tree_fields(*node, |f| f.first_child); loop { match copy p { None => { return; } - Some(c) => { + Some(ref c) => { if !f(c) { return; } - p = ops.with_tree_fields(c, |f| f.next_sibling); + p = ops.with_tree_fields(*c, |f| f.next_sibling); } } } @@ -41,7 +41,7 @@ pub fn empty() -> Tree { mut next_sibling: None} } -pub fn add_child>(ops: O, parent: T, child: T) { +pub fn add_child>(ops: &O, +parent: T, +child: T) { ops.with_tree_fields(child, |child_tf| { match child_tf.parent { @@ -72,8 +72,8 @@ pub fn add_child>(ops: O, parent: T, child: T) { }); } -pub fn get_parent>(ops: O, node: T) -> Option { - ops.with_tree_fields(node, |tf| tf.parent) +pub fn get_parent>(ops: &O, node: &T) -> Option { + ops.with_tree_fields(*node, |tf| tf.parent) } #[cfg(test)] @@ -108,7 +108,7 @@ mod test { let p = new_dummy(3u); for vec::each(children) |c| { - add_child(dtree, p, *c); + add_child(&dtree, p, *c); } return {p: p, children: children}; @@ -118,7 +118,7 @@ mod test { fn add_child_0() { let {p, children} = parent_with_3_children(); let mut i = 0u; - for each_child(dtree, p) |c| { + for each_child(&dtree, &p) |c| { assert c.value == i; i += 1u; } @@ -129,7 +129,7 @@ mod test { fn add_child_break() { let {p, _} = parent_with_3_children(); let mut i = 0u; - for each_child(dtree, p) |_c| { + for each_child(&dtree, &p) |_c| { i += 1u; break; }