Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ad7c2b0

Browse files
committed
Updated error code explanation
1 parent 02f7806 commit ad7c2b0

File tree

1 file changed

+34
-0
lines changed
  • compiler/rustc_error_codes/src/error_codes

1 file changed

+34
-0
lines changed

compiler/rustc_error_codes/src/error_codes/E0582.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,40 @@ fn bar<F, G>(t: F, u: G)
2727
fn main() { }
2828
```
2929

30+
This error also includes the use of associated types with lifetime parameters.
31+
```compile_fail,E0582
32+
trait Foo {
33+
type Assoc<'a>;
34+
}
35+
36+
struct Bar<X, F>
37+
where
38+
X: Foo,
39+
F: for<'a> Fn(X::Assoc<'a>) -> &'a i32
40+
{
41+
x: X,
42+
f: F
43+
}
44+
```
45+
This is as `Foo::Assoc<'a>` could be implemented by a type that does not use
46+
the `'a` parameter, so there is no guarentee that `X::Assoc<'a>` actually uses
47+
`'a`.
48+
49+
To fix this we can pass a dummy parameter:
50+
```
51+
# trait Foo {
52+
# type Assoc<'a>;
53+
# }
54+
struct Bar<X, F>
55+
where
56+
X: Foo,
57+
F: for<'a> Fn(X::Assoc<'a>, /* dummy */ &'a ()) -> &'a i32
58+
{
59+
x: X,
60+
f: F
61+
}
62+
```
63+
3064
Note: The examples above used to be (erroneously) accepted by the
3165
compiler, but this was since corrected. See [issue #33685] for more
3266
details.

0 commit comments

Comments
 (0)