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

Commit 73642e2

Browse files
authored
Unrolled build for rust-lang#124746
Rollup merge of rust-lang#124746 - OliverKillane:E0582-explain-assoc-types-improvement, r=pnkfelix `rustc --explain E0582` additional example ## Context *From rust-lang#124744* Expands the example for E0582, an error ensuring that lifetime in a function's return type is sufficiently constrained (e.g. actually tied to some input type), to show an additional example where one sees the lifetime occurring syntactically among the relevant function input types, but is nonetheless rejected by rustc because a syntactic occurrence is not always sufficient.
2 parents c1dba09 + 012288b commit 73642e2

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+
The latter scenario encounters this error because `Foo::Assoc<'a>` could be
46+
implemented by a type that does not use the `'a` parameter, so there is no
47+
guarentee that `X::Assoc<'a>` actually uses `'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)