Skip to content

Commit b5cc693

Browse files
committed
1 parent 87004db commit b5cc693

File tree

92 files changed

+2465
-2530
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+2465
-2530
lines changed

doc/guide-container.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,25 @@ never call its underlying iterator again once `None` has been returned:
181181
~~~
182182
let xs = [1,2,3,4,5];
183183
let mut calls = 0;
184-
let it = xs.iter().scan((), |_, x| {
185-
calls += 1;
186-
if *x < 3 { Some(x) } else { None }});
187-
// the iterator will only yield 1 and 2 before returning None
188-
// If we were to call it 5 times, calls would end up as 5, despite only 2 values
189-
// being yielded (and therefore 3 unique calls being made). The fuse() adaptor
190-
// can fix this.
191-
let mut it = it.fuse();
192-
it.next();
193-
it.next();
194-
it.next();
195-
it.next();
196-
it.next();
184+
185+
{
186+
let it = xs.iter().scan((), |_, x| {
187+
calls += 1;
188+
if *x < 3 { Some(x) } else { None }});
189+
190+
// the iterator will only yield 1 and 2 before returning None
191+
// If we were to call it 5 times, calls would end up as 5, despite
192+
// only 2 values being yielded (and therefore 3 unique calls being
193+
// made). The fuse() adaptor can fix this.
194+
195+
let mut it = it.fuse();
196+
it.next();
197+
it.next();
198+
it.next();
199+
it.next();
200+
it.next();
201+
}
202+
197203
assert_eq!(calls, 3);
198204
~~~
199205

src/libextra/getopts.rs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
521521
pub mod groups {
522522
use getopts::{HasArg, Long, Maybe, Multi, No, Occur, Opt, Optional, Req};
523523
use getopts::{Short, Yes};
524+
use std::cell::Cell;
524525
525526
/// One group of options, e.g., both -h and --help, along with
526527
/// their shared description and properties.
@@ -680,7 +681,7 @@ pub mod groups {
680681

681682
let desc_sep = "\n" + " ".repeat(24);
682683

683-
let mut rows = opts.iter().map(|optref| {
684+
let rows = opts.iter().map(|optref| {
684685
let OptGroup{short_name: short_name,
685686
long_name: long_name,
686687
hint: hint,
@@ -752,9 +753,9 @@ pub mod groups {
752753
row.push_str(desc_rows.connect(desc_sep));
753754

754755
row
755-
});
756+
}).collect::<~[~str]>();
756757

757-
format!("{}\n\nOptions:\n{}\n", brief, rows.collect::<~[~str]>().connect("\n"))
758+
format!("{}\n\nOptions:\n{}\n", brief, rows.connect("\n"))
758759
}
759760

760761
/// Splits a string into substrings with possibly internal whitespace,
@@ -793,8 +794,10 @@ pub mod groups {
793794
let mut fake_i = ss.len();
794795
let mut lim = lim;
795796

796-
let mut cont = true;
797-
let slice: || = || { cont = it(ss.slice(slice_start, last_end)) };
797+
let cont = Cell::new(true);
798+
let slice: |a: uint, b: uint| = |a, b| {
799+
cont.set(it(ss.slice(a, b)))
800+
};
798801

799802
// if the limit is larger than the string, lower it to save cycles
800803
if lim >= fake_i {
@@ -813,27 +816,37 @@ pub mod groups {
813816
(B, Cr, OverLim) if (i - last_start + 1) > lim
814817
=> fail!("word starting with {} longer than limit!",
815818
ss.slice(last_start, i + 1)),
816-
(B, Cr, OverLim) => { slice(); slice_start = last_start; B }
817-
(B, Ws, UnderLim) => { last_end = i; C }
818-
(B, Ws, OverLim) => { last_end = i; slice(); A }
819+
(B, Cr, OverLim) => { slice(slice_start, last_end);
820+
slice_start = last_start;
821+
B }
822+
(B, Ws, UnderLim) => { last_end = i;
823+
C }
824+
(B, Ws, OverLim) => { last_end = i;
825+
slice(slice_start, last_end);
826+
A }
819827

820828
(C, Cr, UnderLim) => { last_start = i; B }
821-
(C, Cr, OverLim) => { slice(); slice_start = i; last_start = i; last_end = i; B }
822-
(C, Ws, OverLim) => { slice(); A }
829+
(C, Cr, OverLim) => { slice(slice_start, last_end);
830+
slice_start = i;
831+
last_start = i;
832+
last_end = i;
833+
B }
834+
(C, Ws, OverLim) => { slice(slice_start, last_end);
835+
A }
823836
(C, Ws, UnderLim) => { C }
824837
};
825838

826-
cont
839+
cont.get()
827840
};
828841

829842
ss.char_indices().advance(|x| machine(x));
830843

831844
// Let the automaton 'run out' by supplying trailing whitespace
832-
while cont && match state { B | C => true, A => false } {
845+
while cont.get() && match state { B | C => true, A => false } {
833846
machine((fake_i, ' '));
834847
fake_i += 1;
835848
}
836-
return cont;
849+
return cont.get();
837850
}
838851

839852
#[test]

src/libglob/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#[crate_type = "dylib"];
2929
#[license = "MIT/ASL2"];
3030

31+
use std::cell::Cell;
3132
use std::{os, path};
3233
use std::io;
3334
use std::io::fs;
@@ -343,22 +344,24 @@ impl Pattern {
343344
}
344345

345346
fn matches_from(&self,
346-
mut prev_char: Option<char>,
347+
prev_char: Option<char>,
347348
mut file: &str,
348349
i: uint,
349350
options: MatchOptions) -> MatchResult {
350351

352+
let prev_char = Cell::new(prev_char);
353+
351354
let require_literal = |c| {
352355
(options.require_literal_separator && is_sep(c)) ||
353356
(options.require_literal_leading_dot && c == '.'
354-
&& is_sep(prev_char.unwrap_or('/')))
357+
&& is_sep(prev_char.get().unwrap_or('/')))
355358
};
356359

357360
for (ti, token) in self.tokens.slice_from(i).iter().enumerate() {
358361
match *token {
359362
AnySequence => {
360363
loop {
361-
match self.matches_from(prev_char, file, i + ti + 1, options) {
364+
match self.matches_from(prev_char.get(), file, i + ti + 1, options) {
362365
SubPatternDoesntMatch => (), // keep trying
363366
m => return m,
364367
}
@@ -371,7 +374,7 @@ impl Pattern {
371374
if require_literal(c) {
372375
return SubPatternDoesntMatch;
373376
}
374-
prev_char = Some(c);
377+
prev_char.set(Some(c));
375378
file = next;
376379
}
377380
}
@@ -401,7 +404,7 @@ impl Pattern {
401404
if !matches {
402405
return SubPatternDoesntMatch;
403406
}
404-
prev_char = Some(c);
407+
prev_char.set(Some(c));
405408
file = next;
406409
}
407410
}

src/librustc/back/link.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -323,21 +323,23 @@ pub mod write {
323323

324324
let mut llvm_c_strs = ~[];
325325
let mut llvm_args = ~[];
326-
let add = |arg: &str| {
327-
let s = arg.to_c_str();
328-
llvm_args.push(s.with_ref(|p| p));
329-
llvm_c_strs.push(s);
330-
};
331-
add("rustc"); // fake program name
332-
add("-arm-enable-ehabi");
333-
add("-arm-enable-ehabi-descriptors");
334-
if vectorize_loop { add("-vectorize-loops"); }
335-
if vectorize_slp { add("-vectorize-slp"); }
336-
if sess.time_llvm_passes() { add("-time-passes"); }
337-
if sess.print_llvm_passes() { add("-debug-pass=Structure"); }
338-
339-
for arg in sess.opts.llvm_args.iter() {
340-
add(*arg);
326+
{
327+
let add = |arg: &str| {
328+
let s = arg.to_c_str();
329+
llvm_args.push(s.with_ref(|p| p));
330+
llvm_c_strs.push(s);
331+
};
332+
add("rustc"); // fake program name
333+
add("-arm-enable-ehabi");
334+
add("-arm-enable-ehabi-descriptors");
335+
if vectorize_loop { add("-vectorize-loops"); }
336+
if vectorize_slp { add("-vectorize-slp"); }
337+
if sess.time_llvm_passes() { add("-time-passes"); }
338+
if sess.print_llvm_passes() { add("-debug-pass=Structure"); }
339+
340+
for arg in sess.opts.llvm_args.iter() {
341+
add(*arg);
342+
}
341343
}
342344

343345
INIT.doit(|| {
@@ -601,7 +603,7 @@ pub fn mangle(sess: Session, ss: ast_map::Path,
601603

602604
let mut n = ~"_ZN"; // _Z == Begin name-sequence, N == nested
603605

604-
let push = |s: &str| {
606+
let push = |n: &mut ~str, s: &str| {
605607
let sani = sanitize(s);
606608
n.push_str(format!("{}{}", sani.len(), sani));
607609
};
@@ -610,7 +612,7 @@ pub fn mangle(sess: Session, ss: ast_map::Path,
610612
for s in ss.iter() {
611613
match *s {
612614
PathName(s) | PathMod(s) | PathPrettyName(s, _) => {
613-
push(sess.str_of(s))
615+
push(&mut n, sess.str_of(s))
614616
}
615617
}
616618
}
@@ -635,10 +637,10 @@ pub fn mangle(sess: Session, ss: ast_map::Path,
635637
}
636638
}
637639
if hash.len() > 0 {
638-
push(hash);
640+
push(&mut n, hash);
639641
}
640642
match vers {
641-
Some(s) => push(s),
643+
Some(s) => push(&mut n, s),
642644
None => {}
643645
}
644646

src/librustc/front/config.rs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,18 @@ fn filter_view_item<'r>(cx: &Context, view_item: &'r ast::ViewItem)
5858
}
5959

6060
fn fold_mod(cx: &mut Context, m: &ast::Mod) -> ast::Mod {
61-
let filtered_items = m.items.iter()
61+
let filtered_items: ~[&@ast::Item] = m.items.iter()
6262
.filter(|&a| item_in_cfg(cx, *a))
63+
.collect();
64+
let flattened_items = filtered_items.move_iter()
6365
.flat_map(|&x| cx.fold_item(x).move_iter())
6466
.collect();
6567
let filtered_view_items = m.view_items.iter().filter_map(|a| {
6668
filter_view_item(cx, a).map(|x| cx.fold_view_item(x))
6769
}).collect();
6870
ast::Mod {
6971
view_items: filtered_view_items,
70-
items: filtered_items
72+
items: flattened_items
7173
}
7274
}
7375

@@ -113,23 +115,26 @@ fn fold_item_underscore(cx: &mut Context, item: &ast::Item_) -> ast::Item_ {
113115
ast::ItemStruct(fold_struct(cx, def), generics.clone())
114116
}
115117
ast::ItemEnum(ref def, ref generics) => {
116-
let mut variants = def.variants.iter().map(|c| c.clone()).filter(|m| {
117-
(cx.in_cfg)(m.node.attrs)
118-
}).map(|v| {
119-
match v.node.kind {
120-
ast::TupleVariantKind(..) => v,
121-
ast::StructVariantKind(def) => {
122-
let def = fold_struct(cx, def);
123-
@codemap::Spanned {
124-
node: ast::Variant_ {
125-
kind: ast::StructVariantKind(def),
126-
..v.node.clone()
127-
},
128-
..*v
129-
}
118+
let mut variants = def.variants.iter().map(|c| c.clone()).
119+
filter_map(|v| {
120+
if !(cx.in_cfg)(v.node.attrs) {
121+
None
122+
} else {
123+
Some(match v.node.kind {
124+
ast::TupleVariantKind(..) => v,
125+
ast::StructVariantKind(def) => {
126+
let def = fold_struct(cx, def);
127+
@codemap::Spanned {
128+
node: ast::Variant_ {
129+
kind: ast::StructVariantKind(def),
130+
..v.node.clone()
131+
},
132+
..*v
133+
}
134+
}
135+
})
130136
}
131-
}
132-
});
137+
});
133138
ast::ItemEnum(ast::EnumDef {
134139
variants: variants.collect(),
135140
}, generics.clone())
@@ -165,10 +170,11 @@ fn retain_stmt(cx: &Context, stmt: @ast::Stmt) -> bool {
165170
}
166171

167172
fn fold_block(cx: &mut Context, b: ast::P<ast::Block>) -> ast::P<ast::Block> {
168-
let resulting_stmts = b.stmts.iter()
169-
.filter(|&a| retain_stmt(cx, *a))
170-
.flat_map(|&stmt| cx.fold_stmt(stmt).move_iter())
171-
.collect();
173+
let resulting_stmts: ~[&@ast::Stmt] =
174+
b.stmts.iter().filter(|&a| retain_stmt(cx, *a)).collect();
175+
let resulting_stmts = resulting_stmts.move_iter()
176+
.flat_map(|&stmt| cx.fold_stmt(stmt).move_iter())
177+
.collect();
172178
let filtered_view_items = b.view_items.iter().filter_map(|a| {
173179
filter_view_item(cx, a).map(|x| cx.fold_view_item(x))
174180
}).collect();

0 commit comments

Comments
 (0)