Skip to content

Commit 152e018

Browse files
committed
Update some doc examples to accommodate new by-value upvar closures.
1 parent 8ad1253 commit 152e018

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/doc/guide-container.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ let xs = [1,2,3,4,5];
184184
let mut calls = 0;
185185
186186
{
187+
let calls_ref = &mut calls;
187188
let it = xs.iter().scan((), |_, x| {
188-
calls += 1;
189+
*calls_ref += 1;
189190
if *x < 3 { Some(x) } else { None }});
190191
191192
// the iterator will only yield 1 and 2 before returning None

src/doc/tutorial.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,8 @@ access local variables in the enclosing scope.
18381838

18391839
~~~~
18401840
let mut max = 0;
1841-
let f = |x: int| if x > max { max = x };
1841+
let max_ref = &mut max;
1842+
let f = |x: int| if x > *max_ref { *max_ref = x };
18421843
for x in [1, 2, 3].iter() {
18431844
f(*x);
18441845
}

0 commit comments

Comments
 (0)