Skip to content

Commit d7af184

Browse files
committed
---
yaml --- r: 66173 b: refs/heads/master c: cb58b19 h: refs/heads/master i: 66171: a8849c0 v: v3
1 parent 9b195a3 commit d7af184

File tree

10 files changed

+124
-56
lines changed

10 files changed

+124
-56
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 394f455b5edfe96b51bc713ccc65ad3db6bed92f
2+
refs/heads/master: cb58b19f023f95614e4a2bc3c812614d0938a9f2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/src/etc/vim/syntax/rust.vim

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Language: Rust
33
" Maintainer: Patrick Walton <[email protected]>
44
" Maintainer: Ben Blum <[email protected]>
5-
" Last Change: 2012 Jun 14
5+
" Last Change: 2012 Dec 25
66

77
if version < 600
88
syntax clear
@@ -13,16 +13,13 @@ endif
1313
syn keyword rustConditional match if else
1414
syn keyword rustOperator as
1515

16-
syn match rustAssert "\<assert\(\w\)*!"
17-
syn match rustFail "\<fail\(\w\)*!"
1816
syn keyword rustKeyword break copy do drop extern
1917
syn keyword rustKeyword for if impl let log
2018
syn keyword rustKeyword copy do extern
2119
syn keyword rustKeyword for impl let log
2220
syn keyword rustKeyword loop mod once priv pub
2321
syn keyword rustKeyword return
24-
syn keyword rustKeyword unsafe while
25-
syn keyword rustKeyword use nextgroup=rustModPath skipwhite
22+
syn keyword rustKeyword unsafe use while
2623
" FIXME: Scoped impl's name is also fallen in this category
2724
syn keyword rustKeyword mod trait struct enum type nextgroup=rustIdentifier skipwhite
2825
syn keyword rustKeyword fn nextgroup=rustFuncName skipwhite
@@ -48,8 +45,7 @@ syn keyword rustType c_longlong c_ulonglong intptr_t uintptr_t
4845
syn keyword rustType off_t dev_t ino_t pid_t mode_t ssize_t
4946

5047
syn keyword rustTrait Const Copy Send Owned Sized " inherent traits
51-
syn keyword rustTrait Clone Decodable Encodable IterBytes Rand ToStr
52-
syn keyword rustTrait Eq Ord TotalEq TotalOrd Num Ptr
48+
syn keyword rustTrait Eq Ord Num Ptr
5349
syn keyword rustTrait Drop Add Sub Mul Quot Rem Neg BitAnd BitOr
5450
syn keyword rustTrait BitXor Shl Shr Index
5551

@@ -76,21 +72,19 @@ syn keyword rustConstant STDIN_FILENO STDOUT_FILENO STDERR_FILENO
7672
" If foo::bar changes to foo.bar, change this ("::" to "\.").
7773
" If foo::bar changes to Foo::bar, change this (first "\w" to "\u").
7874
syn match rustModPath "\w\(\w\)*::[^<]"he=e-3,me=e-3
79-
syn match rustModPath "\w\(\w\)*" contained " only for 'use path;'
8075
syn match rustModPathSep "::"
8176

8277
syn match rustFuncCall "\w\(\w\)*("he=e-1,me=e-1
8378
syn match rustFuncCall "\w\(\w\)*::<"he=e-3,me=e-3 " foo::<T>();
8479

85-
syn match rustMacro '\w\(\w\)*!' contains=rustAssert,rustFail
86-
syn match rustMacro '#\w\(\w\)*' contains=rustAssert,rustFail
80+
syn match rustMacro '\w\(\w\)*!'
81+
syn match rustMacro '#\w\(\w\)*'
8782

8883
syn match rustFormat display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlLjzt]\|ll\|hh\)\=\([aAbdiuoxXDOUfFeEgGcCsSpn?]\|\[\^\=.[^]]*\]\)" contained
8984
syn match rustFormat display "%%" contained
9085
syn region rustString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=rustTodo,rustFormat
9186

92-
syn region rustAttribute start="#\[" end="\]" contains=rustString,rustDeriving
93-
syn region rustDeriving start="deriving(" end=")" contains=rustTrait
87+
syn region rustAttribute start="#\[" end="\]" contains=rustString
9488

9589
" Number literals
9690
syn match rustNumber display "\<[0-9][0-9_]*\>"
@@ -149,17 +143,11 @@ hi def link rustMacro Macro
149143
hi def link rustType Type
150144
hi def link rustTodo Todo
151145
hi def link rustAttribute PreProc
152-
hi def link rustDeriving PreProc
153146
hi def link rustStorage StorageClass
154147
hi def link rustLifetime Special
155148

156149
" Other Suggestions:
157-
" hi rustAttribute ctermfg=cyan
158-
" hi rustDeriving ctermfg=cyan
159-
" hi rustAssert ctermfg=yellow
160-
" hi rustFail ctermfg=red
161150
" hi rustMacro ctermfg=magenta
162-
" hi rustModPathSep ctermfg=grey
163151

164152
syn sync minlines=200
165153
syn sync maxlines=500

trunk/src/libstd/hashmap.rs

Lines changed: 106 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@
1818
use container::{Container, Mutable, Map, Set};
1919
use cmp::{Eq, Equiv};
2020
use hash::Hash;
21-
use old_iter::BaseIter;
22-
use old_iter;
23-
use iterator::IteratorUtil;
21+
use iterator::{Iterator, IteratorUtil};
2422
use option::{None, Option, Some};
2523
use rand::RngUtil;
2624
use rand;
2725
use uint;
2826
use vec;
29-
use vec::ImmutableVector;
27+
use vec::{ImmutableVector, MutableVector};
3028
use kinds::Copy;
3129
use util::{replace, unreachable};
3230

@@ -311,24 +309,17 @@ impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
311309

312310
/// Visit all key-value pairs
313311
fn each<'a>(&'a self, blk: &fn(&K, &'a V) -> bool) -> bool {
314-
for self.buckets.iter().advance |bucket| {
315-
for bucket.iter().advance |pair| {
316-
if !blk(&pair.key, &pair.value) {
317-
return false;
318-
}
319-
}
320-
}
321-
return true;
312+
self.iter().advance(|(k, v)| blk(k, v))
322313
}
323314

324315
/// Visit all keys
325316
fn each_key(&self, blk: &fn(k: &K) -> bool) -> bool {
326-
self.each(|k, _| blk(k))
317+
self.iter().advance(|(k, _)| blk(k))
327318
}
328319

329320
/// Visit all values
330321
fn each_value<'a>(&'a self, blk: &fn(v: &'a V) -> bool) -> bool {
331-
self.each(|_, v| blk(v))
322+
self.iter().advance(|(_, v)| blk(v))
332323
}
333324

334325
/// Iterate over the map and mutate the contained values
@@ -524,6 +515,19 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
524515
TableFull | FoundHole(_) => None,
525516
}
526517
}
518+
519+
/// An iterator visiting all key-value pairs in arbitrary order.
520+
/// Iterator element type is (&'a K, &'a V).
521+
pub fn iter<'a>(&'a self) -> HashMapIterator<'a, K, V> {
522+
HashMapIterator { iter: self.buckets.iter() }
523+
}
524+
525+
/// An iterator visiting all key-value pairs in arbitrary order,
526+
/// with mutable references to the values.
527+
/// Iterator element type is (&'a K, &'a mut V).
528+
pub fn mut_iter<'a>(&'a mut self) -> HashMapMutIterator<'a, K, V> {
529+
HashMapMutIterator { iter: self.buckets.mut_iter() }
530+
}
527531
}
528532

529533
impl<K: Hash + Eq, V: Copy> HashMap<K, V> {
@@ -542,7 +546,7 @@ impl<K:Hash + Eq,V:Eq> Eq for HashMap<K, V> {
542546
fn eq(&self, other: &HashMap<K, V>) -> bool {
543547
if self.len() != other.len() { return false; }
544548

545-
for self.each |key, value| {
549+
for self.iter().advance |(key, value)| {
546550
match other.find(key) {
547551
None => return false,
548552
Some(v) => if value != v { return false },
@@ -555,19 +559,68 @@ impl<K:Hash + Eq,V:Eq> Eq for HashMap<K, V> {
555559
fn ne(&self, other: &HashMap<K, V>) -> bool { !self.eq(other) }
556560
}
557561

562+
/// HashMap iterator
563+
pub struct HashMapIterator<'self, K, V> {
564+
priv iter: vec::VecIterator<'self, Option<Bucket<K, V>>>,
565+
}
566+
567+
/// HashMap mutable values iterator
568+
pub struct HashMapMutIterator<'self, K, V> {
569+
priv iter: vec::VecMutIterator<'self, Option<Bucket<K, V>>>,
570+
}
571+
572+
/// HashSet iterator
573+
pub struct HashSetIterator<'self, K> {
574+
priv iter: vec::VecIterator<'self, Option<Bucket<K, ()>>>,
575+
}
576+
577+
impl<'self, K, V> Iterator<(&'self K, &'self V)> for HashMapIterator<'self, K, V> {
578+
#[inline]
579+
fn next(&mut self) -> Option<(&'self K, &'self V)> {
580+
for self.iter.advance |elt| {
581+
match elt {
582+
&Some(ref bucket) => return Some((&bucket.key, &bucket.value)),
583+
&None => {},
584+
}
585+
}
586+
None
587+
}
588+
}
589+
590+
impl<'self, K, V> Iterator<(&'self K, &'self mut V)> for HashMapMutIterator<'self, K, V> {
591+
#[inline]
592+
fn next(&mut self) -> Option<(&'self K, &'self mut V)> {
593+
for self.iter.advance |elt| {
594+
match elt {
595+
&Some(ref mut bucket) => return Some((&bucket.key, &mut bucket.value)),
596+
&None => {},
597+
}
598+
}
599+
None
600+
}
601+
}
602+
603+
impl<'self, K> Iterator<&'self K> for HashSetIterator<'self, K> {
604+
#[inline]
605+
fn next(&mut self) -> Option<&'self K> {
606+
for self.iter.advance |elt| {
607+
match elt {
608+
&Some(ref bucket) => return Some(&bucket.key),
609+
&None => {},
610+
}
611+
}
612+
None
613+
}
614+
}
615+
616+
558617
/// An implementation of a hash set using the underlying representation of a
559618
/// HashMap where the value is (). As with the `HashMap` type, a `HashSet`
560619
/// requires that the elements implement the `Eq` and `Hash` traits.
561620
pub struct HashSet<T> {
562621
priv map: HashMap<T, ()>
563622
}
564623

565-
impl<T:Hash + Eq> BaseIter<T> for HashSet<T> {
566-
/// Visit all values in order
567-
fn each(&self, f: &fn(&T) -> bool) -> bool { self.map.each_key(f) }
568-
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
569-
}
570-
571624
impl<T:Hash + Eq> Eq for HashSet<T> {
572625
fn eq(&self, other: &HashSet<T>) -> bool { self.map == other.map }
573626
fn ne(&self, other: &HashSet<T>) -> bool { self.map != other.map }
@@ -601,12 +654,12 @@ impl<T:Hash + Eq> Set<T> for HashSet<T> {
601654
/// Return true if the set has no elements in common with `other`.
602655
/// This is equivalent to checking for an empty intersection.
603656
fn is_disjoint(&self, other: &HashSet<T>) -> bool {
604-
old_iter::all(self, |v| !other.contains(v))
657+
self.iter().all(|v| !other.contains(v))
605658
}
606659

607660
/// Return true if the set is a subset of another
608661
fn is_subset(&self, other: &HashSet<T>) -> bool {
609-
old_iter::all(self, |v| other.contains(v))
662+
self.iter().all(|v| other.contains(v))
610663
}
611664

612665
/// Return true if the set is a superset of another
@@ -616,7 +669,7 @@ impl<T:Hash + Eq> Set<T> for HashSet<T> {
616669

617670
/// Visit the values representing the difference
618671
fn difference(&self, other: &HashSet<T>, f: &fn(&T) -> bool) -> bool {
619-
self.each(|v| other.contains(v) || f(v))
672+
self.iter().advance(|v| other.contains(v) || f(v))
620673
}
621674

622675
/// Visit the values representing the symmetric difference
@@ -628,12 +681,12 @@ impl<T:Hash + Eq> Set<T> for HashSet<T> {
628681

629682
/// Visit the values representing the intersection
630683
fn intersection(&self, other: &HashSet<T>, f: &fn(&T) -> bool) -> bool {
631-
self.each(|v| !other.contains(v) || f(v))
684+
self.iter().advance(|v| !other.contains(v) || f(v))
632685
}
633686

634687
/// Visit the values representing the union
635688
fn union(&self, other: &HashSet<T>, f: &fn(&T) -> bool) -> bool {
636-
self.each(f) && other.each(|v| self.contains(v) || f(v))
689+
self.iter().advance(f) && other.iter().advance(|v| self.contains(v) || f(v))
637690
}
638691
}
639692

@@ -664,6 +717,18 @@ impl<T:Hash + Eq> HashSet<T> {
664717
pub fn contains_equiv<Q:Hash + Equiv<T>>(&self, value: &Q) -> bool {
665718
self.map.contains_key_equiv(value)
666719
}
720+
721+
/// Visit all elements in arbitrary order
722+
/// FIXME: #6978: Remove when all callers are converted
723+
pub fn each(&self, f: &fn(&T) -> bool) -> bool {
724+
self.iter().advance(f)
725+
}
726+
727+
/// An iterator visiting all elements in arbitrary order.
728+
/// Iterator element type is &'a T.
729+
pub fn iter<'a>(&'a self) -> HashSetIterator<'a, T> {
730+
HashSetIterator { iter: self.map.buckets.iter() }
731+
}
667732
}
668733

669734
#[cfg(test)]
@@ -808,7 +873,7 @@ mod test_map {
808873
assert!(m.insert(i, i*2));
809874
}
810875
let mut observed = 0;
811-
for m.each |k, v| {
876+
for m.iter().advance |(k, v)| {
812877
assert_eq!(*v, *k * 2);
813878
observed |= (1 << *k);
814879
}
@@ -885,6 +950,7 @@ mod test_set {
885950
use super::*;
886951
use container::{Container, Map, Set};
887952
use vec;
953+
use uint;
888954

889955
#[test]
890956
fn test_disjoint() {
@@ -937,6 +1003,19 @@ mod test_set {
9371003
assert!(b.is_superset(&a));
9381004
}
9391005

1006+
#[test]
1007+
fn test_iterate() {
1008+
let mut a = HashSet::new();
1009+
for uint::range(0, 32) |i| {
1010+
assert!(a.insert(i));
1011+
}
1012+
let mut observed = 0;
1013+
for a.iter().advance |k| {
1014+
observed |= (1 << *k);
1015+
}
1016+
assert_eq!(observed, 0xFFFF_FFFF);
1017+
}
1018+
9401019
#[test]
9411020
fn test_intersection() {
9421021
let mut a = HashSet::new();

trunk/src/libstd/to_str.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use hash::Hash;
2323
use cmp::Eq;
2424
use old_iter::BaseIter;
2525
use vec::ImmutableVector;
26+
use iterator::IteratorUtil;
2627

2728
/// A generic trait for converting a value to a string
2829
pub trait ToStr {
@@ -56,7 +57,7 @@ impl<A:ToStr+Hash+Eq, B:ToStr+Hash+Eq> ToStr for HashMap<A, B> {
5657
#[inline]
5758
fn to_str(&self) -> ~str {
5859
let mut (acc, first) = (~"{", true);
59-
for self.each |key, value| {
60+
for self.iter().advance |(key, value)| {
6061
if first {
6162
first = false;
6263
}
@@ -76,7 +77,7 @@ impl<A:ToStr+Hash+Eq> ToStr for HashSet<A> {
7677
#[inline]
7778
fn to_str(&self) -> ~str {
7879
let mut (acc, first) = (~"{", true);
79-
for self.each |element| {
80+
for self.iter().advance |element| {
8081
if first {
8182
first = false;
8283
}

trunk/src/test/compile-fail/class-cast-to-trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
5858

5959
fn main() {
6060
let nyan : @noisy = @cat(0, 2, ~"nyan") as @noisy;
61-
nyan.eat(); //~ ERROR does not implement any method in scope named `eat`
61+
nyan.eat(); //~ ERROR type `@noisy` does not implement any method in scope named `eat`
6262
}

trunk/src/test/compile-fail/extern-wrong-value-type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ extern fn f() {
1313

1414
fn main() {
1515
// extern functions are *u8 types
16-
let _x: &fn() = f; //~ ERROR found `*u8`
16+
let _x: &fn() = f; //~ ERROR mismatched types: expected `&fn()` but found `*u8`
1717
}

trunk/src/test/compile-fail/issue-4523.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
fn foopy() {}
1212

13-
static f: &'static fn() = foopy; //~ ERROR found extern fn
13+
static f: &'static fn() = foopy; //~ ERROR mismatched types: expected `&'static fn()`
1414

1515
fn main () {
1616
f();

trunk/src/test/compile-fail/issue-4972.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ pub enum TraitWrapper {
1616

1717
fn get_tw_map<'lt>(tw: &'lt TraitWrapper) -> &'lt MyTrait {
1818
match *tw {
19-
A(~ref map) => map, //~ ERROR found a ~-box pattern
19+
A(~ref map) => map, //~ ERROR mismatched types: expected `~MyTrait` but found a ~-box pattern
2020
}
2121
}
2222

23-
pub fn main() {}
23+
pub fn main() {}

trunk/src/test/compile-fail/map-types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ fn main() {
1717
let x: @Map<~str, ~str> = @HashMap::new::<~str, ~str>() as
1818
@Map<~str, ~str>;
1919
let y: @Map<uint, ~str> = @x;
20-
//~^ ERROR expected trait std::container::Map but found @-ptr
20+
//~^ ERROR mismatched types: expected `@std::container::Map<uint,~str>`
2121
}

0 commit comments

Comments
 (0)