Skip to content

Commit

Permalink
One line one sentence for the Statements chapter.
Browse files Browse the repository at this point in the history
  • Loading branch information
isHavvy committed Sep 29, 2022
1 parent 8f8175b commit da903cf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 38 deletions.
9 changes: 9 additions & 0 deletions src/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ assert_eq!(

> **Note**: Since this is applied recursively, these expressions are also evaluated from innermost to outermost, ignoring siblings until there are no inner subexpressions.
## Early Termination

Expressions may be *terminated* early, whether by a jump expression or unwinding.
When terminated, evaluation of the expression stops.
If the expression is the target of termination by a jump expression, then it evaluates to the value specified by the jump expression.
Otherwise, it evaluates to the never type.

**Note**: Destructors are still executed for the expression after being terminated.

## Place Expressions and Value Expressions

Expressions are divided into two main categories: place expressions and value expressions;
Expand Down
61 changes: 23 additions & 38 deletions src/statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,27 @@
>    | [_MacroInvocationSemi_]

A *statement* is a component of a [block], which is in turn a component of an
outer [expression] or [function].
A *statement* is a component of a [block], which is in turn a component of an outer [expression] or [function].

Rust has two kinds of statement: [declaration
statements](#declaration-statements) and [expression
statements](#expression-statements).
Rust has two kinds of statement: [declaration statements](#declaration-statements) and [expression statements](#expression-statements).

## Declaration statements

A *declaration statement* is one that introduces one or more *names* into the
enclosing statement block. The declared names may denote new variables or new
[items][item].
A *declaration statement* is one that introduces one or more *names* into the enclosing statement block.
The declared names may denote new variables or new [items][item].

The two kinds of declaration statements are item declarations and `let`
statements.
The two kinds of declaration statements are item declarations and `let` statements.

### Item declarations

An *item declaration statement* has a syntactic form identical to an
[item declaration][item] within a [module]. Declaring an item within a statement
block restricts its scope to the block containing the statement. The item is not
given a [canonical path] nor are any sub-items it may declare. The exception to
this is that associated items defined by [implementations] are still accessible
in outer scopes as long as the item and, if applicable, trait are accessible.
An *item declaration statement* has a syntactic form identical to an [item declaration][item] within a [module].
Declaring an item within a statement block restricts its scope to the block containing the statement.
The item is not given a [canonical path] nor are any sub-items it may declare.
The exception to this is that associated items defined by [implementations] are still accessible in outer scopes as long as the item and, if applicable, trait are accessible.
It is otherwise identical in meaning to declaring the item inside a module.

There is no implicit capture of the containing function's generic parameters,
parameters, and local variables. For example, `inner` may not access
`outer_var`.
There is no implicit capture of the containing function's generic parameters, parameters, and local variables.
For example, `inner` may not access `outer_var`.

```rust
fn outer() {
Expand All @@ -56,14 +48,10 @@ fn outer() {
> &nbsp;&nbsp; [_OuterAttribute_]<sup>\*</sup> `let` [_PatternNoTopAlt_]
> ( `:` [_Type_] )<sup>?</sup> (`=` [_Expression_] )<sup>?</sup> `;`
A *`let` statement* introduces a new set of [variables], given by an
irrefutable [pattern]. The pattern is followed optionally by a type
annotation and then optionally by an initializer expression. When no
type annotation is given, the compiler will infer the type, or signal
an error if insufficient type information is available for definite
inference. Any variables introduced by a variable declaration are visible
from the point of declaration until the end of the enclosing block scope,
except when they are shadowed by another variable declaration.
A *`let` statement* introduces a new set of [variables], given by an irrefutable [pattern].
The pattern is followed optionally by a type annotation and then optionally by an initializer expression.
When no type annotation is given, the compiler will infer the type, or signal an error if insufficient type information is available for definite inference.
Any variables introduced by a variable declaration are visible from the point of declaration until the end of the enclosing block scope, except when they are shadowed by another variable declaration.

## Expression statements

Expand All @@ -72,16 +60,13 @@ except when they are shadowed by another variable declaration.
> &nbsp;&nbsp; &nbsp;&nbsp; [_ExpressionWithoutBlock_][expression] `;`\
> &nbsp;&nbsp; | [_ExpressionWithBlock_][expression] `;`<sup>?</sup>
An *expression statement* is one that evaluates an [expression] and ignores its
result. 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] and ignores its result.
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][block] or control flow
expression, if used in a context where a statement is permitted, can omit the
trailing semicolon. This can cause an ambiguity between it being parsed as a
standalone statement and as a part of another expression; in this case, it is
parsed as a statement. The type of [_ExpressionWithBlock_][expression]
expressions when used as statements must be the unit type.
An expression that consists of only a [block expression][block] or control flow expression, if used in a context where a statement is permitted, can omit the trailing semicolon.
This can cause an ambiguity between it being parsed as a standalone statement and as a part of another expression;
in this case, it is parsed as a statement.
The type of [_ExpressionWithBlock_][expression] expressions when used as statements must be the unit type.

```rust
# let mut v = vec![1, 2, 3];
Expand Down Expand Up @@ -113,8 +98,8 @@ if true {

## Attributes on Statements

Statements accept [outer attributes]. The attributes that have meaning on a
statement are [`cfg`], and [the lint check attributes].
Statements accept [outer attributes].
The attributes that have meaning on a statement are [`cfg`], and [the lint check attributes].

[block]: expressions/block-expr.md
[expression]: expressions.md
Expand Down

0 comments on commit da903cf

Please sign in to comment.