]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0581.md
Rollup merge of #68120 - Centril:ban-range-to-dotdotdot, r=oli-obk
[rust.git] / src / librustc_error_codes / error_codes / E0581.md
1 In a `fn` type, a lifetime appears only in the return type,
2 and not in the arguments types.
3
4 Erroneous code example:
5
6 ```compile_fail,E0581
7 fn main() {
8     // Here, `'a` appears only in the return type:
9     let x: for<'a> fn() -> &'a i32;
10 }
11 ```
12
13 To fix this issue, either use the lifetime in the arguments, or use
14 `'static`. Example:
15
16 ```
17 fn main() {
18     // Here, `'a` appears only in the return type:
19     let x: for<'a> fn(&'a i32) -> &'a i32;
20     let y: fn() -> &'static i32;
21 }
22 ```
23
24 Note: The examples above used to be (erroneously) accepted by the
25 compiler, but this was since corrected. See [issue #33685] for more
26 details.
27
28 [issue #33685]: https://github.com/rust-lang/rust/issues/33685