]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0049.md
Rollup merge of #93556 - dtolnay:trailingcomma, r=cjgillot
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0049.md
1 An attempted implementation of a trait method has the wrong number of type or
2 const parameters.
3
4 Erroneous code example:
5
6 ```compile_fail,E0049
7 trait Foo {
8     fn foo<T: Default>(x: T) -> Self;
9 }
10
11 struct Bar;
12
13 // error: method `foo` has 0 type parameters but its trait declaration has 1
14 // type parameter
15 impl Foo for Bar {
16     fn foo(x: bool) -> Self { Bar }
17 }
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 ```