Skip to content

Commit eda1f34

Browse files
committed
---
yaml --- r: 54422 b: refs/heads/snap-stage3 c: 6dd20c8 h: refs/heads/master v: v3
1 parent 114eeb3 commit eda1f34

File tree

16 files changed

+850
-774
lines changed

16 files changed

+850
-774
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: 47011e3b710e9ef43a753defc467fefe5dcfd9f3
4+
refs/heads/snap-stage3: 6dd20c8186e1eb2819f50d09ddba6941b7ff85b8
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/etc/vim/syntax/rust.vim

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,17 @@ elseif exists("b:current_syntax")
1010
finish
1111
endif
1212

13-
syn keyword rustConditional match if else
14-
syn keyword rustOperator as
15-
16-
syn keyword rustKeyword break copy do drop extern
13+
syn match rustAssert "\<assert\(\w\)*"
14+
syn keyword rustKeyword as break
15+
syn keyword rustKeyword copy do drop else extern
1716
syn keyword rustKeyword for if impl let log
18-
syn keyword rustKeyword copy do drop extern
19-
syn keyword rustKeyword for impl let log
20-
syn keyword rustKeyword loop mod once priv pub
21-
syn keyword rustKeyword return
17+
syn keyword rustKeyword loop match mod once priv pub pure
18+
syn keyword rustKeyword ref return static
2219
syn keyword rustKeyword unsafe use while
2320
" FIXME: Scoped impl's name is also fallen in this category
2421
syn keyword rustKeyword mod trait struct enum type nextgroup=rustIdentifier skipwhite
2522
syn keyword rustKeyword fn nextgroup=rustFuncName skipwhite
26-
syn keyword rustStorage const mut ref static
23+
syn keyword rustStorage const mut
2724

2825
syn match rustIdentifier contains=rustIdentifierPrime "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
2926
syn match rustFuncName "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
@@ -74,8 +71,8 @@ syn keyword rustConstant STDIN_FILENO STDOUT_FILENO STDERR_FILENO
7471
syn match rustModPath "\w\(\w\)*::[^<]"he=e-3,me=e-3
7572
syn match rustModPathSep "::"
7673

77-
syn match rustFuncCall "\w\(\w\)*("he=e-1,me=e-1
78-
syn match rustFuncCall "\w\(\w\)*::<"he=e-3,me=e-3 " foo::<T>();
74+
syn match rustFuncCall "\w\(\w\)*("he=e-1,me=e-1 contains=rustAssert
75+
syn match rustFuncCall "\w\(\w\)*::<"he=e-3,me=e-3 contains=rustAssert " foo::<T>();
7976

8077
syn match rustMacro '\w\(\w\)*!'
8178
syn match rustMacro '#\w\(\w\)*'
@@ -113,7 +110,8 @@ syn match rustCharacter "'\([^'\\]\|\\\(['nrt\\\"]\|x\x\{2}\|u\x\{4}\|U\x\{8
113110
syn region rustComment start="/\*" end="\*/" contains=rustComment,rustTodo
114111
syn region rustComment start="//" skip="\\$" end="$" contains=rustTodo keepend
115112

116-
syn keyword rustTodo contained TODO FIXME XXX NB
113+
114+
syn keyword rustTodo TODO FIXME XXX NB unsafe
117115

118116
hi def link rustHexNumber rustNumber
119117
hi def link rustBinNumber rustNumber
@@ -128,9 +126,8 @@ hi def link rustBoolean Boolean
128126
hi def link rustConstant Constant
129127
hi def link rustSelf Constant
130128
hi def link rustFloat Float
131-
hi def link rustOperator Operator
129+
hi def link rustAssert Keyword
132130
hi def link rustKeyword Keyword
133-
hi def link rustConditional Conditional
134131
hi def link rustIdentifier Identifier
135132
hi def link rustModPath Include
136133
hi def link rustFuncName Function
@@ -143,6 +140,7 @@ hi def link rustStorage StorageClass
143140
hi def link rustLifetime Special
144141

145142
" Other Suggestions:
143+
" hi rustAssert ctermfg=yellow
146144
" hi rustMacro ctermfg=magenta
147145

148146
syn sync minlines=200

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,16 @@ pub mod linear {
393393
}
394394
}
395395
396-
pub impl<K:Hash + IterBytes + Eq,V> LinearMap<K, V> {
396+
pub impl<K: Hash + IterBytes + Eq, V> LinearMap<K, V> {
397397
/// Create an empty LinearMap
398398
fn new() -> LinearMap<K, V> {
399-
linear_map_with_capacity(INITIAL_CAPACITY)
399+
LinearMap::with_capacity(INITIAL_CAPACITY)
400+
}
401+
402+
/// Create an empty LinearMap with space for at least `n` elements in
403+
/// the hash table.
404+
fn with_capacity(capacity: uint) -> LinearMap<K, V> {
405+
linear_map_with_capacity(capacity)
400406
}
401407
402408
/// Reserve space for at least `n` elements in the hash table.
@@ -652,7 +658,15 @@ pub mod linear {
652658

653659
pub impl <T:Hash + IterBytes + Eq> LinearSet<T> {
654660
/// Create an empty LinearSet
655-
fn new() -> LinearSet<T> { LinearSet{map: LinearMap::new()} }
661+
fn new() -> LinearSet<T> {
662+
LinearSet::with_capacity(INITIAL_CAPACITY)
663+
}
664+
665+
/// Create an empty LinearSet with space for at least `n` elements in
666+
/// the hash table.
667+
fn with_capacity(capacity: uint) -> LinearSet<T> {
668+
LinearSet { map: LinearMap::with_capacity(capacity) }
669+
}
656670

657671
/// Reserve space for at least `n` elements in the hash table.
658672
fn reserve_at_least(&mut self, n: uint) {

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,28 @@ pub fn consume<T>(mut v: ~[T], f: &fn(uint, v: T)) {
560560
}
561561
}
562562
563+
pub fn consume_reverse<T>(mut v: ~[T], f: &fn(uint, v: T)) {
564+
unsafe {
565+
do as_mut_buf(v) |p, ln| {
566+
let mut i = ln;
567+
while i > 0 {
568+
i -= 1;
569+
570+
// NB: This unsafe operation counts on init writing 0s to the
571+
// holes we create in the vector. That ensures that, if the
572+
// iterator fails then we won't try to clean up the consumed
573+
// elements during unwinding
574+
let mut x = intrinsics::init();
575+
let p = ptr::mut_offset(p, i);
576+
x <-> *p;
577+
f(i, x);
578+
}
579+
}
580+
581+
raw::set_len(&mut v, 0);
582+
}
583+
}
584+
563585
/// Remove the last element from a vector and return it
564586
pub fn pop<T>(v: &mut ~[T]) -> T {
565587
let ln = v.len();
@@ -1985,6 +2007,7 @@ pub trait OwnedVector<T> {
19852007
fn truncate(&mut self, newlen: uint);
19862008
fn retain(&mut self, f: &fn(t: &T) -> bool);
19872009
fn consume(self, f: &fn(uint, v: T));
2010+
fn consume_reverse(self, f: &fn(uint, v: T));
19882011
fn filter(self, f: &fn(t: &T) -> bool) -> ~[T];
19892012
fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T]);
19902013
fn grow_fn(&mut self, n: uint, op: iter::InitOp<T>);
@@ -2046,6 +2069,11 @@ impl<T> OwnedVector<T> for ~[T] {
20462069
consume(self, f)
20472070
}
20482071

2072+
#[inline]
2073+
fn consume_reverse(self, f: &fn(uint, v: T)) {
2074+
consume_reverse(self, f)
2075+
}
2076+
20492077
#[inline]
20502078
fn filter(self, f: &fn(&T) -> bool) -> ~[T] {
20512079
filter(self, f)

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ trait read_method_map_entry_helper {
558558
fn encode_method_map_entry(ecx: @e::EncodeContext,
559559
ebml_w: writer::Encoder,
560560
mme: method_map_entry) {
561-
do ebml_w.emit_rec {
561+
do ebml_w.emit_struct("method_map_entry", 3) {
562562
do ebml_w.emit_field(~"self_arg", 0u) {
563563
ebml_w.emit_arg(ecx, mme.self_arg);
564564
}
@@ -574,7 +574,7 @@ fn encode_method_map_entry(ecx: @e::EncodeContext,
574574
impl read_method_map_entry_helper for reader::Decoder {
575575
fn read_method_map_entry(&self, xcx: @ExtendedDecodeContext)
576576
-> method_map_entry {
577-
do self.read_rec {
577+
do self.read_struct("method_map_entry", 3) {
578578
method_map_entry {
579579
self_arg: self.read_field(~"self_arg", 0u, || {
580580
self.read_arg(xcx)
@@ -778,7 +778,7 @@ impl ebml_writer_helpers for writer::Encoder {
778778
779779
fn emit_tpbt(&self, ecx: @e::EncodeContext,
780780
tpbt: ty::ty_param_bounds_and_ty) {
781-
do self.emit_rec {
781+
do self.emit_struct("ty_param_bounds_and_ty", 3) {
782782
do self.emit_field(~"bounds", 0) {
783783
do self.emit_from_vec(*tpbt.bounds) |bs| {
784784
self.emit_bounds(ecx, *bs);
@@ -1045,7 +1045,7 @@ impl ebml_decoder_decoder_helpers for reader::Decoder {
10451045
fn read_ty_param_bounds_and_ty(&self, xcx: @ExtendedDecodeContext)
10461046
-> ty::ty_param_bounds_and_ty
10471047
{
1048-
do self.read_rec {
1048+
do self.read_struct("ty_param_bounds_and_ty", 3) {
10491049
ty::ty_param_bounds_and_ty {
10501050
bounds: self.read_field(~"bounds", 0u, || {
10511051
@self.read_to_vec(|| self.read_bounds(xcx) )
@@ -1212,7 +1212,6 @@ fn mk_ctxt() -> @fake_ext_ctxt {
12121212
#[cfg(test)]
12131213
fn roundtrip(in_item: Option<@ast::item>) {
12141214
use core::io;
1215-
use std::prettyprint;
12161215

12171216
let in_item = in_item.get();
12181217
let bytes = do io::with_bytes_writer |wr| {
@@ -1222,17 +1221,7 @@ fn roundtrip(in_item: Option<@ast::item>) {
12221221
let ebml_doc = reader::Doc(@bytes);
12231222
let out_item = decode_item_ast(ebml_doc);
12241223

1225-
let exp_str = do io::with_str_writer |w| {
1226-
in_item.encode(&prettyprint::Serializer(w))
1227-
};
1228-
let out_str = do io::with_str_writer |w| {
1229-
out_item.encode(&prettyprint::Serializer(w))
1230-
};
1231-
1232-
debug!("expected string: %s", exp_str);
1233-
debug!("actual string : %s", out_str);
1234-
1235-
assert!(exp_str == out_str);
1224+
assert_eq!(in_item, out_item);
12361225
}
12371226

12381227
#[test]

branches/snap-stage3/src/libstd/deque.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ pub impl<T> Deque<T> {
6666
get(self.elts, idx)
6767
}
6868

69+
/// Iterate over the elements in the deque
70+
fn each(&self, f: &fn(&T) -> bool) {
71+
self.eachi(|_i, e| f(e))
72+
}
73+
74+
/// Iterate over the elements in the deque by index
75+
fn eachi(&self, f: &fn(uint, &T) -> bool) {
76+
for uint::range(0, self.nelts) |i| {
77+
if !f(i, self.get(i as int)) { return; }
78+
}
79+
}
80+
6981
/// Remove and return the first element in the deque
7082
///
7183
/// Fails if the deque is empty
@@ -223,6 +235,7 @@ mod tests {
223235
assert!(*deq.get(3) == d);
224236
}
225237

238+
#[test]
226239
fn test_parameterized<T:Copy + Eq + Durable>(a: T, b: T, c: T, d: T) {
227240
let mut deq = Deque::new();
228241
assert!(deq.len() == 0);
@@ -300,4 +313,23 @@ mod tests {
300313
let reccy4 = RecCy { x: 19, y: 252, t: Two(17, 42) };
301314
test_parameterized::<RecCy>(reccy1, reccy2, reccy3, reccy4);
302315
}
316+
317+
#[test]
318+
fn test_eachi() {
319+
let mut deq = Deque::new();
320+
deq.add_back(1);
321+
deq.add_back(2);
322+
deq.add_back(3);
323+
324+
for deq.eachi |i, e| {
325+
assert_eq!(*e, i + 1);
326+
}
327+
328+
deq.pop_front();
329+
330+
for deq.eachi |i, e| {
331+
assert_eq!(*e, i + 2);
332+
}
333+
334+
}
303335
}

0 commit comments

Comments
 (0)