about summary refs log tree commit diff
path: root/src/librustc_error_codes/error_codes
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-12-31 12:58:10 +0000
committerbors <bors@rust-lang.org>2019-12-31 12:58:10 +0000
commit509510152865d5a9a47723ad56047904986c9dd9 (patch)
treed9ee7734e8761c217d43c5f2cc3e8bd90ae754e7 /src/librustc_error_codes/error_codes
parent71bb0ff33e3759ee71ea19c230492c11e5e32b87 (diff)
parent529a42a1a6b6523e8376610556d9890479b9524c (diff)
downloadrust-509510152865d5a9a47723ad56047904986c9dd9.tar.gz
rust-509510152865d5a9a47723ad56047904986c9dd9.zip
Auto merge of #67752 - Dylan-DPC:rollup-7f9v4nx, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #67430 (doc: minus (U+2212) instead of dash (U+002D) for negative infinity)
 - #67697 (Move the region_scope_tree query to librustc_passes.)
 - #67719 (Add self to .mailmap)
 - #67723 (Add error code explanation for E0477)
 - #67735 (Support `-Z ui-testing=yes/no`)

Failed merges:

r? @ghost
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..794456451ef
--- /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 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 || {     // error: this closure has lifetime 'a
+                                        //        rather than 'static
+        println!("{}", s.lock().unwrap().data);
+    });
+}
+```