Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0ac6e5a

Browse files
committedFeb 11, 2014
auto merge of #12158 : nikomatsakis/rust/issue-6801-borrowck-closures, r=pcwalton
I factored the commits by affected files, for the most part. The last 7 or 8 contain the meat of the PR. The rest are small changes to closures found in the codebase. Maybe interesting to read to see some of the impact of the rules. r? @pcwalton Fixes #6801
2 parents 2ab248a + 484f0f1 commit 0ac6e5a

File tree

97 files changed

+2967
-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.

97 files changed

+2967
-2530
lines changed
 

‎src/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/libgetopts/lib.rs

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -775,14 +775,13 @@ fn each_split_within<'a>(ss: &'a str, lim: uint, it: |&'a str| -> bool)
775775
let mut lim = lim;
776776
777777
let mut cont = true;
778-
let slice: || = || { cont = it(ss.slice(slice_start, last_end)) };
779778
780779
// if the limit is larger than the string, lower it to save cycles
781780
if lim >= fake_i {
782781
lim = fake_i;
783782
}
784783
785-
let machine: |(uint, char)| -> bool = |(i, c)| {
784+
let machine: |&mut bool, (uint, char)| -> bool = |cont, (i, c)| {
786785
let whitespace = if ::std::char::is_whitespace(c) { Ws } else { Cr };
787786
let limit = if (i - slice_start + 1) <= lim { UnderLim } else { OverLim };
788787
@@ -794,24 +793,49 @@ fn each_split_within<'a>(ss: &'a str, lim: uint, it: |&'a str| -> bool)
794793
(B, Cr, OverLim) if (i - last_start + 1) > lim
795794
=> fail!("word starting with {} longer than limit!",
796795
ss.slice(last_start, i + 1)),
797-
(B, Cr, OverLim) => { slice(); slice_start = last_start; B }
798-
(B, Ws, UnderLim) => { last_end = i; C }
799-
(B, Ws, OverLim) => { last_end = i; slice(); A }
800-
801-
(C, Cr, UnderLim) => { last_start = i; B }
802-
(C, Cr, OverLim) => { slice(); slice_start = i; last_start = i; last_end = i; B }
803-
(C, Ws, OverLim) => { slice(); A }
804-
(C, Ws, UnderLim) => { C }
796+
(B, Cr, OverLim) => {
797+
*cont = it(ss.slice(slice_start, last_end));
798+
slice_start = last_start;
799+
B
800+
}
801+
(B, Ws, UnderLim) => {
802+
last_end = i;
803+
C
804+
}
805+
(B, Ws, OverLim) => {
806+
last_end = i;
807+
*cont = it(ss.slice(slice_start, last_end));
808+
A
809+
}
810+
811+
(C, Cr, UnderLim) => {
812+
last_start = i;
813+
B
814+
}
815+
(C, Cr, OverLim) => {
816+
*cont = it(ss.slice(slice_start, last_end));
817+
slice_start = i;
818+
last_start = i;
819+
last_end = i;
820+
B
821+
}
822+
(C, Ws, OverLim) => {
823+
*cont = it(ss.slice(slice_start, last_end));
824+
A
825+
}
826+
(C, Ws, UnderLim) => {
827+
C
828+
}
805829
};
806830

807-
cont
831+
*cont
808832
};
809833

810-
ss.char_indices().advance(|x| machine(x));
834+
ss.char_indices().advance(|x| machine(&mut cont, x));
811835

812836
// Let the automaton 'run out' by supplying trailing whitespace
813837
while cont && match state { B | C => true, A => false } {
814-
machine((fake_i, ' '));
838+
machine(&mut cont, (fake_i, ' '));
815839
fake_i += 1;
816840
}
817841
return cont;

0 commit comments

Comments
 (0)
Please sign in to comment.