]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_error_codes/src/error_codes/E0623.md
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / compiler / rustc_error_codes / src / error_codes / E0623.md
1 A lifetime didn't match what was expected.
2
3 Erroneous code example:
4
5 ```compile_fail,E0623
6 struct Foo<'a> {
7 x: &'a isize,
8 }
9
10 fn bar<'short, 'long>(c: Foo<'short>, l: &'long isize) {
11 let _: Foo<'long> = c; // error!
12 }
13 ```
14
15 In this example, we tried to set a value with an incompatible lifetime to
16 another one (`'long` is unrelated to `'short`). We can solve this issue in
17 two different ways:
18
19 Either we make `'short` live at least as long as `'long`:
20
21 ```
22 struct Foo<'a> {
23 x: &'a isize,
24 }
25
26 // we set 'short to live at least as long as 'long
27 fn bar<'short: 'long, 'long>(c: Foo<'short>, l: &'long isize) {
28 let _: Foo<'long> = c; // ok!
29 }
30 ```
31
32 Or we use only one lifetime:
33
34 ```
35 struct Foo<'a> {
36 x: &'a isize,
37 }
38 fn bar<'short>(c: Foo<'short>, l: &'short isize) {
39 let _: Foo<'short> = c; // ok!
40 }
41 ```