Skip to content

Commit c911bb1

Browse files
clean up E0107 error explanation
1 parent 481b18a commit c911bb1

File tree

1 file changed

+20
-3
lines changed
  • src/librustc_error_codes/error_codes

1 file changed

+20
-3
lines changed
+20-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
This error means that an incorrect number of generic arguments were provided:
1+
An incorrect number of generic arguments were provided.
2+
3+
Erroneous code example:
24

35
```compile_fail,E0107
46
struct Foo<T> { x: T }
@@ -9,19 +11,34 @@ struct Baz<S, T> { x: Foo<S, T> } // error: wrong number of type arguments:
911
// expected 1, found 2
1012
1113
fn foo<T, U>(x: T, y: U) {}
14+
fn f() {}
1215
1316
fn main() {
1417
let x: bool = true;
1518
foo::<bool>(x); // error: wrong number of type arguments:
1619
// expected 2, found 1
1720
foo::<bool, i32, i32>(x, 2, 4); // error: wrong number of type arguments:
1821
// expected 2, found 3
22+
f::<'static>(); // error: wrong number of lifetime arguments
23+
// expected 0, found 1
1924
}
25+
```
26+
27+
When using/declaring an item with generic arguments, you must provide the exact
28+
same number:
29+
30+
```
31+
struct Foo<T> { x: T }
32+
33+
struct Bar<T> { x: Foo<T> } // ok!
34+
struct Baz<S, T> { x: Foo<S>, y: Foo<T> } // ok!
2035
36+
fn foo<T, U>(x: T, y: U) {}
2137
fn f() {}
2238
2339
fn main() {
24-
f::<'static>(); // error: wrong number of lifetime arguments:
25-
// expected 0, found 1
40+
let x: bool = true;
41+
foo::<bool, u32>(x, 12); // ok!
42+
f(); // ok!
2643
}
2744
```

0 commit comments

Comments
 (0)