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
+10-20
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,5 @@
1
-
# Expressions
2
-
3
1
r[expr]
2
+
# Expressions
4
3
5
4
r[expr.syntax]
6
5
> **<sup>Syntax</sup>**\
@@ -68,9 +67,8 @@ Blocks are just another kind of expression, so blocks, statements, expressions,
68
67
69
68
> **Note**: We give names to the operands of expressions so that we may discuss them, but these names are not stable and may be changed.
70
69
71
-
## Expression precedence
72
-
73
70
r[expr.precedence]
71
+
## Expression precedence
74
72
75
73
The precedence of Rust operators and expressions is ordered as follows, going from strong to weak.
76
74
Binary Operators at the same precedence level are grouped in the order given by their associativity.
@@ -97,9 +95,8 @@ Binary Operators at the same precedence level are grouped in the order given by
97
95
|`=``+=``-=``*=``/=``%=` <br> `&=` <code>|=</code> `^=``<<=``>>=`| right to left |
98
96
|`return``break` closures ||
99
97
100
-
## Evaluation order of operands
101
-
102
98
r[expr.operand-order]
99
+
## Evaluation order of operands
103
100
104
101
r[expr.operand-order.default]
105
102
The following list of expressions all evaluate their operands the same way, as described after the list.
@@ -147,9 +144,8 @@ assert_eq!(
147
144
148
145
> **Note**: Since this is applied recursively, these expressions are also evaluated from innermost to outermost, ignoring siblings until there are no inner subexpressions.
149
146
150
-
## Place Expressions and Value Expressions
151
-
152
147
r[expr.place-value]
148
+
## Place Expressions and Value Expressions
153
149
154
150
r[expr.place-value.intro]
155
151
Expressions are divided into two main categories: place expressions and value expressions;
@@ -200,9 +196,8 @@ Explicitly, the assignee expressions are:
200
196
r[expr.place-value.parenthesis]
201
197
Arbitrary parenthesisation is permitted inside assignee expressions.
202
198
203
-
### Moved and copied types
204
-
205
199
r[expr.move]
200
+
### Moved and copied types
206
201
207
202
r[expr.move.intro]
208
203
When a place expression is evaluated in a value expression context, or is bound by value in a pattern, it denotes the value held _in_ that memory location.
@@ -227,9 +222,8 @@ After moving out of a place expression that evaluates to a local variable, the l
227
222
r[expr.move.place-invalid]
228
223
In all other cases, trying to use a place expression in a value expression context is an error.
229
224
230
-
### Mutability
231
-
232
225
r[expr.mut]
226
+
### Mutability
233
227
234
228
r[expr.mut.intro]
235
229
For a place expression to be [assigned][assign] to, mutably [borrowed][borrow], [implicitly mutably borrowed], or bound to a pattern containing `ref mut`, it must be _mutable_.
@@ -251,17 +245,15 @@ The following expressions can be mutable place expression contexts:
251
245
*[Array indexing] of a type that implements `IndexMut`:
252
246
this then evaluates the value being indexed, but not the index, in mutable place expression context.
253
247
254
-
### Temporaries
255
-
256
248
r[expr.temporary]
249
+
### Temporaries
257
250
258
251
When using a value expression in most place expression contexts, a temporary unnamed memory location is created and initialized to that value.
259
252
The expression evaluates to that location instead, except if [promoted] to a `static`.
260
253
The [drop scope] of the temporary is usually the end of the enclosing statement.
261
254
262
-
### Implicit Borrows
263
-
264
255
r[expr.implicit-borrow]
256
+
### Implicit Borrows
265
257
266
258
r[expr.implicit-borrow-intro]
267
259
Certain expressions will treat an expression as a place expression by implicitly borrowing it.
@@ -291,16 +283,14 @@ Implicit borrows may be taken in the following expressions:
291
283
* Operands of [comparison].
292
284
* Left operands of the [compound assignment].
293
285
294
-
## Overloading Traits
295
-
296
286
r[expr.overload]
287
+
## Overloading Traits
297
288
298
289
Many of the following operators and expressions can also be overloaded for other types using traits in `std::ops` or `std::cmp`.
299
290
These traits also exist in `core::ops` and `core::cmp` with the same names.
300
291
301
-
## Expression Attributes
302
-
303
292
r[expr.attr]
293
+
## Expression Attributes
304
294
305
295
r[expr.attr.restriction]
306
296
[Outer attributes][_OuterAttribute_] before an expression are allowed only in a few specific cases:
Copy file name to clipboardExpand all lines: src/expressions/field-expr.md
+3-6
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,5 @@
1
-
# Field access expressions
2
-
3
1
r[expr.field]
2
+
# Field access expressions
4
3
5
4
r[expr.field.syntax]
6
5
> **<sup>Syntax</sup>**\
@@ -43,16 +42,14 @@ foo().x;
43
42
(mystruct.function_field)() // Call expression containing a field expression
44
43
```
45
44
46
-
## Automatic dereferencing
47
-
48
45
r[expr.field.autoref-deref]
46
+
## Automatic dereferencing
49
47
50
48
If the type of the container operand implements [`Deref`] or [`DerefMut`][`Deref`] depending on whether the operand is [mutable], it is *automatically dereferenced* as many times as necessary to make the field access possible.
51
49
This process is also called *autoderef* for short.
52
50
53
-
## Borrowing
54
-
55
51
r[expr.field.borrow]
52
+
## Borrowing
56
53
57
54
The fields of a struct or a reference to a struct are treated as separate entities when borrowing.
58
55
If the struct does not implement [`Drop`] and is stored in a local variable, this also applies to moving out of each of its fields.
0 commit comments