|
1 | 1 | This error indicates a violation of one of Rust's orphan rules for trait
|
2 | 2 | implementations. The rule concerns the use of type parameters in an
|
3 | 3 | implementation of a foreign trait (a trait defined in another crate), and
|
4 |
| -states that type parameters must be "covered" by a local type. To understand |
5 |
| -what this means, it is perhaps easiest to consider a few examples. |
| 4 | +states that type parameters must be "covered" by a local type. |
| 5 | + |
| 6 | +When implementing a foreign trait for a foreign type, |
| 7 | +the trait must have one or more type parameters. |
| 8 | +A type local to your crate must appear before any use of any type parameters. |
| 9 | + |
| 10 | +To understand what this means, it is perhaps easier to consider a few examples. |
6 | 11 |
|
7 | 12 | If `ForeignTrait` is a trait defined in some external crate `foo`, then the
|
8 | 13 | following trait `impl` is an error:
|
@@ -60,10 +65,18 @@ impl<P1, ..., Pm> ForeignTrait<T1, ..., Tn> for T0 { ... }
|
60 | 65 |
|
61 | 66 | where `P1, ..., Pm` are the type parameters of the `impl` and `T0, ..., Tn`
|
62 | 67 | are types. One of the types `T0, ..., Tn` must be a local type (this is another
|
63 |
| -orphan rule, see the explanation for E0117). Let `i` be the smallest integer |
64 |
| -such that `Ti` is a local type. Then no type parameter can appear in any of the |
65 |
| -`Tj` for `j < i`. |
| 68 | +orphan rule, see the explanation for E0117). |
| 69 | + |
| 70 | +Both of the following must be true: |
| 71 | +1. At least one of the types `T0..=Tn` must be a local type. |
| 72 | +Let `Ti` be the first such type. |
| 73 | +2. No uncovered type parameters `P1..=Pm` may appear in `T0..Ti` |
| 74 | +(excluding `Ti`). |
| 75 | + |
| 76 | +For information on the design of the orphan rules, |
| 77 | +see [RFC 2451] and [RFC 1023]. |
66 | 78 |
|
67 | 79 | For information on the design of the orphan rules, see [RFC 1023].
|
68 | 80 |
|
| 81 | +[RFC 2451]: https://rust-lang.github.io/rfcs/2451-re-rebalancing-coherence.html |
69 | 82 | [RFC 1023]: https://github.com/rust-lang/rfcs/blob/master/text/1023-rebalancing-coherence.md
|
0 commit comments