Skip to content

Commit 58a15f3

Browse files
committed
auto merge of #11584 : alexcrichton/rust/issue-3862, r=brson
Turns out there is no documentation of a block expression in the rust manual currently! I deleted the "record expressions" section to make room for a "block expressions" section. Closes #3862
2 parents 80a3f45 + 421d245 commit 58a15f3

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

doc/rust.md

+17-5
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,9 @@ path_glob : ident [ "::" path_glob ] ?
806806

807807
A _use declaration_ creates one or more local name bindings synonymous
808808
with some other [path](#paths).
809-
Usually a `use` declaration is used to shorten the path required to refer to a module item.
809+
Usually a `use` declaration is used to shorten the path required to refer to a
810+
module item. These declarations may appear at the top of [modules](#modules) and
811+
[blocks](#blocks).
810812

811813
*Note*: Unlike in many languages,
812814
`use` declarations in Rust do *not* declare linkage dependency with external crates.
@@ -2318,14 +2320,24 @@ let base = Point3d {x: 1, y: 2, z: 3};
23182320
Point3d {y: 0, z: 10, .. base};
23192321
~~~~
23202322

2321-
### Record expressions
2323+
### Block expressions
23222324

23232325
~~~~ {.ebnf .gram}
2324-
rec_expr : '{' ident ':' expr
2325-
[ ',' ident ':' expr ] *
2326-
[ ".." expr ] '}'
2326+
block_expr : '{' [ view_item ] *
2327+
[ stmt ';' | item ] *
2328+
[ expr ] '}'
23272329
~~~~
23282330

2331+
A _block expression_ is similar to a module in terms of the declarations that
2332+
are possible. Each block conceptually introduces a new namespace scope. View
2333+
items can bring new names into scopes and declared items are in scope for only
2334+
the block itself.
2335+
2336+
A block will execute each statement sequentially, and then execute the
2337+
expression (if given). If the final expression is omitted, the type and return
2338+
value of the block are `()`, but if it is provided, the type and return value
2339+
of the block are that of the expression itself.
2340+
23292341
### Method-call expressions
23302342

23312343
~~~~ {.ebnf .gram}

0 commit comments

Comments
 (0)