Skip to content

Commit 148d90b

Browse files
committed
clarfiy reference with regards to the value of block expressions
Fixes #14849
1 parent cf636c2 commit 148d90b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/doc/reference.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -2701,9 +2701,19 @@ items can bring new names into scopes and declared items are in scope for only
27012701
the block itself.
27022702

27032703
A block will execute each statement sequentially, and then execute the
2704-
expression (if given). If the final expression is omitted, the type and return
2705-
value of the block are `()`, but if it is provided, the type and return value
2706-
of the block are that of the expression itself.
2704+
expression (if given). If the block ends in a statement, its value is `()`:
2705+
2706+
```
2707+
let x: () = { println!("Hello."); };
2708+
```
2709+
2710+
If it ends in an expression, its value and type are that of the expression:
2711+
2712+
```
2713+
let x: i32 = { println!("Hello."); 5 };
2714+
2715+
assert_eq!(5, x);
2716+
```
27072717

27082718
### Method-call expressions
27092719

0 commit comments

Comments
 (0)