File tree 1 file changed +21
-4
lines changed
src/librustc_error_codes/error_codes 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change 1
- This error indicates that an attempted implementation of a trait method
2
- has the wrong number of type or const parameters.
1
+ An attempted implementation of a trait method has the wrong number of type or
2
+ const parameters.
3
3
4
- For example, the trait below has a method ` foo ` with a type parameter ` T ` ,
5
- but the implementation of ` foo ` for the type ` Bar ` is missing this parameter:
4
+ Erroneous code example:
6
5
7
6
``` compile_fail,E0049
8
7
trait Foo {
@@ -17,3 +16,21 @@ impl Foo for Bar {
17
16
fn foo(x: bool) -> Self { Bar }
18
17
}
19
18
```
19
+
20
+ For example, the ` Foo ` trait has a method ` foo ` with a type parameter ` T ` ,
21
+ but the implementation of ` foo ` for the type ` Bar ` is missing this parameter.
22
+ To fix this error, they must have the same type parameters:
23
+
24
+ ```
25
+ trait Foo {
26
+ fn foo<T: Default>(x: T) -> Self;
27
+ }
28
+
29
+ struct Bar;
30
+
31
+ impl Foo for Bar {
32
+ fn foo<T: Default>(x: T) -> Self { // ok!
33
+ Bar
34
+ }
35
+ }
36
+ ```
You can’t perform that action at this time.
0 commit comments