about summary refs log tree commit diff
path: root/src/librustc_error_codes/error_codes
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustc_error_codes/error_codes')
-rw-r--r--src/librustc_error_codes/error_codes/E0477.md45
1 files changed, 45 insertions, 0 deletions
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);
+    });
+}
+```