From 751fe7c43d428595d965d22ff21cc3c39dbccd5a Mon Sep 17 00:00:00 2001 From: Donough Liu Date: Mon, 30 Dec 2019 14:41:46 +0800 Subject: [PATCH 1/2] Add error code explanation for E0477 --- src/librustc_error_codes/error_codes.rs | 2 +- src/librustc_error_codes/error_codes/E0477.md | 45 +++++++++++++++++++ src/test/ui/issues/issue-26217.stderr | 1 + src/test/ui/issues/issue-54943.stderr | 1 + .../ui/kindck/kindck-impl-type-params.stderr | 3 +- src/test/ui/kindck/kindck-send-object1.stderr | 3 +- ...s-bounded-by-trait-requiring-static.stderr | 1 + ...ions-bounded-method-type-parameters.stderr | 1 + 8 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 src/librustc_error_codes/error_codes/E0477.md diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs index 18d58d9d19e2c..272147e28a419 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 0000000000000..29ce534334598 --- /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(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 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(a: F) + where F: Fn() + 'static {} + +fn print_string(s: Mutex>) { + + i_want_static_closure(move || { // error: this closure has lifetime 'a + // rather than 'static + println!("{}", s.lock().unwrap().data); + }); +} +``` diff --git a/src/test/ui/issues/issue-26217.stderr b/src/test/ui/issues/issue-26217.stderr index 8bcc62ab2e73c..be9da569f8be1 100644 --- a/src/test/ui/issues/issue-26217.stderr +++ b/src/test/ui/issues/issue-26217.stderr @@ -8,3 +8,4 @@ LL | foo::<&'a i32>(); error: aborting due to previous error +For more information about this error, try `rustc --explain E0477`. diff --git a/src/test/ui/issues/issue-54943.stderr b/src/test/ui/issues/issue-54943.stderr index d0f03f90c8330..62aacee811110 100644 --- a/src/test/ui/issues/issue-54943.stderr +++ b/src/test/ui/issues/issue-54943.stderr @@ -8,3 +8,4 @@ LL | let x = foo::<&'a u32>(); error: aborting due to previous error +For more information about this error, try `rustc --explain E0477`. diff --git a/src/test/ui/kindck/kindck-impl-type-params.stderr b/src/test/ui/kindck/kindck-impl-type-params.stderr index 777a553c2a58a..2075fdd311e61 100644 --- a/src/test/ui/kindck/kindck-impl-type-params.stderr +++ b/src/test/ui/kindck/kindck-impl-type-params.stderr @@ -76,4 +76,5 @@ LL | let a: Box> = t; error: aborting due to 7 previous errors -For more information about this error, try `rustc --explain E0277`. +Some errors have detailed explanations: E0277, E0477. +For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/kindck/kindck-send-object1.stderr b/src/test/ui/kindck/kindck-send-object1.stderr index 436b92637aaad..b2e89087e387f 100644 --- a/src/test/ui/kindck/kindck-send-object1.stderr +++ b/src/test/ui/kindck/kindck-send-object1.stderr @@ -33,4 +33,5 @@ LL | assert_send::>(); error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0277`. +Some errors have detailed explanations: E0277, E0477. +For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/regions/regions-bounded-by-trait-requiring-static.stderr b/src/test/ui/regions/regions-bounded-by-trait-requiring-static.stderr index fcd7332cf39f9..c72d6483c28f4 100644 --- a/src/test/ui/regions/regions-bounded-by-trait-requiring-static.stderr +++ b/src/test/ui/regions/regions-bounded-by-trait-requiring-static.stderr @@ -48,3 +48,4 @@ LL | assert_send::<*mut &'a isize>(); error: aborting due to 6 previous errors +For more information about this error, try `rustc --explain E0477`. diff --git a/src/test/ui/regions/regions-bounded-method-type-parameters.stderr b/src/test/ui/regions/regions-bounded-method-type-parameters.stderr index f77f97f44f2b7..66b61b1349d2b 100644 --- a/src/test/ui/regions/regions-bounded-method-type-parameters.stderr +++ b/src/test/ui/regions/regions-bounded-method-type-parameters.stderr @@ -8,3 +8,4 @@ LL | Foo.some_method::<&'a isize>(); error: aborting due to previous error +For more information about this error, try `rustc --explain E0477`. From b4e1fbcf8147362ee82c8e82ff270ddc3eb08270 Mon Sep 17 00:00:00 2001 From: Donough Liu Date: Mon, 30 Dec 2019 17:14:08 +0800 Subject: [PATCH 2/2] Gammer fix --- src/librustc_error_codes/error_codes/E0477.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0477.md b/src/librustc_error_codes/error_codes/E0477.md index 29ce534334598..794456451ef33 100644 --- a/src/librustc_error_codes/error_codes/E0477.md +++ b/src/librustc_error_codes/error_codes/E0477.md @@ -21,9 +21,9 @@ fn print_string<'a>(s: Mutex>) { } ``` -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: +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;