Skip to content

Commit eb515e7

Browse files
committed
Remove incorrect coercion. Define type coercions.
1 parent d9e6a59 commit eb515e7

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/type-coercions.md

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Type coercions
22

3-
Coercions are defined in [RFC 401]. [RFC 1558] then expanded on that.
4-
A coercion is implicit and has no syntax.
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.
56

6-
[RFC 401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
7-
[RFC 1558]: https://github.com/rust-lang/rfcs/blob/master/text/1558-closure-to-fn-coercion.md
7+
Coercions are originally defined in [RFC 401] and expanded upon in [RFC 1558].
88

99
## Coercion sites
1010

@@ -21,7 +21,7 @@ sites are:
2121
let _: i8 = 42;
2222
```
2323

24-
* `static` and `const` statements (similar to `let` statements).
24+
* `static` and `const` items (similar to `let` statements).
2525

2626
* Arguments for function calls
2727

@@ -41,7 +41,7 @@ sites are:
4141
For method calls, the receiver (`self` parameter) can only take advantage
4242
of [unsized coercions](#unsized-coercions).
4343

44-
* Instantiations of struct or variant fields
44+
* Instantiations of struct, union, or enum variant fields
4545

4646
For example, `42` is coerced to have type `i8` in the following:
4747

@@ -53,7 +53,7 @@ sites are:
5353
}
5454
```
5555

56-
* Function results, either the final line of a block if it is not
56+
* Function results — either the final line of a block if it is not
5757
semicolon-terminated or any expression in a `return` statement
5858

5959
For example, `42` is coerced to have type `i8` in the following:
@@ -91,7 +91,7 @@ the block has a known type.
9191

9292
Coercion is allowed between the following types:
9393

94-
* `T` to `U` if `T` is a subtype of `U` (*reflexive case*)
94+
* `T` to `U` if `T` is a [subtype] of `U` (*reflexive case*)
9595

9696
* `T_1` to `T_3` where `T_1` coerces to `T_2` and `T_2` coerces to `T_3`
9797
(*transitive case*)
@@ -140,7 +140,7 @@ Coercion is allowed between the following types:
140140
- `*mut T`
141141
- `Box<T>`
142142

143-
and where `T` can obtained from `U` by [unsized coercion](#unsized-coercions).
143+
and where `T` can obtained from `U` by an [unsized coercion](#unsized-coercions).
144144

145145
<!--In the future, coerce_inner will be recursively extended to tuples and
146146
structs. In addition, coercions from sub-traits to super-traits will be
@@ -164,8 +164,7 @@ the compiler will provide an implementation of `Unsize<U>` for `T`:
164164

165165
* `[T; n]` to `[T]`.
166166

167-
* `T` to `U`, when `U` is a trait object type and either `T` implements `U` or
168-
`T` is a trait object for a subtrait of `U`.
167+
* `T` to `dyn U`, when `T` implements `U + Sized`
169168

170169
* `Foo<..., T, ...>` to `Foo<..., U, ...>`, when:
171170
* `Foo` is a struct.
@@ -182,5 +181,8 @@ unsized coercion to `Foo<U>`.
182181
> has been stabilized, the traits themselves are not yet stable and therefore
183182
> can't be used directly in stable Rust.
184183
185-
[Unsize]: ../std/marker/trait.Unsize.html
186-
[CoerceUnsized]: ../std/ops/trait.CoerceUnsized.html
184+
[RFC 401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
185+
[RFC 1558]: https://github.com/rust-lang/rfcs/blob/master/text/1558-closure-to-fn-coercion.md
186+
[subtype]: subtyping.html
187+
[`Unsize`]: ../std/marker/trait.Unsize.html
188+
[`CoerceUnsized`]: ../std/ops/trait.CoerceUnsized.html

0 commit comments

Comments
 (0)