Updated error code explanation
This commit is contained in:
parent
02f7806ecd
commit
ad7c2b0660
1 changed files with 34 additions and 0 deletions
|
@ -27,6 +27,40 @@ fn bar<F, G>(t: F, u: G)
|
||||||
fn main() { }
|
fn main() { }
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This error also includes the use of associated types with lifetime parameters.
|
||||||
|
```compile_fail,E0582
|
||||||
|
trait Foo {
|
||||||
|
type Assoc<'a>;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Bar<X, F>
|
||||||
|
where
|
||||||
|
X: Foo,
|
||||||
|
F: for<'a> Fn(X::Assoc<'a>) -> &'a i32
|
||||||
|
{
|
||||||
|
x: X,
|
||||||
|
f: F
|
||||||
|
}
|
||||||
|
```
|
||||||
|
This is as `Foo::Assoc<'a>` could be implemented by a type that does not use
|
||||||
|
the `'a` parameter, so there is no guarentee that `X::Assoc<'a>` actually uses
|
||||||
|
`'a`.
|
||||||
|
|
||||||
|
To fix this we can pass a dummy parameter:
|
||||||
|
```
|
||||||
|
# trait Foo {
|
||||||
|
# type Assoc<'a>;
|
||||||
|
# }
|
||||||
|
struct Bar<X, F>
|
||||||
|
where
|
||||||
|
X: Foo,
|
||||||
|
F: for<'a> Fn(X::Assoc<'a>, /* dummy */ &'a ()) -> &'a i32
|
||||||
|
{
|
||||||
|
x: X,
|
||||||
|
f: F
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Note: The examples above used to be (erroneously) accepted by the
|
Note: The examples above used to be (erroneously) accepted by the
|
||||||
compiler, but this was since corrected. See [issue #33685] for more
|
compiler, but this was since corrected. See [issue #33685] for more
|
||||||
details.
|
details.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue