Skip to content

Commit fe1902e

Browse files
committed
---
yaml --- r: 54614 b: refs/heads/snap-stage3 c: 48e7bda h: refs/heads/master v: v3
1 parent e56bfd6 commit fe1902e

40 files changed

+251
-225
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 5f13e9ccc2e3328d4cd8ca49f84e6840dd998346
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: ac9dc69bf3c0e4c46fadeab76229ba35f61d8158
4+
refs/heads/snap-stage3: 48e7bda8269861df43763b4fb42e68af0eb09b20
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libcore/container.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ pub trait Map<K, V>: Mutable {
2929
/// Return true if the map contains a value for the specified key
3030
fn contains_key(&self, key: &K) -> bool;
3131

32-
// Visits all keys and values
33-
fn each(&self, f: &fn(&K, &V) -> bool);
34-
3532
/// Visit all keys
3633
fn each_key(&self, f: &fn(&K) -> bool);
3734

branches/snap-stage3/src/libcore/hashmap.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,24 @@ priv impl<K:Hash + IterBytes + Eq,V> HashMap<K, V> {
279279
}
280280
}
281281
282+
impl<'self,K:Hash + IterBytes + Eq,V>
283+
BaseIter<(&'self K, &'self V)> for HashMap<K, V> {
284+
/// Visit all key-value pairs
285+
fn each(&self, blk: &fn(&(&'self K, &'self V)) -> bool) {
286+
for uint::range(0, self.buckets.len()) |i| {
287+
let mut broke = false;
288+
do self.buckets[i].map |bucket| {
289+
if !blk(&(&bucket.key, &bucket.value)) {
290+
broke = true; // FIXME(#3064) just write "break;"
291+
}
292+
};
293+
if broke { break; }
294+
}
295+
}
296+
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
297+
}
298+
299+
282300
impl<K:Hash + IterBytes + Eq,V> Container for HashMap<K, V> {
283301
/// Return the number of elements in the map
284302
fn len(&const self) -> uint { self.size }
@@ -297,7 +315,7 @@ impl<K:Hash + IterBytes + Eq,V> Mutable for HashMap<K, V> {
297315
}
298316
}
299317
300-
impl<K:Hash + IterBytes + Eq,V> Map<K, V> for HashMap<K, V> {
318+
impl<'self,K:Hash + IterBytes + Eq,V> Map<K, V> for HashMap<K, V> {
301319
/// Return true if the map contains a value for the specified key
302320
fn contains_key(&self, k: &K) -> bool {
303321
match self.bucket_for_key(k) {
@@ -306,25 +324,14 @@ impl<K:Hash + IterBytes + Eq,V> Map<K, V> for HashMap<K, V> {
306324
}
307325
}
308326
309-
/// Visit all key-value pairs
310-
fn each(&self, blk: &fn(&'self K, &'self V) -> bool) {
311-
for uint::range(0, self.buckets.len()) |i| {
312-
for self.buckets[i].each |bucket| {
313-
if !blk(&bucket.key, &bucket.value) {
314-
return;
315-
}
316-
}
317-
}
318-
}
319-
320327
/// Visit all keys
321328
fn each_key(&self, blk: &fn(k: &K) -> bool) {
322-
self.each(|k, _| blk(k))
329+
self.each(|&(k, _)| blk(k))
323330
}
324331
325332
/// Visit all values
326333
fn each_value(&self, blk: &fn(v: &V) -> bool) {
327-
self.each(|_, v| blk(v))
334+
self.each(|&(_, v)| blk(v))
328335
}
329336
330337
/// Iterate over the map and mutate the contained values
@@ -538,7 +545,7 @@ impl<K:Hash + IterBytes + Eq,V:Eq> Eq for HashMap<K, V> {
538545
fn eq(&self, other: &HashMap<K, V>) -> bool {
539546
if self.len() != other.len() { return false; }
540547

541-
for self.each |key, value| {
548+
for self.each |&(key, value)| {
542549
match other.find(key) {
543550
None => return false,
544551
Some(v) => if value != v { return false },
@@ -791,7 +798,7 @@ mod test_map {
791798
assert!(m.insert(i, i*2));
792799
}
793800
let mut observed = 0;
794-
for m.each |k, v| {
801+
for m.each |&(k, v)| {
795802
assert!(*v == *k * 2);
796803
observed |= (1 << *k);
797804
}

branches/snap-stage3/src/libcore/trie.rs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ pub struct TrieMap<T> {
2828
priv length: uint
2929
}
3030

31+
impl<'self,T> BaseIter<(uint, &'self T)> for TrieMap<T> {
32+
/// Visit all key-value pairs in order
33+
#[inline(always)]
34+
fn each(&self, f: &fn(&(uint, &'self T)) -> bool) {
35+
self.root.each(f);
36+
}
37+
#[inline(always)]
38+
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
39+
}
40+
41+
impl<'self,T> ReverseIter<(uint, &'self T)> for TrieMap<T> {
42+
/// Visit all key-value pairs in reverse order
43+
#[inline(always)]
44+
fn each_reverse(&self, f: &fn(&(uint, &'self T)) -> bool) {
45+
self.root.each_reverse(f);
46+
}
47+
}
48+
3149
impl<T> Container for TrieMap<T> {
3250
/// Return the number of elements in the map
3351
#[inline(always)]
@@ -54,22 +72,16 @@ impl<T> Map<uint, T> for TrieMap<T> {
5472
self.find(key).is_some()
5573
}
5674

57-
/// Visit all key-value pairs in order
58-
#[inline(always)]
59-
fn each(&self, f: &fn(&uint, &'self T) -> bool) {
60-
self.root.each(f);
61-
}
62-
6375
/// Visit all keys in order
6476
#[inline(always)]
6577
fn each_key(&self, f: &fn(&uint) -> bool) {
66-
self.each(|k, _| f(k))
78+
self.each(|&(k, _)| f(&k))
6779
}
6880

6981
/// Visit all values in order
7082
#[inline(always)]
7183
fn each_value(&self, f: &fn(&T) -> bool) {
72-
self.each(|_, v| f(v))
84+
self.each(|&(_, v)| f(v))
7385
}
7486

7587
/// Iterate over the map and mutate the contained values
@@ -136,22 +148,16 @@ pub impl<T> TrieMap<T> {
136148
TrieMap{root: TrieNode::new(), length: 0}
137149
}
138150

139-
/// Visit all key-value pairs in reverse order
140-
#[inline(always)]
141-
fn each_reverse(&self, f: &fn(&uint, &'self T) -> bool) {
142-
self.root.each_reverse(f);
143-
}
144-
145151
/// Visit all keys in reverse order
146152
#[inline(always)]
147153
fn each_key_reverse(&self, f: &fn(&uint) -> bool) {
148-
self.each_reverse(|k, _| f(k))
154+
self.each_reverse(|&(k, _)| f(&k))
149155
}
150156

151157
/// Visit all values in reverse order
152158
#[inline(always)]
153159
fn each_value_reverse(&self, f: &fn(&T) -> bool) {
154-
self.each_reverse(|_, v| f(v))
160+
self.each_reverse(|&(_, v)| f(v))
155161
}
156162
}
157163

@@ -233,22 +239,22 @@ impl<T> TrieNode<T> {
233239
}
234240

235241
impl<T> TrieNode<T> {
236-
fn each(&self, f: &fn(&uint, &'self T) -> bool) -> bool {
242+
fn each(&self, f: &fn(&(uint, &'self T)) -> bool) -> bool {
237243
for uint::range(0, self.children.len()) |idx| {
238244
match self.children[idx] {
239245
Internal(ref x) => if !x.each(f) { return false },
240-
External(k, ref v) => if !f(&k, v) { return false },
246+
External(k, ref v) => if !f(&(k, v)) { return false },
241247
Nothing => ()
242248
}
243249
}
244250
true
245251
}
246252

247-
fn each_reverse(&self, f: &fn(&uint, &'self T) -> bool) -> bool {
253+
fn each_reverse(&self, f: &fn(&(uint, &'self T)) -> bool) -> bool {
248254
for uint::range_rev(self.children.len(), 0) |idx| {
249255
match self.children[idx - 1] {
250256
Internal(ref x) => if !x.each_reverse(f) { return false },
251-
External(k, ref v) => if !f(&k, v) { return false },
257+
External(k, ref v) => if !f(&(k, v)) { return false },
252258
Nothing => ()
253259
}
254260
}
@@ -432,8 +438,8 @@ mod tests {
432438
assert!(m.insert(1, 2));
433439

434440
let mut n = 0;
435-
for m.each |k, v| {
436-
assert!(*k == n);
441+
for m.each |&(k, v)| {
442+
assert!(k == n);
437443
assert!(*v == n * 2);
438444
n += 1;
439445
}
@@ -448,11 +454,11 @@ mod tests {
448454
}
449455

450456
let mut n = uint::max_value - 9999;
451-
for m.each |k, v| {
457+
for m.each |&(k, v)| {
452458
if n == uint::max_value - 5000 { break }
453459
assert!(n < uint::max_value - 5000);
454460

455-
assert!(*k == n);
461+
assert!(k == n);
456462
assert!(*v == n / 2);
457463
n += 1;
458464
}
@@ -469,8 +475,8 @@ mod tests {
469475
assert!(m.insert(1, 2));
470476

471477
let mut n = 4;
472-
for m.each_reverse |k, v| {
473-
assert!(*k == n);
478+
for m.each_reverse |&(k, v)| {
479+
assert!(k == n);
474480
assert!(*v == n * 2);
475481
n -= 1;
476482
}
@@ -485,11 +491,11 @@ mod tests {
485491
}
486492

487493
let mut n = uint::max_value;
488-
for m.each_reverse |k, v| {
494+
for m.each_reverse |&(k, v)| {
489495
if n == uint::max_value - 5000 { break }
490496
assert!(n > uint::max_value - 5000);
491497

492-
assert!(*k == n);
498+
assert!(k == n);
493499
assert!(*v == n / 2);
494500
n -= 1;
495501
}

branches/snap-stage3/src/librustc/front/core_inject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn inject_libcore_ref(sess: Session,
7777
fold_mod: |module, fld| {
7878
let n2 = sess.next_node_id();
7979

80-
let prelude_path = @ast::path {
80+
let prelude_path = @ast::Path {
8181
span: dummy_sp(),
8282
global: false,
8383
idents: ~[

branches/snap-stage3/src/librustc/front/test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,16 +336,16 @@ fn nospan<T:Copy>(t: T) -> codemap::spanned<T> {
336336
codemap::spanned { node: t, span: dummy_sp() }
337337
}
338338

339-
fn path_node(+ids: ~[ast::ident]) -> @ast::path {
340-
@ast::path { span: dummy_sp(),
339+
fn path_node(+ids: ~[ast::ident]) -> @ast::Path {
340+
@ast::Path { span: dummy_sp(),
341341
global: false,
342342
idents: ids,
343343
rp: None,
344344
types: ~[] }
345345
}
346346

347-
fn path_node_global(+ids: ~[ast::ident]) -> @ast::path {
348-
@ast::path { span: dummy_sp(),
347+
fn path_node_global(+ids: ~[ast::ident]) -> @ast::Path {
348+
@ast::Path { span: dummy_sp(),
349349
global: true,
350350
idents: ids,
351351
rp: None,

branches/snap-stage3/src/librustc/metadata/cstore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub fn have_crate_data(cstore: &CStore, cnum: ast::crate_num) -> bool {
8686

8787
pub fn iter_crate_data(cstore: &CStore,
8888
i: &fn(ast::crate_num, @crate_metadata)) {
89-
for cstore.metas.each |&k, &v| {
89+
for cstore.metas.each |&(&k, &v)| {
9090
i(k, v);
9191
}
9292
}

branches/snap-stage3/src/librustc/metadata/tydecode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub fn parse_arg_data(data: @~[u8], crate_num: int, pos: uint, tcx: ty::ctxt,
137137
parse_arg(st, conv)
138138
}
139139

140-
fn parse_path(st: @mut PState) -> @ast::path {
140+
fn parse_path(st: @mut PState) -> @ast::Path {
141141
let mut idents: ~[ast::ident] = ~[];
142142
fn is_last(c: char) -> bool { return c == '(' || c == ':'; }
143143
idents.push(parse_ident_(st, is_last));
@@ -146,7 +146,7 @@ fn parse_path(st: @mut PState) -> @ast::path {
146146
':' => { next(st); next(st); }
147147
c => {
148148
if c == '(' {
149-
return @ast::path { span: dummy_sp(),
149+
return @ast::Path { span: dummy_sp(),
150150
global: false,
151151
idents: idents,
152152
rp: None,

branches/snap-stage3/src/librustc/middle/lang_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ pub impl<'self> LanguageItemCollector<'self> {
397397
}
398398

399399
fn check_completeness(&self) {
400-
for self.item_refs.each |&key, &item_ref| {
400+
for self.item_refs.each |&(&key, &item_ref)| {
401401
match self.items.items[item_ref] {
402402
None => {
403403
self.session.err(fmt!("no item found for `%s`", *key));

branches/snap-stage3/src/librustc/middle/lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ pub fn build_settings_crate(sess: session::Session, crate: @ast::crate) {
460460

461461
do cx.with_lint_attrs(/*bad*/copy crate.node.attrs) |cx| {
462462
// Copy out the default settings
463-
for cx.curr.each |&k, &v| {
463+
for cx.curr.each |&(k, &v)| {
464464
sess.lint_settings.default_settings.insert(k, v);
465465
}
466466

branches/snap-stage3/src/librustc/middle/pat_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn pat_is_binding_or_wild(dm: resolve::DefMap, pat: @pat) -> bool {
7272
}
7373

7474
pub fn pat_bindings(dm: resolve::DefMap, pat: @pat,
75-
it: &fn(binding_mode, node_id, span, @path)) {
75+
it: &fn(binding_mode, node_id, span, @Path)) {
7676
do walk_pat(pat) |p| {
7777
match p.node {
7878
pat_ident(binding_mode, pth, _) if pat_is_binding(dm, p) => {

branches/snap-stage3/src/librustc/middle/privacy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use syntax::ast::{decl_item, def, def_fn, def_id, def_static_method};
2626
use syntax::ast::{def_variant, expr_field, expr_method_call, expr_path};
2727
use syntax::ast::{expr_struct, expr_unary, ident, inherited, item_enum};
2828
use syntax::ast::{item_foreign_mod, item_fn, item_impl, item_struct};
29-
use syntax::ast::{item_trait, local_crate, node_id, pat_struct, path};
29+
use syntax::ast::{item_trait, local_crate, node_id, pat_struct, Path};
3030
use syntax::ast::{private, provided, public, required, stmt_decl, visibility};
3131
use syntax::ast;
3232
use syntax::ast_map::{node_foreign_item, node_item, node_method};
@@ -276,7 +276,7 @@ pub fn check_crate(tcx: ty::ctxt,
276276
};
277277

278278
// Checks that a private path is in scope.
279-
let check_path: @fn(span: span, def: def, path: @path) =
279+
let check_path: @fn(span: span, def: def, path: @Path) =
280280
|span, def, path| {
281281
debug!("checking path");
282282
match def {

branches/snap-stage3/src/librustc/middle/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ pub fn determine_rp_in_crate(sess: Session,
842842
debug!("%s", {
843843
debug!("Region variance results:");
844844
let region_paramd_items = cx.region_paramd_items;
845-
for region_paramd_items.each |&key, &value| {
845+
for region_paramd_items.each |&(&key, &value)| {
846846
debug!("item %? (%s) is parameterized with variance %?",
847847
key,
848848
ast_map::node_id_to_str(ast_map, key,

0 commit comments

Comments
 (0)