Skip to content

Commit 1cf57f7

Browse files
committed
auto merge of #7003 : alco/rust/tutorial-block-expr, r=bstrie
This is something that's only been briefly mentioned in the beginning of the tutorial and all of the closure examples within this subsection include only one expression between { and }.
2 parents 88517f9 + 93b2ddf commit 1cf57f7

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

doc/tutorial.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,10 +1442,15 @@ call_closure_with_ten(closure);
14421442
~~~~
14431443

14441444
Closures begin with the argument list between vertical bars and are followed by
1445-
a single expression. The types of the arguments are generally omitted,
1446-
as is the return type, because the compiler can almost always infer
1447-
them. In the rare case where the compiler needs assistance, though, the
1448-
arguments and return types may be annotated.
1445+
a single expression. Remember that a block, `{ <expr1>; <expr2>; ... }`, is
1446+
considered a single expression: it evaluates to the result of the last
1447+
expression it contains if that expression is not followed by a semicolon,
1448+
otherwise the block evaluates to `()`.
1449+
1450+
The types of the arguments are generally omitted, as is the return type,
1451+
because the compiler can almost always infer them. In the rare case where the
1452+
compiler needs assistance, though, the arguments and return types may be
1453+
annotated.
14491454

14501455
~~~~
14511456
let square = |x: int| -> uint { x * x as uint };

0 commit comments

Comments
 (0)