Skip to content

Commit 2312207

Browse files
Clean up E0049
1 parent 11bb297 commit 2312207

File tree

1 file changed

+21
-4
lines changed
  • src/librustc_error_codes/error_codes

1 file changed

+21
-4
lines changed

src/librustc_error_codes/error_codes/E0049.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
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.
33

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:
65

76
```compile_fail,E0049
87
trait Foo {
@@ -17,3 +16,21 @@ impl Foo for Bar {
1716
fn foo(x: bool) -> Self { Bar }
1817
}
1918
```
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+
```

0 commit comments

Comments
 (0)