Skip to content

Commit a1e94cd

Browse files
sasurau4Joshua Nelson
and
Joshua Nelson
committed
Add long explanation for E0212
Update compiler/rustc_error_codes/src/error_codes/E0212.md Co-authored-by: Joshua Nelson <[email protected]>
1 parent 36363e5 commit a1e94cd

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ E0206: include_str!("./error_codes/E0206.md"),
111111
E0207: include_str!("./error_codes/E0207.md"),
112112
E0210: include_str!("./error_codes/E0210.md"),
113113
E0211: include_str!("./error_codes/E0211.md"),
114+
E0212: include_str!("./error_codes/E0212.md"),
114115
E0214: include_str!("./error_codes/E0214.md"),
115116
E0220: include_str!("./error_codes/E0220.md"),
116117
E0221: include_str!("./error_codes/E0221.md"),
@@ -503,7 +504,6 @@ E0779: include_str!("./error_codes/E0779.md"),
503504
// E0196, // cannot determine a type for this closure
504505
E0208,
505506
// E0209, // builtin traits can only be implemented on structs or enums
506-
E0212, // cannot extract an associated type from a higher-ranked trait bound
507507
// E0213, // associated types are not accepted in this context
508508
// E0215, // angle-bracket notation is not stable with `Fn`
509509
// E0216, // parenthetical notation is only stable with `Fn`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
```

0 commit comments

Comments
 (0)