@@ -1454,6 +1454,40 @@ struct Prince<'kiss, 'SnowWhite: 'kiss> { // You say here that 'kiss must live
1454
1454
```
1455
1455
"## ,
1456
1456
1457
+ E0491 : r##"
1458
+ A reference has a longer lifetime than the data it references.
1459
+
1460
+ Erroneous code example:
1461
+
1462
+ ```compile_fail,E0491
1463
+ // struct containing a reference requires a lifetime parameter,
1464
+ // because the data the reference points to must outlive the struct (see E0106)
1465
+ struct Struct<'a> {
1466
+ ref_i32: &'a i32,
1467
+ }
1468
+
1469
+ // However, a nested struct like this, the signature itself does not tell
1470
+ // whether 'a outlives 'b or the other way around.
1471
+ // So it could be possible that 'b of reference outlives 'a of the data.
1472
+ struct Nested<'a, 'b> {
1473
+ ref_struct: &'b Struct<'a>, // compile error E0491
1474
+ }
1475
+ ```
1476
+
1477
+ To fix this issue, you can specify a bound to the lifetime like below:
1478
+
1479
+ ```
1480
+ struct Struct<'a> {
1481
+ ref_i32: &'a i32,
1482
+ }
1483
+
1484
+ // 'a: 'b means 'a outlives 'b
1485
+ struct Nested<'a: 'b, 'b> {
1486
+ ref_struct: &'b Struct<'a>,
1487
+ }
1488
+ ```
1489
+ "## ,
1490
+
1457
1491
E0496 : r##"
1458
1492
A lifetime name is shadowing another lifetime name. Erroneous code example:
1459
1493
@@ -1698,7 +1732,6 @@ register_diagnostics! {
1698
1732
E0488 , // lifetime of variable does not enclose its declaration
1699
1733
E0489 , // type/lifetime parameter not in scope here
1700
1734
E0490 , // a value of type `..` is borrowed for too long
1701
- E0491 , // in type `..`, reference has a longer lifetime than the data it...
1702
1735
E0495 , // cannot infer an appropriate lifetime due to conflicting requirements
1703
1736
E0566 // conflicting representation hints
1704
1737
}
0 commit comments