mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
Rollup merge of #75702 - GuillaumeGomez:cleanup-e0759, r=pickfire
Clean up E0759 explanation r? @Dylan-DPC cc @pickfire
This commit is contained in:
commit
ba104d291a
@ -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)
|
||||
}
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user