about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2017-01-19 11:56:04 +0100
committerGitHub <noreply@github.com>2017-01-19 11:56:04 +0100
commitba76f5158caeb312d40ada78b99da49fcb9e2099 (patch)
tree94f9c9e585e1140995aff4d7c2f8357731238ca1
parent7985ae0bb1653f59063d565f23159fdeb37cfadb (diff)
parentc525094badc72c50fb713922d4aa0d0513622ff2 (diff)
downloadrust-ba76f5158caeb312d40ada78b99da49fcb9e2099.tar.gz
rust-ba76f5158caeb312d40ada78b99da49fcb9e2099.zip
Rollup merge of #39091 - richard-imaoka:E0491-long-explanation, r=GuillaumeGomez
Add error explanation for E0491

Refs #32777

Please let me know if any question or anything doesn't look right about this.
-rw-r--r--src/librustc/diagnostics.rs35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs
index 636d543a071..0d180e6ad76 100644
--- a/src/librustc/diagnostics.rs
+++ b/src/librustc/diagnostics.rs
@@ -1454,6 +1454,40 @@ struct Prince<'kiss, 'SnowWhite: 'kiss> { // You say here that 'kiss must live
 ```
 "##,
 
+E0491: r##"
+A reference has a longer lifetime than the data it references.
+
+Erroneous code example:
+
+```compile_fail,E0491
+// struct containing a reference requires a lifetime parameter,
+// because the data the reference points to must outlive the struct (see E0106)
+struct Struct<'a> {
+    ref_i32: &'a i32,
+}
+
+// However, a nested struct like this, the signature itself does not tell
+// whether 'a outlives 'b or the other way around.
+// So it could be possible that 'b of reference outlives 'a of the data.
+struct Nested<'a, 'b> {
+    ref_struct: &'b Struct<'a>, // compile error E0491
+}
+```
+
+To fix this issue, you can specify a bound to the lifetime like below:
+
+```
+struct Struct<'a> {
+    ref_i32: &'a i32,
+}
+
+// 'a: 'b means 'a outlives 'b
+struct Nested<'a: 'b, 'b> {
+    ref_struct: &'b Struct<'a>,
+}
+```
+"##,
+
 E0496: r##"
 A lifetime name is shadowing another lifetime name. Erroneous code example:
 
@@ -1697,7 +1731,6 @@ register_diagnostics! {
     E0488, // lifetime of variable does not enclose its declaration
     E0489, // type/lifetime parameter not in scope here
     E0490, // a value of type `..` is borrowed for too long
-    E0491, // in type `..`, reference has a longer lifetime than the data it...
     E0495, // cannot infer an appropriate lifetime due to conflicting requirements
     E0566  // conflicting representation hints
 }