Fix more warnings in util::tree

This commit is contained in:
Brian Anderson 2012-10-08 18:15:39 -07:00
parent 958d6c10fe
commit a83e1659e4
4 changed files with 26 additions and 26 deletions

View file

@ -31,8 +31,8 @@ impl NodeTree : tree::ReadMethods<Node> {
tree::each_child(&self, node, f) tree::each_child(&self, node, f)
} }
fn with_tree_fields<R>(&&n: Node, f: fn(tree::Tree<Node>) -> R) -> R { fn with_tree_fields<R>(n: &Node, f: fn(&tree::Tree<Node>) -> R) -> R {
n.read(|n| f(n.tree)) n.read(|n| f(&n.tree))
} }
} }
@ -161,8 +161,8 @@ impl NodeScope : tree::ReadMethods<Node> {
tree::get_parent(&self, node) tree::get_parent(&self, node)
} }
fn with_tree_fields<R>(node: Node, f: fn(tree::Tree<Node>) -> R) -> R { fn with_tree_fields<R>(node: &Node, f: fn(&tree::Tree<Node>) -> R) -> R {
self.read(node, |n| f(n.tree)) self.read(*node, |n| f(&n.tree))
} }
} }
@ -172,7 +172,7 @@ impl NodeScope : tree::WriteMethods<Node> {
tree::add_child(&self, node, child) tree::add_child(&self, node, child)
} }
fn with_tree_fields<R>(node: Node, f: fn(tree::Tree<Node>) -> R) -> R { fn with_tree_fields<R>(node: &Node, f: fn(&tree::Tree<Node>) -> R) -> R {
self.write(node, |n| f(n.tree)) self.write(*node, |n| f(&n.tree))
} }
} }

View file

@ -312,8 +312,8 @@ impl RenderBoxTree : tree::ReadMethods<@RenderBox> {
tree::each_child(&self, &node, |box| f(*box) ) tree::each_child(&self, &node, |box| f(*box) )
} }
fn with_tree_fields<R>(&&b: @RenderBox, f: fn(tree::Tree<@RenderBox>) -> R) -> R { fn with_tree_fields<R>(b: &@RenderBox, f: fn(&tree::Tree<@RenderBox>) -> R) -> R {
f(b.d().tree) f(&b.d().tree)
} }
} }
@ -323,8 +323,8 @@ impl RenderBoxTree : tree::WriteMethods<@RenderBox> {
tree::add_child(&self, parent, child) tree::add_child(&self, parent, child)
} }
fn with_tree_fields<R>(&&b: @RenderBox, f: fn(tree::Tree<@RenderBox>) -> R) -> R { fn with_tree_fields<R>(b: &@RenderBox, f: fn(&tree::Tree<@RenderBox>) -> R) -> R {
f(b.d().tree) f(&b.d().tree)
} }
} }

View file

@ -217,8 +217,8 @@ impl FlowTree : tree::ReadMethods<@FlowContext> {
tree::each_child(&self, &ctx, |box| f(*box) ) tree::each_child(&self, &ctx, |box| f(*box) )
} }
fn with_tree_fields<R>(&&box: @FlowContext, f: fn(tree::Tree<@FlowContext>) -> R) -> R { fn with_tree_fields<R>(box: &@FlowContext, f: fn(&tree::Tree<@FlowContext>) -> R) -> R {
f(box.d().tree) f(&box.d().tree)
} }
} }
@ -228,8 +228,8 @@ impl FlowTree : tree::WriteMethods<@FlowContext> {
tree::add_child(&self, parent, child) tree::add_child(&self, parent, child)
} }
fn with_tree_fields<R>(&&box: @FlowContext, f: fn(tree::Tree<@FlowContext>) -> R) -> R { fn with_tree_fields<R>(box: &@FlowContext, f: fn(&tree::Tree<@FlowContext>) -> R) -> R {
f(box.d().tree) f(&box.d().tree)
} }
} }

View file

@ -13,21 +13,21 @@ pub type Tree<T> = {
}; };
pub trait ReadMethods<T> { pub trait ReadMethods<T> {
fn with_tree_fields<R>(T, f: fn(Tree<T>) -> R) -> R; fn with_tree_fields<R>(&T, f: fn(&Tree<T>) -> R) -> R;
} }
pub trait WriteMethods<T> { pub trait WriteMethods<T> {
fn with_tree_fields<R>(T, f: fn(Tree<T>) -> R) -> R; fn with_tree_fields<R>(&T, f: fn(&Tree<T>) -> R) -> R;
} }
pub fn each_child<T:Copy,O:ReadMethods<T>>(ops: &O, node: &T, f: fn(&T) -> bool) { pub fn each_child<T:Copy,O:ReadMethods<T>>(ops: &O, node: &T, f: fn(&T) -> bool) {
let mut p = ops.with_tree_fields(*node, |f| f.first_child); let mut p = ops.with_tree_fields(node, |f| f.first_child);
loop { loop {
match copy p { match copy p {
None => { return; } None => { return; }
Some(ref c) => { Some(ref c) => {
if !f(c) { return; } if !f(c) { return; }
p = ops.with_tree_fields(*c, |f| f.next_sibling); p = ops.with_tree_fields(c, |f| f.next_sibling);
} }
} }
} }
@ -43,7 +43,7 @@ pub fn empty<T>() -> Tree<T> {
pub fn add_child<T:Copy,O:WriteMethods<T>>(ops: &O, +parent: T, +child: T) { pub fn add_child<T:Copy,O:WriteMethods<T>>(ops: &O, +parent: T, +child: T) {
ops.with_tree_fields(child, |child_tf| { ops.with_tree_fields(&child, |child_tf| {
match child_tf.parent { match child_tf.parent {
Some(_) => { fail ~"Already has a parent"; } Some(_) => { fail ~"Already has a parent"; }
None => { child_tf.parent = Some(parent); } None => { child_tf.parent = Some(parent); }
@ -52,14 +52,14 @@ pub fn add_child<T:Copy,O:WriteMethods<T>>(ops: &O, +parent: T, +child: T) {
assert child_tf.prev_sibling.is_none(); assert child_tf.prev_sibling.is_none();
assert child_tf.next_sibling.is_none(); assert child_tf.next_sibling.is_none();
ops.with_tree_fields(parent, |parent_tf| { ops.with_tree_fields(&parent, |parent_tf| {
match copy parent_tf.last_child { match copy parent_tf.last_child {
None => { None => {
parent_tf.first_child = Some(child); parent_tf.first_child = Some(child);
} }
Some(lc) => { Some(lc) => {
let lc = lc; // satisfy alias checker let lc = lc; // satisfy alias checker
ops.with_tree_fields(lc, |lc_tf| { ops.with_tree_fields(&lc, |lc_tf| {
assert lc_tf.next_sibling.is_none(); assert lc_tf.next_sibling.is_none();
lc_tf.next_sibling = Some(child); lc_tf.next_sibling = Some(child);
}); });
@ -73,7 +73,7 @@ pub fn add_child<T:Copy,O:WriteMethods<T>>(ops: &O, +parent: T, +child: T) {
} }
pub fn get_parent<T:Copy,O:ReadMethods<T>>(ops: &O, node: &T) -> Option<T> { pub fn get_parent<T:Copy,O:ReadMethods<T>>(ops: &O, node: &T) -> Option<T> {
ops.with_tree_fields(*node, |tf| tf.parent) ops.with_tree_fields(node, |tf| tf.parent)
} }
#[cfg(test)] #[cfg(test)]
@ -86,14 +86,14 @@ mod test {
enum dtree { dtree } enum dtree { dtree }
impl dtree : ReadMethods<dummy> { impl dtree : ReadMethods<dummy> {
fn with_tree_fields<R>(d: dummy, f: fn(Tree<dummy>) -> R) -> R { fn with_tree_fields<R>(d: &dummy, f: fn(&Tree<dummy>) -> R) -> R {
f(d.fields) f(&d.fields)
} }
} }
impl dtree : WriteMethods<dummy> { impl dtree : WriteMethods<dummy> {
fn with_tree_fields<R>(d: dummy, f: fn(Tree<dummy>) -> R) -> R { fn with_tree_fields<R>(d: &dummy, f: fn(&Tree<dummy>) -> R) -> R {
f(d.fields) f(&d.fields)
} }
} }