Skip to content

Commit e076c6e

Browse files
isHavvyehuss
authored andcommitted
One line one sentence for the Statements chapter.
1 parent cadf497 commit e076c6e

File tree

2 files changed

+32
-39
lines changed

2 files changed

+32
-39
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-39
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() {
@@ -61,18 +53,13 @@ fn outer() {
6153
> _Expression_ must not be a [_LazyBooleanExpression_], or end with a `}`.</span>
6254
6355
A *`let` statement* introduces a new set of [variables], given by a [pattern].
64-
The pattern is followed optionally by a type annotation and then either ends,
65-
or is followed by an initializer expression plus an optional `else` block.
66-
When no type annotation is given, the compiler will infer the type, or signal
67-
an error if insufficient type information is available for definite
68-
inference. Any variables introduced by a variable declaration are visible
69-
from the point of declaration until the end of the enclosing block scope,
70-
except when they are shadowed by another variable declaration.
56+
The pattern is followed optionally by a type annotation and then either ends, or is followed by an initializer expression plus an optional `else` block.
57+
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.
58+
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.
7159

7260
If an `else` block is not present, the pattern must be irrefutable.
7361
If an `else` block is present, the pattern may be refutable.
74-
If the pattern does not match (this requires it to be refutable), the `else`
75-
block is executed.
62+
If the pattern does not match (this requires it to be refutable), the `else` block is executed.
7663
The `else` block must always diverge (evaluate to the [never type]).
7764

7865
```rust
@@ -93,16 +80,13 @@ let [u, v] = [v[0], v[1]] else { // This pattern is irrefutable, so the compiler
9380
> &nbsp;&nbsp; &nbsp;&nbsp; [_ExpressionWithoutBlock_][expression] `;`\
9481
> &nbsp;&nbsp; | [_ExpressionWithBlock_][expression] `;`<sup>?</sup>
9582
96-
An *expression statement* is one that evaluates an [expression] and ignores its
97-
result. As a rule, an expression statement's purpose is to trigger the effects
98-
of evaluating its expression.
83+
An *expression statement* is one that evaluates an [expression] and ignores its result.
84+
As a rule, an expression statement's purpose is to trigger the effects of evaluating its expression.
9985

100-
An expression that consists of only a [block expression][block] or control flow
101-
expression, if used in a context where a statement is permitted, can omit the
102-
trailing semicolon. This can cause an ambiguity between it being parsed as a
103-
standalone statement and as a part of another expression; in this case, it is
104-
parsed as a statement. The type of [_ExpressionWithBlock_][expression]
105-
expressions when used as statements must be the unit type.
86+
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.
87+
This can cause an ambiguity between it being parsed as a standalone statement and as a part of another expression;
88+
in this case, it is parsed as a statement.
89+
The type of [_ExpressionWithBlock_][expression] expressions when used as statements must be the unit type.
10690

10791
```rust
10892
# let mut v = vec![1, 2, 3];
@@ -134,8 +118,8 @@ if true {
134118

135119
## Attributes on Statements
136120

137-
Statements accept [outer attributes]. The attributes that have meaning on a
138-
statement are [`cfg`], and [the lint check attributes].
121+
Statements accept [outer attributes].
122+
The attributes that have meaning on a statement are [`cfg`], and [the lint check attributes].
139123

140124
[block]: expressions/block-expr.md
141125
[expression]: expressions.md

0 commit comments

Comments
 (0)