Skip to content

Commit 853ccb4

Browse files
committed
Adjust rules next to headers
1 parent fbe355b commit 853ccb4

20 files changed

+97
-194
lines changed

src/expressions.md

+10-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# Expressions
2-
31
r[expr]
2+
# Expressions
43

54
r[expr.syntax]
65
> **<sup>Syntax</sup>**\
@@ -68,9 +67,8 @@ Blocks are just another kind of expression, so blocks, statements, expressions,
6867

6968
> **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.
7069
71-
## Expression precedence
72-
7370
r[expr.precedence]
71+
## Expression precedence
7472

7573
The precedence of Rust operators and expressions is ordered as follows, going from strong to weak.
7674
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
9795
| `=` `+=` `-=` `*=` `/=` `%=` <br> `&=` <code>&#124;=</code> `^=` `<<=` `>>=` | right to left |
9896
| `return` `break` closures | |
9997

100-
## Evaluation order of operands
101-
10298
r[expr.operand-order]
99+
## Evaluation order of operands
103100

104101
r[expr.operand-order.default]
105102
The following list of expressions all evaluate their operands the same way, as described after the list.
@@ -147,9 +144,8 @@ assert_eq!(
147144

148145
> **Note**: Since this is applied recursively, these expressions are also evaluated from innermost to outermost, ignoring siblings until there are no inner subexpressions.
149146
150-
## Place Expressions and Value Expressions
151-
152147
r[expr.place-value]
148+
## Place Expressions and Value Expressions
153149

154150
r[expr.place-value.intro]
155151
Expressions are divided into two main categories: place expressions and value expressions;
@@ -200,9 +196,8 @@ Explicitly, the assignee expressions are:
200196
r[expr.place-value.parenthesis]
201197
Arbitrary parenthesisation is permitted inside assignee expressions.
202198

203-
### Moved and copied types
204-
205199
r[expr.move]
200+
### Moved and copied types
206201

207202
r[expr.move.intro]
208203
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
227222
r[expr.move.place-invalid]
228223
In all other cases, trying to use a place expression in a value expression context is an error.
229224

230-
### Mutability
231-
232225
r[expr.mut]
226+
### Mutability
233227

234228
r[expr.mut.intro]
235229
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:
251245
* [Array indexing] of a type that implements `IndexMut`:
252246
this then evaluates the value being indexed, but not the index, in mutable place expression context.
253247

254-
### Temporaries
255-
256248
r[expr.temporary]
249+
### Temporaries
257250

258251
When using a value expression in most place expression contexts, a temporary unnamed memory location is created and initialized to that value.
259252
The expression evaluates to that location instead, except if [promoted] to a `static`.
260253
The [drop scope] of the temporary is usually the end of the enclosing statement.
261254

262-
### Implicit Borrows
263-
264255
r[expr.implicit-borrow]
256+
### Implicit Borrows
265257

266258
r[expr.implicit-borrow-intro]
267259
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:
291283
* Operands of [comparison].
292284
* Left operands of the [compound assignment].
293285

294-
## Overloading Traits
295-
296286
r[expr.overload]
287+
## Overloading Traits
297288

298289
Many of the following operators and expressions can also be overloaded for other types using traits in `std::ops` or `std::cmp`.
299290
These traits also exist in `core::ops` and `core::cmp` with the same names.
300291

301-
## Expression Attributes
302-
303292
r[expr.attr]
293+
## Expression Attributes
304294

305295
r[expr.attr.restriction]
306296
[Outer attributes][_OuterAttribute_] before an expression are allowed only in a few specific cases:

src/expressions/array-expr.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# Array and array index expressions
2-
31
r[expr.array]
2+
# Array and array index expressions
43

54
## Array expressions
65

@@ -64,9 +63,8 @@ const EMPTY: Vec<i32> = Vec::new();
6463
[EMPTY; 2];
6564
```
6665

67-
## Array and slice indexing expressions
68-
6966
r[expr.array.index]
67+
## Array and slice indexing expressions
7068

7169
> **<sup>Syntax</sup>**\
7270
> _IndexExpression_ :\

src/expressions/await-expr.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# Await expressions
2-
31
r[expr.await]
2+
# Await expressions
43

54
r[expr.await.syntax]
65
> **<sup>Syntax</sup>**\
@@ -30,16 +29,14 @@ More specifically, an await expression has the following effect.
3029

3130
> **Edition differences**: Await expressions are only available beginning with Rust 2018.
3231
33-
## Task context
34-
3532
r[expr.await.task]
33+
## Task context
3634

3735
The task context refers to the [`Context`] which was supplied to the current [async context] when the async context itself was polled.
3836
Because `await` expressions are only legal in an async context, there must be some task context available.
3937

40-
## Approximate desugaring
41-
4238
r[expr.await.desugar]
39+
## Approximate desugaring
4340

4441
Effectively, an await expression is roughly equivalent to the following non-normative desugaring:
4542

src/expressions/block-expr.md

+9-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# Block expressions
2-
31
r[expr.block]
2+
# Block expressions
43

54
r[expr.block.syntax]
65
> **<sup>Syntax</sup>**\
@@ -87,9 +86,8 @@ Blocks are always [value expressions] and evaluate the last operand in value exp
8786
> }
8887
> ```
8988
90-
## `async` blocks
91-
9289
r[expr.block.async]
90+
## `async` blocks
9391
9492
r[expr.block.async.syntax]
9593
> **<sup>Syntax</sup>**\
@@ -116,24 +114,21 @@ The actual data format for this type is unspecified.
116114
117115
> **Edition differences**: Async blocks are only available beginning with Rust 2018.
118116
119-
### Capture modes
120-
121117
r[expr.block.async.capture]
118+
### Capture modes
122119
123120
Async blocks capture variables from their environment using the same [capture modes] as closures.
124121
Like closures, when written `async { .. }` the capture mode for each variable will be inferred from the content of the block.
125122
`async move { .. }` blocks however will move all referenced variables into the resulting future.
126123
127-
### Async context
128-
129124
r[expr.block.async.context]
125+
### Async context
130126
131127
Because async blocks construct a future, they define an **async context** which can in turn contain [`await` expressions].
132128
Async contexts are established by async blocks as well as the bodies of async functions, whose semantics are defined in terms of async blocks.
133129
134-
### Control-flow operators
135-
136130
r[expr.block.async.function]
131+
### Control-flow operators
137132
138133
r[expr.block.async.function.intro]
139134
Async blocks act like a function boundary, much like closures.
@@ -155,9 +150,8 @@ loop {
155150
}
156151
```
157152
158-
## `const` blocks
159-
160153
r[expr.block.const]
154+
## `const` blocks
161155

162156
r[expr.block.const.syntax]
163157
> **<sup>Syntax</sup>**\
@@ -221,9 +215,8 @@ if false {
221215
}
222216
```
223217

224-
## `unsafe` blocks
225-
226218
r[expr.block.unsafe]
219+
## `unsafe` blocks
227220

228221
> **<sup>Syntax</sup>**\
229222
> _UnsafeBlockExpression_ :\
@@ -246,15 +239,13 @@ unsafe {
246239
let a = unsafe { an_unsafe_fn() };
247240
```
248241

249-
## Labelled block expressions
250-
251242
r[expr.block.label]
243+
## Labelled block expressions
252244

253245
Labelled block expressions are documented in the [Loops and other breakable expressions] section.
254246

255-
## Attributes on block expressions
256-
257247
r[expr.block.attributes]
248+
## Attributes on block expressions
258249

259250
r[expr.block.attributes.inner-attributes]
260251
[Inner attributes] are allowed directly after the opening brace of a block expression in the following situations:

src/expressions/call-expr.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# Call expressions
2-
31
r[expr.call]
2+
# Call expressions
43

54
r[expr.call.syntax]
65
> **<sup>Syntax</sup>**\
@@ -36,9 +35,8 @@ let three: i32 = add(1i32, 2i32);
3635
let name: &'static str = (|| "Rust")();
3736
```
3837

39-
## Disambiguating Function Calls
40-
4138
r[expr.call.desugar]
39+
## Disambiguating Function Calls
4240

4341
r[expr.call.desugar.fully-qualified]
4442
All function calls are sugar for a more explicit [fully-qualified syntax].

src/expressions/closure-expr.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# Closure expressions
2-
31
r[expr.closure]
2+
# Closure expressions
43

54
r[expr.closure.syntax]
65
> **<sup>Syntax</sup>**\
@@ -48,9 +47,8 @@ r[expr.closure.capture-move]
4847
A closure can be forced to capture its environment by copying or moving values by prefixing it with the `move` keyword.
4948
This is often used to ensure that the closure's lifetime is `'static`.
5049

51-
## Closure trait implementations
52-
5350
r[expr.closure.trait-impl]
51+
## Closure trait implementations
5452

5553
Which traits the closure type implement depends on how variables are captured, the types of the captured variables, and the presence of `async`.
5654
See the [call traits and coercions] chapter for how and when a closure implements `Fn`, `FnMut`, and `FnOnce`.
@@ -100,7 +98,6 @@ ten_times(move |j| println!("{}, {}", word, j));
10098
## Attributes on closure parameters
10199

102100
r[expr.closure.param-attributes]
103-
104101
Attributes on closure parameters follow the same rules and restrictions as [regular function parameters].
105102

106103
[_Expression_]: ../expressions.md

src/expressions/field-expr.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# Field access expressions
2-
31
r[expr.field]
2+
# Field access expressions
43

54
r[expr.field.syntax]
65
> **<sup>Syntax</sup>**\
@@ -43,16 +42,14 @@ foo().x;
4342
(mystruct.function_field)() // Call expression containing a field expression
4443
```
4544
46-
## Automatic dereferencing
47-
4845
r[expr.field.autoref-deref]
46+
## Automatic dereferencing
4947

5048
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.
5149
This process is also called *autoderef* for short.
5250

53-
## Borrowing
54-
5551
r[expr.field.borrow]
52+
## Borrowing
5653

5754
The fields of a struct or a reference to a struct are treated as separate entities when borrowing.
5855
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.

src/expressions/grouped-expr.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# Grouped expressions
2-
31
r[expr.paren]
2+
# Grouped expressions
43

54
r[expr.paren.syntax]
65
> **<sup>Syntax</sup>**\

src/expressions/if-expr.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# `if` and `if let` expressions
2-
31
r[expr.if]
2+
# `if` and `if let` expressions
43

54
## `if` expressions
65

@@ -53,9 +52,8 @@ let y = if 12 * 15 > 150 {
5352
assert_eq!(y, "Bigger");
5453
```
5554

56-
## `if let` expressions
57-
5855
r[expr.if.let]
56+
## `if let` expressions
5957

6058
r[expr.if.let.syntax]
6159
> **<sup>Syntax</sup>**\

0 commit comments

Comments
 (0)