Skip to content

Commit da903cf

Browse files
committed
One line one sentence for the Statements chapter.
1 parent 8f8175b commit da903cf

File tree

2 files changed

+32
-38
lines changed

2 files changed

+32
-38
lines changed

src/expressions.md

+9
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ assert_eq!(
129129

130130
> **Note**: Since this is applied recursively, these expressions are also evaluated from innermost to outermost, ignoring siblings until there are no inner subexpressions.
131131
132+
## Early Termination
133+
134+
Expressions may be *terminated* early, whether by a jump expression or unwinding.
135+
When terminated, evaluation of the expression stops.
136+
If the expression is the target of termination by a jump expression, then it evaluates to the value specified by the jump expression.
137+
Otherwise, it evaluates to the never type.
138+
139+
**Note**: Destructors are still executed for the expression after being terminated.
140+
132141
## Place Expressions and Value Expressions
133142

134143
Expressions are divided into two main categories: place expressions and value expressions;

src/statements.md

+23-38
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,27 @@
99
>    | [_MacroInvocationSemi_]
1010
1111

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

15-
Rust has two kinds of statement: [declaration
16-
statements](#declaration-statements) and [expression
17-
statements](#expression-statements).
14+
Rust has two kinds of statement: [declaration statements](#declaration-statements) and [expression statements](#expression-statements).
1815

1916
## Declaration statements
2017

21-
A *declaration statement* is one that introduces one or more *names* into the
22-
enclosing statement block. The declared names may denote new variables or new
23-
[items][item].
18+
A *declaration statement* is one that introduces one or more *names* into the enclosing statement block.
19+
The declared names may denote new variables or new [items][item].
2420

25-
The two kinds of declaration statements are item declarations and `let`
26-
statements.
21+
The two kinds of declaration statements are item declarations and `let` statements.
2722

2823
### Item declarations
2924

30-
An *item declaration statement* has a syntactic form identical to an
31-
[item declaration][item] within a [module]. Declaring an item within a statement
32-
block restricts its scope to the block containing the statement. The item is not
33-
given a [canonical path] nor are any sub-items it may declare. The exception to
34-
this is that associated items defined by [implementations] are still accessible
35-
in outer scopes as long as the item and, if applicable, trait are accessible.
25+
An *item declaration statement* has a syntactic form identical to an [item declaration][item] within a [module].
26+
Declaring an item within a statement block restricts its scope to the block containing the statement.
27+
The item is not given a [canonical path] nor are any sub-items it may declare.
28+
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.
3629
It is otherwise identical in meaning to declaring the item inside a module.
3730

38-
There is no implicit capture of the containing function's generic parameters,
39-
parameters, and local variables. For example, `inner` may not access
40-
`outer_var`.
31+
There is no implicit capture of the containing function's generic parameters, parameters, and local variables.
32+
For example, `inner` may not access `outer_var`.
4133

4234
```rust
4335
fn outer() {
@@ -56,14 +48,10 @@ fn outer() {
5648
> &nbsp;&nbsp; [_OuterAttribute_]<sup>\*</sup> `let` [_PatternNoTopAlt_]
5749
> ( `:` [_Type_] )<sup>?</sup> (`=` [_Expression_] )<sup>?</sup> `;`
5850
59-
A *`let` statement* introduces a new set of [variables], given by an
60-
irrefutable [pattern]. The pattern is followed optionally by a type
61-
annotation and then optionally by an initializer expression. When no
62-
type annotation is given, the compiler will infer the type, or signal
63-
an error if insufficient type information is available for definite
64-
inference. Any variables introduced by a variable declaration are visible
65-
from the point of declaration until the end of the enclosing block scope,
66-
except when they are shadowed by another variable declaration.
51+
A *`let` statement* introduces a new set of [variables], given by an irrefutable [pattern].
52+
The pattern is followed optionally by a type annotation and then optionally by an initializer expression.
53+
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.
54+
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.
6755

6856
## Expression statements
6957

@@ -72,16 +60,13 @@ except when they are shadowed by another variable declaration.
7260
> &nbsp;&nbsp; &nbsp;&nbsp; [_ExpressionWithoutBlock_][expression] `;`\
7361
> &nbsp;&nbsp; | [_ExpressionWithBlock_][expression] `;`<sup>?</sup>
7462
75-
An *expression statement* is one that evaluates an [expression] and ignores its
76-
result. As a rule, an expression statement's purpose is to trigger the effects
77-
of evaluating its expression.
63+
An *expression statement* is one that evaluates an [expression] and ignores its result.
64+
As a rule, an expression statement's purpose is to trigger the effects of evaluating its expression.
7865

79-
An expression that consists of only a [block expression][block] or control flow
80-
expression, if used in a context where a statement is permitted, can omit the
81-
trailing semicolon. This can cause an ambiguity between it being parsed as a
82-
standalone statement and as a part of another expression; in this case, it is
83-
parsed as a statement. The type of [_ExpressionWithBlock_][expression]
84-
expressions when used as statements must be the unit type.
66+
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.
67+
This can cause an ambiguity between it being parsed as a standalone statement and as a part of another expression;
68+
in this case, it is parsed as a statement.
69+
The type of [_ExpressionWithBlock_][expression] expressions when used as statements must be the unit type.
8570

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

11499
## Attributes on Statements
115100

116-
Statements accept [outer attributes]. The attributes that have meaning on a
117-
statement are [`cfg`], and [the lint check attributes].
101+
Statements accept [outer attributes].
102+
The attributes that have meaning on a statement are [`cfg`], and [the lint check attributes].
118103

119104
[block]: expressions/block-expr.md
120105
[expression]: expressions.md

0 commit comments

Comments
 (0)