From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../rustc_error_codes/src/error_codes/E0477.md | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 compiler/rustc_error_codes/src/error_codes/E0477.md (limited to 'compiler/rustc_error_codes/src/error_codes/E0477.md') 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(a: F) + where F: Fn() + 'static {} + +fn print_string<'a>(s: Mutex>) { + + 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(a: F) + where F: Fn() + 'static {} + +fn print_string(s: Mutex>) { + + i_want_static_closure(move || { // ok! + println!("{}", s.lock().unwrap().data); + }); +} +``` -- cgit v1.2.3