summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_error_codes/src/error_codes/E0477.md
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_error_codes/src/error_codes/E0477.md')
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0477.md46
1 files changed, 46 insertions, 0 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0477.md b/compiler/rustc_error_codes/src/error_codes/E0477.md
new file mode 100644
index 000000000..c6be8dc70
--- /dev/null
+++ b/compiler/rustc_error_codes/src/error_codes/E0477.md
@@ -0,0 +1,46 @@
+#### Note: this error code is no longer emitted by the compiler.
+
+The type does not fulfill the required lifetime.
+
+Erroneous code example:
+
+```compile_fail
+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 does not satisfy the `'static` lifetime constraint.
+To fix this error, you need to double check the 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 || { // ok!
+ println!("{}", s.lock().unwrap().data);
+ });
+}
+```