未验证 提交 ba104d29 编写于 作者: J Josh Stone 提交者: GitHub

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

Clean up E0759 explanation

r? @Dylan-DPC

cc @pickfire
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)
}
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册