From 5606fc0c90461db40faeca16d7bffd9e61c2be73 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sat, 6 Apr 2013 11:22:36 -0400 Subject: [PATCH] Revert map.each to something which takes two parameters rather than a tuple. The current setup iterates over `BaseIter<(&'self K, &'self V)>` where 'self is a lifetime declared *in the each method*. You can't place such a type in the impl declaration. The compiler currently allows it, but this will not be legal under #5656 and I'm pretty sure it's not sound now. --- src/libcore/container.rs | 3 + src/libcore/hashmap.rs | 39 +++++------- src/libcore/trie.rs | 62 +++++++++---------- src/librustc/metadata/cstore.rs | 2 +- src/librustc/middle/lang_items.rs | 2 +- src/librustc/middle/lint.rs | 2 +- src/librustc/middle/region.rs | 2 +- src/librustc/middle/resolve.rs | 16 ++--- src/librustc/middle/trans/base.rs | 4 +- .../middle/typeck/infer/region_inference.rs | 2 +- src/librustc/rustc.rc | 2 +- src/libstd/json.rs | 8 +-- src/libstd/net_url.rs | 2 +- src/libstd/serialize.rs | 6 +- src/libstd/smallintmap.rs | 52 +++++++--------- src/libstd/treemap.rs | 52 +++++++--------- src/libstd/workcache.rs | 4 +- src/test/bench/shootout-k-nucleotide-pipes.rs | 2 +- .../class-impl-very-parameterized-trait.rs | 28 ++++----- 19 files changed, 132 insertions(+), 158 deletions(-) diff --git a/src/libcore/container.rs b/src/libcore/container.rs index e20821b919b6c..a1836d16fd733 100644 --- a/src/libcore/container.rs +++ b/src/libcore/container.rs @@ -29,6 +29,9 @@ pub trait Map: Mutable { /// Return true if the map contains a value for the specified key fn contains_key(&self, key: &K) -> bool; + // Visits all keys and values + fn each(&self, f: &fn(&K, &V) -> bool); + /// Visit all keys fn each_key(&self, f: &fn(&K) -> bool); diff --git a/src/libcore/hashmap.rs b/src/libcore/hashmap.rs index 5dbf085f09719..d4af0ffe7fe7b 100644 --- a/src/libcore/hashmap.rs +++ b/src/libcore/hashmap.rs @@ -279,24 +279,6 @@ priv impl HashMap { } } -impl<'self,K:Hash + IterBytes + Eq,V> - BaseIter<(&'self K, &'self V)> for HashMap { - /// Visit all key-value pairs - fn each(&self, blk: &fn(&(&'self K, &'self V)) -> bool) { - for uint::range(0, self.buckets.len()) |i| { - let mut broke = false; - do self.buckets[i].map |bucket| { - if !blk(&(&bucket.key, &bucket.value)) { - broke = true; // FIXME(#3064) just write "break;" - } - }; - if broke { break; } - } - } - fn size_hint(&self) -> Option { Some(self.len()) } -} - - impl Container for HashMap { /// Return the number of elements in the map fn len(&const self) -> uint { self.size } @@ -315,7 +297,7 @@ impl Mutable for HashMap { } } -impl<'self,K:Hash + IterBytes + Eq,V> Map for HashMap { +impl Map for HashMap { /// Return true if the map contains a value for the specified key fn contains_key(&self, k: &K) -> bool { match self.bucket_for_key(k) { @@ -324,14 +306,25 @@ impl<'self,K:Hash + IterBytes + Eq,V> Map for HashMap { } } + /// Visit all key-value pairs + fn each(&self, blk: &fn(&'self K, &'self V) -> bool) { + for uint::range(0, self.buckets.len()) |i| { + for self.buckets[i].each |bucket| { + if !blk(&bucket.key, &bucket.value) { + return; + } + } + } + } + /// Visit all keys fn each_key(&self, blk: &fn(k: &K) -> bool) { - self.each(|&(k, _)| blk(k)) + self.each(|k, _| blk(k)) } /// Visit all values fn each_value(&self, blk: &fn(v: &V) -> bool) { - self.each(|&(_, v)| blk(v)) + self.each(|_, v| blk(v)) } /// Iterate over the map and mutate the contained values @@ -545,7 +538,7 @@ impl Eq for HashMap { fn eq(&self, other: &HashMap) -> bool { if self.len() != other.len() { return false; } - for self.each |&(key, value)| { + for self.each |key, value| { match other.find(key) { None => return false, Some(v) => if value != v { return false }, @@ -798,7 +791,7 @@ mod test_map { assert!(m.insert(i, i*2)); } let mut observed = 0; - for m.each |&(k, v)| { + for m.each |k, v| { assert!(*v == *k * 2); observed |= (1 << *k); } diff --git a/src/libcore/trie.rs b/src/libcore/trie.rs index 5d87e2a296d3d..f6a92a213859e 100644 --- a/src/libcore/trie.rs +++ b/src/libcore/trie.rs @@ -28,24 +28,6 @@ pub struct TrieMap { priv length: uint } -impl<'self,T> BaseIter<(uint, &'self T)> for TrieMap { - /// Visit all key-value pairs in order - #[inline(always)] - fn each(&self, f: &fn(&(uint, &'self T)) -> bool) { - self.root.each(f); - } - #[inline(always)] - fn size_hint(&self) -> Option { Some(self.len()) } -} - -impl<'self,T> ReverseIter<(uint, &'self T)> for TrieMap { - /// Visit all key-value pairs in reverse order - #[inline(always)] - fn each_reverse(&self, f: &fn(&(uint, &'self T)) -> bool) { - self.root.each_reverse(f); - } -} - impl Container for TrieMap { /// Return the number of elements in the map #[inline(always)] @@ -72,16 +54,22 @@ impl Map for TrieMap { self.find(key).is_some() } + /// Visit all key-value pairs in order + #[inline(always)] + fn each(&self, f: &fn(&uint, &'self T) -> bool) { + self.root.each(f); + } + /// Visit all keys in order #[inline(always)] fn each_key(&self, f: &fn(&uint) -> bool) { - self.each(|&(k, _)| f(&k)) + self.each(|k, _| f(k)) } /// Visit all values in order #[inline(always)] fn each_value(&self, f: &fn(&T) -> bool) { - self.each(|&(_, v)| f(v)) + self.each(|_, v| f(v)) } /// Iterate over the map and mutate the contained values @@ -148,16 +136,22 @@ pub impl TrieMap { TrieMap{root: TrieNode::new(), length: 0} } + /// Visit all key-value pairs in reverse order + #[inline(always)] + fn each_reverse(&self, f: &fn(&uint, &'self T) -> bool) { + self.root.each_reverse(f); + } + /// Visit all keys in reverse order #[inline(always)] fn each_key_reverse(&self, f: &fn(&uint) -> bool) { - self.each_reverse(|&(k, _)| f(&k)) + self.each_reverse(|k, _| f(k)) } /// Visit all values in reverse order #[inline(always)] fn each_value_reverse(&self, f: &fn(&T) -> bool) { - self.each_reverse(|&(_, v)| f(v)) + self.each_reverse(|_, v| f(v)) } } @@ -239,22 +233,22 @@ impl TrieNode { } impl TrieNode { - fn each(&self, f: &fn(&(uint, &'self T)) -> bool) -> bool { + fn each(&self, f: &fn(&uint, &'self T) -> bool) -> bool { for uint::range(0, self.children.len()) |idx| { match self.children[idx] { Internal(ref x) => if !x.each(f) { return false }, - External(k, ref v) => if !f(&(k, v)) { return false }, + External(k, ref v) => if !f(&k, v) { return false }, Nothing => () } } true } - fn each_reverse(&self, f: &fn(&(uint, &'self T)) -> bool) -> bool { + fn each_reverse(&self, f: &fn(&uint, &'self T) -> bool) -> bool { for uint::range_rev(self.children.len(), 0) |idx| { match self.children[idx - 1] { Internal(ref x) => if !x.each_reverse(f) { return false }, - External(k, ref v) => if !f(&(k, v)) { return false }, + External(k, ref v) => if !f(&k, v) { return false }, Nothing => () } } @@ -438,8 +432,8 @@ mod tests { assert!(m.insert(1, 2)); let mut n = 0; - for m.each |&(k, v)| { - assert!(k == n); + for m.each |k, v| { + assert!(*k == n); assert!(*v == n * 2); n += 1; } @@ -454,11 +448,11 @@ mod tests { } let mut n = uint::max_value - 9999; - for m.each |&(k, v)| { + for m.each |k, v| { if n == uint::max_value - 5000 { break } assert!(n < uint::max_value - 5000); - assert!(k == n); + assert!(*k == n); assert!(*v == n / 2); n += 1; } @@ -475,8 +469,8 @@ mod tests { assert!(m.insert(1, 2)); let mut n = 4; - for m.each_reverse |&(k, v)| { - assert!(k == n); + for m.each_reverse |k, v| { + assert!(*k == n); assert!(*v == n * 2); n -= 1; } @@ -491,11 +485,11 @@ mod tests { } let mut n = uint::max_value; - for m.each_reverse |&(k, v)| { + for m.each_reverse |k, v| { if n == uint::max_value - 5000 { break } assert!(n > uint::max_value - 5000); - assert!(k == n); + assert!(*k == n); assert!(*v == n / 2); n -= 1; } diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index 65bd37236b714..d738c3e774794 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -86,7 +86,7 @@ pub fn have_crate_data(cstore: &CStore, cnum: ast::crate_num) -> bool { pub fn iter_crate_data(cstore: &CStore, i: &fn(ast::crate_num, @crate_metadata)) { - for cstore.metas.each |&(&k, &v)| { + for cstore.metas.each |&k, &v| { i(k, v); } } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index ab9b8ca0db624..0dd28e5ca7ca1 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -397,7 +397,7 @@ pub impl<'self> LanguageItemCollector<'self> { } fn check_completeness(&self) { - for self.item_refs.each |&(&key, &item_ref)| { + for self.item_refs.each |&key, &item_ref| { match self.items.items[item_ref] { None => { self.session.err(fmt!("no item found for `%s`", *key)); diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 0adf4b87f3a8e..6f8992bf1ca4a 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -460,7 +460,7 @@ pub fn build_settings_crate(sess: session::Session, crate: @ast::crate) { do cx.with_lint_attrs(/*bad*/copy crate.node.attrs) |cx| { // Copy out the default settings - for cx.curr.each |&(k, &v)| { + for cx.curr.each |&k, &v| { sess.lint_settings.default_settings.insert(k, v); } diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 1c60c37ed12a0..50c193ab3b095 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -842,7 +842,7 @@ pub fn determine_rp_in_crate(sess: Session, debug!("%s", { debug!("Region variance results:"); let region_paramd_items = cx.region_paramd_items; - for region_paramd_items.each |&(&key, &value)| { + for region_paramd_items.each |&key, &value| { debug!("item %? (%s) is parameterized with variance %?", key, ast_map::node_id_to_str(ast_map, key, diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index fcf0b7022a7a7..c7f53c744f1bf 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -2369,7 +2369,7 @@ pub impl Resolver { // Add all resolved imports from the containing module. for containing_module.import_resolutions.each - |&(ident, target_import_resolution)| { + |ident, target_import_resolution| { debug!("(resolving glob import) writing module resolution \ %? into `%s`", @@ -2457,13 +2457,13 @@ pub impl Resolver { }; // Add all children from the containing module. - for containing_module.children.each |&(ident, name_bindings)| { + for containing_module.children.each |ident, name_bindings| { merge_import_resolution(ident, *name_bindings); } // Add external module children from the containing module. for containing_module.external_module_children.each - |&(ident, module)| { + |ident, module| { let name_bindings = @mut Resolver::create_name_bindings_from_module(*module); merge_import_resolution(ident, name_bindings); @@ -3111,7 +3111,7 @@ pub impl Resolver { fn add_exports_for_module(@mut self, exports2: &mut ~[Export2], module_: @mut Module) { - for module_.children.each |&(ident, namebindings)| { + for module_.children.each |ident, namebindings| { debug!("(computing exports) maybe export '%s'", *self.session.str_of(*ident)); self.add_exports_of_namebindings(&mut *exports2, @@ -3126,7 +3126,7 @@ pub impl Resolver { false); } - for module_.import_resolutions.each |&(ident, importresolution)| { + for module_.import_resolutions.each |ident, importresolution| { if importresolution.privacy != Public { debug!("(computing exports) not reexporting private `%s`", *self.session.str_of(*ident)); @@ -3934,7 +3934,7 @@ pub impl Resolver { for arm.pats.eachi() |i, p| { let map_i = self.binding_mode_map(*p); - for map_0.each |&(&key, &binding_0)| { + for map_0.each |&key, &binding_0| { match map_i.find(&key) { None => { self.session.span_err( @@ -3955,7 +3955,7 @@ pub impl Resolver { } } - for map_i.each |&(&key, &binding)| { + for map_i.each |&key, &binding| { if !map_0.contains_key(&key) { self.session.span_err( binding.span, @@ -5248,7 +5248,7 @@ pub impl Resolver { } debug!("Import resolutions:"); - for module_.import_resolutions.each |&(name, import_resolution)| { + for module_.import_resolutions.each |name, import_resolution| { let mut value_repr; match import_resolution.target_for_namespace(ValueNS) { None => { value_repr = ~""; } diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 2eb7f8332ca92..0a116cdbdd169 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2848,7 +2848,7 @@ pub fn create_module_map(ccx: @CrateContext) -> ValueRef { lib::llvm::SetLinkage(map, lib::llvm::InternalLinkage); } let mut elts: ~[ValueRef] = ~[]; - for ccx.module_data.each |&(key, &val)| { + for ccx.module_data.each |key, &val| { let elt = C_struct(~[p2i(ccx, C_cstr(ccx, @/*bad*/ copy *key)), p2i(ccx, val)]); elts.push(elt); @@ -3139,7 +3139,7 @@ pub fn trans_crate(sess: session::Session, } if ccx.sess.count_llvm_insns() { - for ccx.stats.llvm_insns.each |&(&k, &v)| { + for ccx.stats.llvm_insns.each |&k, &v| { io::println(fmt!("%-7u %s", v, k)); } } diff --git a/src/librustc/middle/typeck/infer/region_inference.rs b/src/librustc/middle/typeck/infer/region_inference.rs index 98d12bea6a429..e6354d4ab88f6 100644 --- a/src/librustc/middle/typeck/infer/region_inference.rs +++ b/src/librustc/middle/typeck/infer/region_inference.rs @@ -1223,7 +1223,7 @@ pub impl RegionVarBindings { // It would be nice to write this using map(): let mut edges = vec::with_capacity(num_edges); - for self.constraints.each |&(constraint, span)| { + for self.constraints.each |constraint, span| { edges.push(GraphEdge { next_edge: [uint::max_value, uint::max_value], constraint: *constraint, diff --git a/src/librustc/rustc.rc b/src/librustc/rustc.rc index 94fcb85d1d84c..642a94b194582 100644 --- a/src/librustc/rustc.rc +++ b/src/librustc/rustc.rc @@ -177,7 +177,7 @@ Available lint options: padded(max_key, ~"name"), ~"default", ~"meaning")); io::println(fmt!(" %s %7.7s %s\n", padded(max_key, ~"----"), ~"-------", ~"-------")); - for lint_dict.each |&(k, v)| { + for lint_dict.each |k, v| { let k = str::replace(*k, ~"_", ~"-"); io::println(fmt!(" %s %7.7s %s", padded(max_key, k), diff --git a/src/libstd/json.rs b/src/libstd/json.rs index d733a60f34fff..90a745aaeb9b7 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -926,7 +926,7 @@ impl Eq for Json { &Object(ref d1) => { if d0.len() == d1.len() { let mut equal = true; - for d0.each |&(k, v0)| { + for d0.each |k, v0| { match d1.find(k) { Some(v1) if v0 == v1 => { }, _ => { equal = false; break } @@ -989,12 +989,12 @@ impl Ord for Json { let mut d1_flat = ~[]; // FIXME #4430: this is horribly inefficient... - for d0.each |&(k, v)| { + for d0.each |k, v| { d0_flat.push((@copy *k, @copy *v)); } d0_flat.qsort(); - for d1.each |&(k, v)| { + for d1.each |k, v| { d1_flat.push((@copy *k, @copy *v)); } d1_flat.qsort(); @@ -1125,7 +1125,7 @@ impl ToJson for ~[A] { impl ToJson for HashMap<~str, A> { fn to_json(&self) -> Json { let mut d = HashMap::new(); - for self.each |&(key, value)| { + for self.each |key, value| { d.insert(copy *key, value.to_json()); } Object(~d) diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index f7ffa7435cfa3..b8e0d9d9b2ac4 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -216,7 +216,7 @@ pub fn encode_form_urlencoded(m: &HashMap<~str, ~[~str]>) -> ~str { let mut out = ~""; let mut first = true; - for m.each |&(key, values)| { + for m.each |key, values| { let key = encode_plus(*key); for values.each |value| { diff --git a/src/libstd/serialize.rs b/src/libstd/serialize.rs index e1ab59fb2b3ae..c2f0d9cb43f09 100644 --- a/src/libstd/serialize.rs +++ b/src/libstd/serialize.rs @@ -595,7 +595,7 @@ impl< fn encode(&self, e: &E) { do e.emit_map(self.len()) { let mut i = 0; - for self.each |&(key, val)| { + for self.each |key, val| { e.emit_map_elt_key(i, || key.encode(e)); e.emit_map_elt_val(i, || val.encode(e)); i += 1; @@ -659,7 +659,7 @@ impl< fn encode(&self, e: &E) { do e.emit_map(self.len()) { let mut i = 0; - for self.each |&(key, val)| { + for self.each |key, val| { e.emit_map_elt_key(i, || key.encode(e)); e.emit_map_elt_val(i, || val.encode(e)); i += 1; @@ -717,7 +717,7 @@ impl< fn encode(&self, e: &E) { do e.emit_map(self.len()) { let mut i = 0; - for self.each |&(key, val)| { + for self.each |key, val| { e.emit_map_elt_key(i, || key.encode(e)); e.emit_map_elt_val(i, || val.encode(e)); i += 1; diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index b6c5ec03068cd..811cd710a62cc 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -14,7 +14,7 @@ */ use core::container::{Container, Mutable, Map, Set}; -use core::iter::{BaseIter, ReverseIter}; +use core::iter::{BaseIter}; use core::option::{Some, None}; use core::prelude::*; @@ -22,32 +22,6 @@ pub struct SmallIntMap { priv v: ~[Option], } -impl<'self, V> BaseIter<(uint, &'self V)> for SmallIntMap { - /// Visit all key-value pairs in order - fn each(&self, it: &fn(&(uint, &'self V)) -> bool) { - for uint::range(0, self.v.len()) |i| { - match self.v[i] { - Some(ref elt) => if !it(&(i, elt)) { break }, - None => () - } - } - } - - fn size_hint(&self) -> Option { Some(self.len()) } -} - -impl<'self, V> ReverseIter<(uint, &'self V)> for SmallIntMap { - /// Visit all key-value pairs in reverse order - fn each_reverse(&self, it: &fn(&(uint, &'self V)) -> bool) { - for uint::range_rev(self.v.len(), 0) |i| { - match self.v[i - 1] { - Some(ref elt) => if !it(&(i - 1, elt)) { break }, - None => () - } - } - } -} - impl Container for SmallIntMap { /// Return the number of elements in the map fn len(&const self) -> uint { @@ -76,14 +50,24 @@ impl Map for SmallIntMap { self.find(key).is_some() } + /// Visit all key-value pairs in order + fn each(&self, it: &fn(&uint, &'self V) -> bool) { + for uint::range(0, self.v.len()) |i| { + match self.v[i] { + Some(ref elt) => if !it(&i, elt) { break }, + None => () + } + } + } + /// Visit all keys in order fn each_key(&self, blk: &fn(key: &uint) -> bool) { - self.each(|&(k, _)| blk(&k)) + self.each(|k, _| blk(k)) } /// Visit all values in order fn each_value(&self, blk: &fn(value: &V) -> bool) { - self.each(|&(_, v)| blk(v)) + self.each(|_, v| blk(v)) } /// Iterate over the map and mutate the contained values @@ -149,6 +133,16 @@ pub impl SmallIntMap { /// Create an empty SmallIntMap fn new() -> SmallIntMap { SmallIntMap{v: ~[]} } + /// Visit all key-value pairs in reverse order + fn each_reverse(&self, it: &fn(uint, &'self V) -> bool) { + for uint::range_rev(self.v.len(), 0) |i| { + match self.v[i - 1] { + Some(ref elt) => if !it(i - 1, elt) { break }, + None => () + } + } + } + fn get(&self, key: &uint) -> &'self V { self.find(key).expect("key not present") } diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index d0868da4408d4..041ea855cb39d 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -82,24 +82,6 @@ impl Ord for TreeMap { fn gt(&self, other: &TreeMap) -> bool { lt(other, self) } } -impl<'self, K: TotalOrd, V> BaseIter<(&'self K, &'self V)> for TreeMap { - /// Visit all key-value pairs in order - fn each(&self, f: &fn(&(&'self K, &'self V)) -> bool) { - each(&self.root, f) - } - fn size_hint(&self) -> Option { Some(self.len()) } -} - -impl<'self, K: TotalOrd, V> - ReverseIter<(&'self K, &'self V)> - for TreeMap -{ - /// Visit all key-value pairs in reverse order - fn each_reverse(&self, f: &fn(&(&'self K, &'self V)) -> bool) { - each_reverse(&self.root, f); - } -} - impl Container for TreeMap { /// Return the number of elements in the map fn len(&const self) -> uint { self.length } @@ -122,12 +104,19 @@ impl Map for TreeMap { self.find(key).is_some() } + /// Visit all key-value pairs in order + fn each(&self, f: &fn(&'self K, &'self V) -> bool) { + each(&self.root, f) + } + /// Visit all keys in order - fn each_key(&self, f: &fn(&K) -> bool) { self.each(|&(k, _)| f(k)) } + fn each_key(&self, f: &fn(&K) -> bool) { + self.each(|k, _| f(k)) + } /// Visit all values in order fn each_value(&self, f: &fn(&V) -> bool) { - self.each(|&(_, v)| f(v)) + self.each(|_, v| f(v)) } /// Iterate over the map and mutate the contained values @@ -180,14 +169,19 @@ pub impl TreeMap { /// Create an empty TreeMap fn new() -> TreeMap { TreeMap{root: None, length: 0} } + /// Visit all key-value pairs in reverse order + fn each_reverse(&'self self, f: &fn(&'self K, &'self V) -> bool) { + each_reverse(&self.root, f); + } + /// Visit all keys in reverse order fn each_key_reverse(&self, f: &fn(&K) -> bool) { - self.each_reverse(|&(k, _)| f(k)) + self.each_reverse(|k, _| f(k)) } /// Visit all values in reverse order fn each_value_reverse(&self, f: &fn(&V) -> bool) { - self.each_reverse(|&(_, v)| f(v)) + self.each_reverse(|_, v| f(v)) } /// Get a lazy iterator over the key-value pairs in the map. @@ -538,18 +532,18 @@ pub impl TreeNode { } fn each<'r, K: TotalOrd, V>(node: &'r Option<~TreeNode>, - f: &fn(&(&'r K, &'r V)) -> bool) { + f: &fn(&'r K, &'r V) -> bool) { for node.each |x| { each(&x.left, f); - if f(&(&x.key, &x.value)) { each(&x.right, f) } + if f(&x.key, &x.value) { each(&x.right, f) } } } fn each_reverse<'r, K: TotalOrd, V>(node: &'r Option<~TreeNode>, - f: &fn(&(&'r K, &'r V)) -> bool) { + f: &fn(&'r K, &'r V) -> bool) { for node.each |x| { each_reverse(&x.right, f); - if f(&(&x.key, &x.value)) { each_reverse(&x.left, f) } + if f(&x.key, &x.value) { each_reverse(&x.left, f) } } } @@ -796,7 +790,7 @@ mod test_treemap { let &(k, v) = x; assert!(map.find(&k).unwrap() == &v) } - for map.each |&(map_k, map_v)| { + for map.each |map_k, map_v| { let mut found = false; for ctrl.each |x| { let &(ctrl_k, ctrl_v) = x; @@ -912,7 +906,7 @@ mod test_treemap { assert!(m.insert(1, 2)); let mut n = 0; - for m.each |&(k, v)| { + for m.each |k, v| { assert!(*k == n); assert!(*v == n * 2); n += 1; @@ -930,7 +924,7 @@ mod test_treemap { assert!(m.insert(1, 2)); let mut n = 4; - for m.each_reverse |&(k, v)| { + for m.each_reverse |k, v| { assert!(*k == n); assert!(*v == n * 2); n -= 1; diff --git a/src/libstd/workcache.rs b/src/libstd/workcache.rs index 3e494d0236e97..c4b450810aa86 100644 --- a/src/libstd/workcache.rs +++ b/src/libstd/workcache.rs @@ -145,7 +145,7 @@ impl WorkMap { impl Encodable for WorkMap { fn encode(&self, s: &S) { let mut d = ~[]; - for self.each |&(k, v)| { + for self.each |k, v| { d.push((copy *k, copy *v)) } sort::tim_sort(d); @@ -319,7 +319,7 @@ impl TPrep for Prep { } fn all_fresh(&self, cat: &str, map: &WorkMap) -> bool { - for map.each |&(k, v)| { + for map.each |k, v| { if ! self.is_fresh(cat, k.kind, k.name, *v) { return false; } diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 6ba1caa0d1e1a..c8b13a6e27fa3 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -48,7 +48,7 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str { let mut pairs = ~[]; // map -> [(k,%)] - for mm.each |&(&key, &val)| { + for mm.each |&key, &val| { pairs.push((key, pct(val, total))); } diff --git a/src/test/run-pass/class-impl-very-parameterized-trait.rs b/src/test/run-pass/class-impl-very-parameterized-trait.rs index 30ca5ea3881c9..cfde61d74b21b 100644 --- a/src/test/run-pass/class-impl-very-parameterized-trait.rs +++ b/src/test/run-pass/class-impl-very-parameterized-trait.rs @@ -49,18 +49,6 @@ pub impl cat { } } -impl<'self,T> BaseIter<(int, &'self T)> for cat { - fn each(&self, f: &fn(&(int, &'self T)) -> bool) { - let mut n = int::abs(self.meows); - while n > 0 { - if !f(&(n, &self.name)) { break; } - n -= 1; - } - } - - fn size_hint(&self) -> Option { Some(self.len()) } -} - impl Container for cat { fn len(&const self) -> uint { self.meows as uint } fn is_empty(&const self) -> bool { self.meows == 0 } @@ -71,17 +59,25 @@ impl Mutable for cat { } impl Map for cat { + fn each(&self, f: &fn(&int, &T) -> bool) { + let mut n = int::abs(self.meows); + while n > 0 { + if !f(&n, &self.name) { break; } + n -= 1; + } + } + fn contains_key(&self, k: &int) -> bool { *k <= self.meows } fn each_key(&self, f: &fn(v: &int) -> bool) { - for self.each |&(k, _)| { if !f(&k) { break; } loop;}; + for self.each |k, _| { if !f(k) { break; } loop;}; } fn each_value(&self, f: &fn(v: &T) -> bool) { - for self.each |&(_, v)| { if !f(v) { break; } loop;}; + for self.each |_, v| { if !f(v) { break; } loop;}; } - fn mutate_values(&mut self, f: &fn(&int, &mut T) -> bool) { + fn mutate_values(&mut self, _f: &fn(&int, &mut T) -> bool) { fail!(~"nope") } @@ -98,7 +94,7 @@ impl Map for cat { } } - fn find_mut(&mut self, k: &int) -> Option<&'self mut T> { fail!() } + fn find_mut(&mut self, _k: &int) -> Option<&'self mut T> { fail!() } fn remove(&mut self, k: &int) -> bool { if self.find(k).is_some() {