Skip to content

Commit 9e24a47

Browse files
authored
Merge pull request #961 from osa1/update_casts
Update type casts section
2 parents c94ec31 + 72e25aa commit 9e24a47

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/expressions/operator-expr.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ fn average(values: &[f64]) -> f64 {
307307

308308
`as` can be used to explicitly perform [coercions](../type-coercions.md), as well as the following additional casts.
309309
Any cast that does not fit either a coercion rule or an entry in the table is a compiler error.
310-
Here `*T` means either `*const T` or `*mut T`.
310+
Here `*T` means either `*const T` or `*mut T`. `m` stands for optional `mut` in
311+
reference types and `mut` or `const` in pointer types.
311312

312313
| Type of `e` | `U` | Cast performed by `e as U` |
313314
|-----------------------|-----------------------|----------------------------------|
@@ -318,17 +319,21 @@ Here `*T` means either `*const T` or `*mut T`.
318319
| `*T` | `*V` where `V: Sized` \* | Pointer to pointer cast |
319320
| `*T` where `T: Sized` | Integer type | Pointer to address cast |
320321
| Integer type | `*V` where `V: Sized` | Address to pointer cast |
321-
| `&[T; n]` | `*const T` | Array to pointer cast |
322+
| `&m₁ T` | `*m₂ T` \*\* | Reference to pointer cast |
323+
| `&m₁ [T; n]` | `*m₂ T` \*\* | Array to pointer cast |
322324
| [Function item] | [Function pointer] | Function item to function pointer cast |
323325
| [Function item] | `*V` where `V: Sized` | Function item to pointer cast |
324326
| [Function item] | Integer | Function item to address cast |
325327
| [Function pointer] | `*V` where `V: Sized` | Function pointer to pointer cast |
326328
| [Function pointer] | Integer | Function pointer to address cast |
327-
| Closure \*\* | Function pointer | Closure to function pointer cast |
329+
| Closure \*\*\* | Function pointer | Closure to function pointer cast |
328330

329331
\* or `T` and `V` are compatible unsized types, e.g., both slices, both the same trait object.
330332

331-
\*\* only for closures that do not capture (close over) any local variables
333+
\*\* only when `m₁` is `mut` or `m₂` is `const`. Casting `mut` reference to
334+
`const` pointer is allowed.
335+
336+
\*\*\* only for closures that do not capture (close over) any local variables
332337

333338
### Semantics
334339

0 commit comments

Comments
 (0)