Rollup merge of #75702 - GuillaumeGomez:cleanup-e0759, r=pickfire

Clean up E0759 explanation

r? @Dylan-DPC

cc @pickfire
This commit is contained in:
Josh Stone 2020-08-20 10:07:22 -07:00 committed by GitHub
commit ba104d291a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,34 +1,28 @@
A `'static` requirement in a return type involving a trait is not fulfilled.
Return type involving a trait did not require `'static` lifetime.
Erroneous code examples:
```compile_fail,E0759
use std::fmt::Debug;
fn foo(x: &i32) -> impl Debug {
fn foo(x: &i32) -> impl Debug { // error!
x
}
```
```compile_fail,E0759
# use std::fmt::Debug;
fn bar(x: &i32) -> Box<dyn Debug> {
fn bar(x: &i32) -> Box<dyn Debug> { // error!
Box::new(x)
}
```
These examples have the same semantics as the following:
Add `'static` requirement to fix them:
```compile_fail,E0759
# use std::fmt::Debug;
fn foo(x: &i32) -> impl Debug + 'static {
fn foo(x: &i32) -> impl Debug + 'static { // ok!
x
}
```
```compile_fail,E0759
# use std::fmt::Debug;
fn bar(x: &i32) -> Box<dyn Debug + 'static> {
fn bar(x: &i32) -> Box<dyn Debug + 'static> { // ok!
Box::new(x)
}
```