Skip to content

Explain block like expression statements #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,22 @@ declaration until the end of the enclosing block scope.

## Expression statements

An _expression statement_ is one that evaluates an [expression](expressions.html)
and ignores its result. The type of an expression statement `e;` is always
`()`, regardless of the type of `e`. As a rule, an expression statement's
purpose is to trigger the effects of evaluating its expression.
An _expression statement_ is one that evaluates an
[expression](expressions.html) and ignores its result. The type of an
expression statement `e;` is always `()`, regardless of the type of `e`. As a
rule, an expression statement's purpose is to trigger the effects of evaluating
its expression. An expression that consists of only a [block
expression](expressions.html#block-expressions) or control flow expression,
that doesn't end a block and evaluates to `()` can also be used as an
expression statement by omitting the trailing semicolon.

```rust
# let mut v = vec![1, 2, 3];
v.pop(); // Ignore the element returned from pop
if v.is_empty() {
v.push(5);
} else {
v.remove(0);
} // Semicolon can be omitted.
[1]; // Separate expression statement, not an indexing expression.
```