File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -338,6 +338,7 @@ E0619: include_str!("./error_codes/E0619.md"),
338
338
E0620 : include_str!( "./error_codes/E0620.md" ) ,
339
339
E0621 : include_str!( "./error_codes/E0621.md" ) ,
340
340
E0622 : include_str!( "./error_codes/E0622.md" ) ,
341
+ E0623 : include_str!( "./error_codes/E0623.md" ) ,
341
342
E0624 : include_str!( "./error_codes/E0624.md" ) ,
342
343
E0626 : include_str!( "./error_codes/E0626.md" ) ,
343
344
E0633 : include_str!( "./error_codes/E0633.md" ) ,
@@ -565,7 +566,6 @@ E0743: include_str!("./error_codes/E0743.md"),
565
566
// E0611, // merged into E0616
566
567
// E0612, // merged into E0609
567
568
// E0613, // Removed (merged with E0609)
568
- E0623 , // lifetime mismatch where both parameters are anonymous regions
569
569
E0625 , // thread-local statics cannot be accessed at compile-time
570
570
E0627 , // yield statement outside of generator literal
571
571
E0628 , // generators cannot have explicit parameters
Original file line number Diff line number Diff line change
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
+ ```
You can’t perform that action at this time.
0 commit comments