@@ -17,12 +17,12 @@ function result.
17
17
The most common case of coercion is removing mutability from a reference:
18
18
19
19
* ` &mut T ` to ` &T `
20
-
20
+
21
21
An analogous conversion is to remove mutability from a
22
22
[ raw pointer] ( raw-pointers.md ) :
23
23
24
24
* ` *mut T ` to ` *const T `
25
-
25
+
26
26
References can also be coerced to raw pointers:
27
27
28
28
* ` &T ` to ` *const T `
@@ -32,7 +32,7 @@ References can also be coerced to raw pointers:
32
32
Custom coercions may be defined using [ ` Deref ` ] ( deref-coercions.md ) .
33
33
34
34
Coercion is transitive.
35
-
35
+
36
36
# ` as `
37
37
38
38
The ` as ` keyword does safe casting:
@@ -64,7 +64,7 @@ A cast `e as U` is also valid in any of the following cases:
64
64
and ` U ` is an integer type; * enum-cast*
65
65
* ` e ` has type ` bool ` or ` char ` and ` U ` is an integer type; * prim-int-cast*
66
66
* ` e ` has type ` u8 ` and ` U ` is ` char ` ; * u8-char-cast*
67
-
67
+
68
68
For example
69
69
70
70
``` rust
@@ -98,9 +98,9 @@ The semantics of numeric casts are:
98
98
99
99
[ float-int ] : https://github.com/rust-lang/rust/issues/10184
100
100
[ float-float ] : https://github.com/rust-lang/rust/issues/15536
101
-
101
+
102
102
## Pointer casts
103
-
103
+
104
104
Perhaps surprisingly, it is safe to cast [ raw pointers] ( raw-pointers.md ) to and
105
105
from integers, and to cast between pointers to different types subject to
106
106
some constraints. It is only unsafe to dereference the pointer:
@@ -114,7 +114,7 @@ let b = a as u32;
114
114
115
115
* ` e ` has type ` *T ` , ` U ` has type ` *U_0 ` , and either ` U_0: Sized ` or
116
116
` unsize_kind(T) == unsize_kind(U_0) ` ; a * ptr-ptr-cast*
117
-
117
+
118
118
* ` e ` has type ` *T ` and ` U ` is a numeric type, while ` T: Sized ` ; * ptr-addr-cast*
119
119
120
120
* ` e ` is an integer and ` U ` is ` *U_0 ` , while ` U_0: Sized ` ; * addr-ptr-cast*
0 commit comments