]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0582.md
Rollup merge of #67875 - dtolnay:hidden, r=GuillaumeGomez
[rust.git] / src / librustc_error_codes / error_codes / E0582.md
1 A lifetime appears only in an associated-type binding,
2 and not in the input types to the trait.
3
4 Erroneous code example:
5
6 ```compile_fail,E0582
7 fn bar<F>(t: F)
8     // No type can satisfy this requirement, since `'a` does not
9     // appear in any of the input types (here, `i32`):
10     where F: for<'a> Fn(i32) -> Option<&'a i32>
11 {
12 }
13
14 fn main() { }
15 ```
16
17 To fix this issue, either use the lifetime in the inputs, or use
18 `'static`. Example:
19
20 ```
21 fn bar<F, G>(t: F, u: G)
22     where F: for<'a> Fn(&'a i32) -> Option<&'a i32>,
23           G: Fn(i32) -> Option<&'static i32>,
24 {
25 }
26
27 fn main() { }
28 ```
29
30 Note: The examples above used to be (erroneously) accepted by the
31 compiler, but this was since corrected. See [issue #33685] for more
32 details.
33
34 [issue #33685]: https://github.com/rust-lang/rust/issues/33685