You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/expressions.md
+9
Original file line number
Diff line number
Diff line change
@@ -129,6 +129,15 @@ assert_eq!(
129
129
130
130
> **Note**: Since this is applied recursively, these expressions are also evaluated from innermost to outermost, ignoring siblings until there are no inner subexpressions.
131
131
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
+
132
141
## Place Expressions and Value Expressions
133
142
134
143
Expressions are divided into two main categories: place expressions and value expressions;
Copy file name to clipboardExpand all lines: src/statements.md
+23-38
Original file line number
Diff line number
Diff line change
@@ -9,35 +9,27 @@
9
9
> | [_MacroInvocationSemi_]
10
10
11
11
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].
14
13
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).
18
15
19
16
## Declaration statements
20
17
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].
24
20
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.
27
22
28
23
### Item declarations
29
24
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.
36
29
It is otherwise identical in meaning to declaring the item inside a module.
37
30
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.
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.
67
55
68
56
## Expression statements
69
57
@@ -72,16 +60,13 @@ except when they are shadowed by another variable declaration.
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.
78
65
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.
85
70
86
71
```rust
87
72
# letmutv=vec![1, 2, 3];
@@ -113,8 +98,8 @@ if true {
113
98
114
99
## Attributes on Statements
115
100
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].
0 commit comments