Skip to content

Commit

Permalink
clean up E0107 error explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Dec 3, 2019
1 parent 481b18a commit c911bb1
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/librustc_error_codes/error_codes/E0107.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
This error means that an incorrect number of generic arguments were provided:
An incorrect number of generic arguments were provided.

Erroneous code example:

```compile_fail,E0107
struct Foo<T> { x: T }
Expand All @@ -9,19 +11,34 @@ struct Baz<S, T> { x: Foo<S, T> } // error: wrong number of type arguments:
// expected 1, found 2
fn foo<T, U>(x: T, y: U) {}
fn f() {}
fn main() {
let x: bool = true;
foo::<bool>(x); // error: wrong number of type arguments:
// expected 2, found 1
foo::<bool, i32, i32>(x, 2, 4); // error: wrong number of type arguments:
// expected 2, found 3
f::<'static>(); // error: wrong number of lifetime arguments
// expected 0, found 1
}
```

When using/declaring an item with generic arguments, you must provide the exact
same number:

```
struct Foo<T> { x: T }
struct Bar<T> { x: Foo<T> } // ok!
struct Baz<S, T> { x: Foo<S>, y: Foo<T> } // ok!
fn foo<T, U>(x: T, y: U) {}
fn f() {}
fn main() {
f::<'static>(); // error: wrong number of lifetime arguments:
// expected 0, found 1
let x: bool = true;
foo::<bool, u32>(x, 12); // ok!
f(); // ok!
}
```

0 comments on commit c911bb1

Please sign in to comment.