]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0107.md
Rollup merge of #92310 - ehuss:rustdoc-ice, r=estebank
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0107.md
1 An incorrect number of generic arguments was provided.
2
3 Erroneous code example:
4
5 ```compile_fail,E0107
6 struct Foo<T> { x: T }
7
8 struct Bar { x: Foo }             // error: wrong number of type arguments:
9                                   //        expected 1, found 0
10 struct Baz<S, T> { x: Foo<S, T> } // error: wrong number of type arguments:
11                                   //        expected 1, found 2
12
13 fn foo<T, U>(x: T, y: U) {}
14 fn f() {}
15
16 fn main() {
17     let x: bool = true;
18     foo::<bool>(x);                 // error: wrong number of type arguments:
19                                     //        expected 2, found 1
20     foo::<bool, i32, i32>(x, 2, 4); // error: wrong number of type arguments:
21                                     //        expected 2, found 3
22     f::<'static>();                 // error: wrong number of lifetime arguments
23                                     //        expected 0, found 1
24 }
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!
35
36 fn foo<T, U>(x: T, y: U) {}
37 fn f() {}
38
39 fn main() {
40     let x: bool = true;
41     foo::<bool, u32>(x, 12);              // ok!
42     f();                                  // ok!
43 }
44 ```