about summary refs log tree commit diff
path: root/src/librustc_error_codes
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustc_error_codes')
-rw-r--r--src/librustc_error_codes/error_codes.rs2
-rw-r--r--src/librustc_error_codes/error_codes/E0477.md45
2 files changed, 46 insertions, 1 deletions
diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs
index 18d58d9d19e..272147e28a4 100644
--- a/src/librustc_error_codes/error_codes.rs
+++ b/src/librustc_error_codes/error_codes.rs
@@ -238,6 +238,7 @@ E0463: include_str!("./error_codes/E0463.md"),
 E0466: include_str!("./error_codes/E0466.md"),
 E0468: include_str!("./error_codes/E0468.md"),
 E0469: include_str!("./error_codes/E0469.md"),
+E0477: include_str!("./error_codes/E0477.md"),
 E0478: include_str!("./error_codes/E0478.md"),
 E0491: include_str!("./error_codes/E0491.md"),
 E0492: include_str!("./error_codes/E0492.md"),
@@ -531,7 +532,6 @@ E0745: include_str!("./error_codes/E0745.md"),
     E0474, // captured variable `..` does not outlive the enclosing closure
     E0475, // index of slice outside its lifetime
     E0476, // lifetime of the source pointer does not outlive lifetime bound...
-    E0477, // the type `..` does not fulfill the required lifetime...
     E0479, // the type `..` (provided as the value of a type parameter) is...
     E0480, // lifetime of method receiver does not outlive the method call
     E0481, // lifetime of function argument does not outlive the function call
diff --git a/src/librustc_error_codes/error_codes/E0477.md b/src/librustc_error_codes/error_codes/E0477.md
new file mode 100644
index 00000000000..29ce5343345
--- /dev/null
+++ b/src/librustc_error_codes/error_codes/E0477.md
@@ -0,0 +1,45 @@
+The type does not fulfill the required lifetime.
+
+Erroneous code example:
+
+```compile_fail,E0477
+use std::sync::Mutex;
+
+struct MyString<'a> {
+    data: &'a str,
+}
+
+fn i_want_static_closure<F>(a: F)
+    where F: Fn() + 'static {}
+
+fn print_string<'a>(s: Mutex<MyString<'a>>) {
+
+    i_want_static_closure(move || {     // error: this closure has lifetime 'a
+                                        //        rather than 'static
+        println!("{}", s.lock().unwrap().data);
+    });
+}
+```
+
+In this example, the closure doesn't satisfy the `'static` lifetime constraint.
+To fix this kind of error, you need to double check lifetime of the type. Here,
+we can fix this problem by giving `s` a static lifetime:
+
+```
+use std::sync::Mutex;
+
+struct MyString<'a> {
+    data: &'a str,
+}
+
+fn i_want_static_closure<F>(a: F)
+    where F: Fn() + 'static {}
+
+fn print_string(s: Mutex<MyString<'static>>) {
+
+    i_want_static_closure(move || {     // error: this closure has lifetime 'a
+                                        //        rather than 'static
+        println!("{}", s.lock().unwrap().data);
+    });
+}
+```