1
1
# Type coercions
2
2
3
- ** Type coercions** are implicit changes of the type of a value. They happen
4
- automatically at specific locations and are highly restricted in what types
5
- actually coerce.
3
+ ** Type coercions** are implicit operations that change the type of a value.
4
+ They happen automatically at specific locations and are highly restricted in
5
+ what types actually coerce.
6
6
7
7
Coercions are originally defined in [ RFC 401] and expanded upon in [ RFC 1558] .
8
8
@@ -21,7 +21,7 @@ sites are:
21
21
let _ : & i8 = & mut 42 ;
22
22
```
23
23
24
- * ` static ` and ` const ` items (similar to ` let ` statements).
24
+ * ` static ` and ` const ` item declarations (similar to ` let ` statements).
25
25
26
26
* Arguments for function calls
27
27
@@ -52,19 +52,20 @@ sites are:
52
52
Foo { x : & mut 42 };
53
53
}
54
54
```
55
+
56
+ (Note that lifetime specifiers on ` struct Foo ` have been omitted for brevity.)
55
57
56
58
* Function results&ndash ; either the final line of a block if it is not
57
59
semicolon-terminated or any expression in a ` return ` statement
58
60
59
- For example, ` x ` is coerced to have type ` &dyn Binary ` in the following:
61
+ For example, ` x ` is coerced to have type ` &dyn Display ` in the following:
60
62
61
63
``` rust
62
- fn foo (x : & u32 ) -> & dyn Binary {
64
+ fn foo (x : & u32 ) -> & dyn Display {
63
65
x
64
66
}
65
67
```
66
- The [ as] keyword can also be used to perform explicit type coersion, as well as
67
- some additional casts.
68
+ * The [ as] type cast operator can also explicitly perform type coersion.
68
69
69
70
70
71
If the expression in one of these coercion sites is a coercion-propagating
0 commit comments