@@ -15,10 +15,10 @@ sites are:
15
15
16
16
* ` let ` statements where an explicit type is given.
17
17
18
- For example, ` 42 ` is coerced to have type ` i8 ` in the following:
18
+ For example, ` &mut 42` is coerced to have type ` & i8` in the following:
19
19
20
20
``` rust
21
- let _ : i8 = 42 ;
21
+ let _ : & i8 = & mut 42 ;
22
22
```
23
23
24
24
* ` static ` and ` const ` items (similar to ` let ` statements).
@@ -28,13 +28,13 @@ sites are:
28
28
The value being coerced is the actual parameter, and it is coerced to
29
29
the type of the formal parameter.
30
30
31
- For example, ` 42 ` is coerced to have type ` i8 ` in the following:
31
+ For example, ` &mut 42` is coerced to have type ` & i8` in the following:
32
32
33
33
``` rust
34
- fn bar (_ : i8 ) { }
34
+ fn bar (_ : & i8 ) { }
35
35
36
36
fn main () {
37
- bar (42 );
37
+ bar (& mut 42 );
38
38
}
39
39
```
40
40
@@ -43,26 +43,29 @@ sites are:
43
43
44
44
* Instantiations of struct, union, or enum variant fields
45
45
46
- For example, ` 42 ` is coerced to have type ` i8 ` in the following:
46
+ For example, ` &mut 42` is coerced to have type ` & i8` in the following:
47
47
48
48
``` rust
49
- struct Foo { x : i8 }
49
+ struct Foo { x : & i8 }
50
50
51
51
fn main () {
52
- Foo { x : 42 };
52
+ Foo { x : & mut 42 };
53
53
}
54
54
```
55
55
56
- * Function results &ndash ; either the final line of a block if it is not
56
+ * Function results&ndash ; either the final line of a block if it is not
57
57
semicolon-terminated or any expression in a ` return ` statement
58
58
59
- For example, ` 42 ` is coerced to have type ` i8 ` in the following:
59
+ For example, ` x ` is coerced to have type ` &dyn Binary ` in the following:
60
60
61
61
``` rust
62
- fn foo () -> i8 {
63
- 42
62
+ fn foo (x : & u32 ) -> & dyn Binary {
63
+ x
64
64
}
65
65
```
66
+ The [ as] keyword can also be used to perform explicit type coersion, as well as
67
+ some additional casts.
68
+
66
69
67
70
If the expression in one of these coercion sites is a coercion-propagating
68
71
expression, then the relevant sub-expressions in that expression are also
@@ -183,6 +186,7 @@ unsized coercion to `Foo<U>`.
183
186
184
187
[ RFC 401 ] : https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
185
188
[ RFC 1558 ] : https://github.com/rust-lang/rfcs/blob/master/text/1558-closure-to-fn-coercion.md
186
- [ subtype ] : subtyping.html
189
+ [ subtype ] : subtyping.html`
190
+ [ as ] : operator-expr.html#type-cast-expressions`
187
191
[ `Unsize` ] : ../std/marker/trait.Unsize.html
188
192
[ `CoerceUnsized` ] : ../std/ops/trait.CoerceUnsized.html
0 commit comments