Skip to content

Commit 1163cef

Browse files
committed
remove obsolete closure syntax from the guide
1 parent 0ba9e1f commit 1163cef

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/doc/trpl/closures.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ arguments, really powerful things are possible.
99
Let's make a closure:
1010

1111
```{rust}
12-
let add_one = |&: x| { 1 + x };
12+
let add_one = |x| { 1 + x };
1313
1414
println!("The sum of 5 plus 1 is {}.", add_one(5));
1515
```
@@ -21,8 +21,8 @@ binding name and two parentheses, just like we would for a named function.
2121
Let's compare syntax. The two are pretty close:
2222

2323
```{rust}
24-
let add_one = |&: x: i32| -> i32 { 1 + x };
25-
fn add_one (x: i32) -> i32 { 1 + x }
24+
let add_one = |x: i32| -> i32 { 1 + x };
25+
fn add_one (x: i32) -> i32 { 1 + x }
2626
```
2727

2828
As you may have noticed, closures infer their argument and return types, so you
@@ -37,7 +37,7 @@ this:
3737
fn main() {
3838
let x: i32 = 5;
3939
40-
let printer = |&:| { println!("x is: {}", x); };
40+
let printer = || { println!("x is: {}", x); };
4141
4242
printer(); // prints "x is: 5"
4343
}
@@ -53,7 +53,7 @@ defined. The closure borrows any variables it uses, so this will error:
5353
fn main() {
5454
let mut x: i32 = 5;
5555
56-
let printer = |&:| { println!("x is: {}", x); };
56+
let printer = || { println!("x is: {}", x); };
5757
5858
x = 6; // error: cannot assign to `x` because it is borrowed
5959
}
@@ -80,7 +80,7 @@ fn twice<F: Fn(i32) -> i32>(x: i32, f: F) -> i32 {
8080
}
8181
8282
fn main() {
83-
let square = |&: x: i32| { x * x };
83+
let square = |x: i32| { x * x };
8484
8585
twice(5, square); // evaluates to 50
8686
}
@@ -89,15 +89,15 @@ fn main() {
8989
Let's break the example down, starting with `main`:
9090

9191
```{rust}
92-
let square = |&: x: i32| { x * x };
92+
let square = |x: i32| { x * x };
9393
```
9494

9595
We've seen this before. We make a closure that takes an integer, and returns
9696
its square.
9797

9898
```{rust}
9999
# fn twice<F: Fn(i32) -> i32>(x: i32, f: F) -> i32 { f(x) + f(x) }
100-
# let square = |&: x: i32| { x * x };
100+
# let square = |x: i32| { x * x };
101101
twice(5, square); // evaluates to 50
102102
```
103103

@@ -184,8 +184,8 @@ fn compose<F, G>(x: i32, f: F, g: G) -> i32
184184
185185
fn main() {
186186
compose(5,
187-
|&: n: i32| { n + 42 },
188-
|&: n: i32| { n * 2 }); // evaluates to 94
187+
|n: i32| { n + 42 },
188+
|n: i32| { n * 2 }); // evaluates to 94
189189
}
190190
```
191191

0 commit comments

Comments
 (0)