]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0212.md
Rollup merge of #93556 - dtolnay:trailingcomma, r=cjgillot
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0212.md
1 Cannot use the associated type of
2 a trait with uninferred generic parameters.
3
4 Erroneous code example:
5
6 ```compile_fail,E0212
7 pub trait Foo<T> {
8     type A;
9
10     fn get(&self, t: T) -> Self::A;
11 }
12
13 fn foo2<I : for<'x> Foo<&'x isize>>(
14     field: I::A) {} // error!
15 ```
16
17 In this example, we have to instantiate `'x`, and
18 we don't know what lifetime to instantiate it with.
19 To fix this, spell out the precise lifetimes involved.
20 Example:
21
22 ```
23 pub trait Foo<T> {
24     type A;
25
26     fn get(&self, t: T) -> Self::A;
27 }
28
29 fn foo3<I : for<'x> Foo<&'x isize>>(
30     x: <I as Foo<&isize>>::A) {} // ok!
31
32
33 fn foo4<'a, I : for<'x> Foo<&'x isize>>(
34     x: <I as Foo<&'a isize>>::A) {} // ok!
35 ```