From 148d90be99b13d5874fedf398a506a5171cbba88 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 13 Feb 2015 17:56:06 -0500 Subject: [PATCH] clarfiy reference with regards to the value of block expressions Fixes #14849 --- src/doc/reference.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 9c51f6bad6f..df702a1840f 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -2701,9 +2701,19 @@ items can bring new names into scopes and declared items are in scope for only the block itself. A block will execute each statement sequentially, and then execute the -expression (if given). If the final expression is omitted, the type and return -value of the block are `()`, but if it is provided, the type and return value -of the block are that of the expression itself. +expression (if given). If the block ends in a statement, its value is `()`: + +``` +let x: () = { println!("Hello."); }; +``` + +If it ends in an expression, its value and type are that of the expression: + +``` +let x: i32 = { println!("Hello."); 5 }; + +assert_eq!(5, x); +``` ### Method-call expressions