]>
Commit | Line | Data |
---|---|---|
74b04a01 XL |
1 | A trait implementation has stricter requirements than the trait definition. |
2 | ||
3 | Erroneous code example: | |
60c5eb7d XL |
4 | |
5 | ```compile_fail,E0276 | |
6 | trait Foo { | |
7 | fn foo<T>(x: T); | |
8 | } | |
9 | ||
10 | impl Foo for bool { | |
11 | fn foo<T>(x: T) where T: Copy {} | |
12 | } | |
13 | ``` | |
14 | ||
15 | Here, all types implementing `Foo` must have a method `foo<T>(x: T)` which can | |
16 | take any type `T`. However, in the `impl` for `bool`, we have added an extra | |
17 | bound that `T` is `Copy`, which isn't compatible with the original trait. | |
18 | ||
19 | Consider removing the bound from the method or adding the bound to the original | |
20 | method definition in the trait. |