Conversation
|
r? @davidtwco rustbot has assigned @davidtwco. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
Add this note to lifetime errors:
```text
error[E0521]: borrowed data escapes outside of function
--> $DIR/static-impl-obligation.rs:163:9
|
LL | fn bar<'a>(x: &'a &'a u32) {
| -- - `x` is a reference that is only valid in the function body
| |
| lifetime `'a` defined here
LL | let y: &dyn Foo = x;
LL | y.hello();
| ^^^^^^^^^
| |
| `x` escapes the function body here
| argument requires that `'a` must outlive `'static`
|
note: `'static` requirement for `<(dyn o::Foo + 'static)>::hello` introduced here
--> $DIR/static-impl-obligation.rs:158:40
|
LL | impl dyn Foo + 'static where Self: 'static {
| ^^^^^^^ `'static` requirement introduced here
LL | fn hello(&'static self) where Self: 'static {}
| ^^^^^^^ `'static` requirement introduced here
```
This currently only accounts for explicit bounds, other obligations like those arising from `Self` in a `impl dyn Trait {}` or from the receiver in `fn foo(&'static self)` are not accounted for.
6e47c50 to
e478abb
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
```
note: `'static` lifetime requirement from `<(dyn b::Foo + 'static)>::hello` introduced here
--> $DIR/static-impl-obligation.rs:16:18
|
LL | impl dyn Foo {
LL | fn hello(&'static self) {}
| ^^^^^^^^^^^^^ lifetime requirement introduced here
```
```
note: `'static` lifetime requirement from `<(dyn a::Foo + 'static)>::hello` introduced here
--> $DIR/static-impl-obligation.rs:4:5
|
LL | impl dyn Foo {
| ^^^^^^^^^^^^ lifetime requirement introduced here
LL | fn hello(&self) {}
|
```
… lifetime
```
note: `'static` lifetime requirement from `<(dyn a::Foo + 'static)>::hello` introduced here
--> $DIR/static-impl-obligation.rs:4:10
|
LL | impl dyn Foo {
| ^^^^^^^ `dyn Trait` introduces an implicit `'static` lifetime requirement
LL | fn hello(&self) {}
|
```
```
note: `'static` lifetime requirement from `<(dyn e::Foo + 'static)>::hello` introduced here
--> $DIR/static-impl-obligation.rs:48:20
|
LL | impl dyn Foo + 'static {
| ^^^^^^^ lifetime requirement introduced here
LL | fn hello(&self) {}
|
```
This comment has been minimized.
This comment has been minimized.
|
cc @rust-lang/clippy |
| error[E0478]: lifetime bound not satisfied | ||
| --> $DIR/static-impl-obligation.rs:221:10 | ||
| | | ||
| LL | impl MyTrait for dyn ObjectTrait + '_ {} | ||
| | ^^^^^^^ | ||
| | | ||
| note: lifetime parameter instantiated with the anonymous lifetime as defined here | ||
| --> $DIR/static-impl-obligation.rs:221:40 | ||
| | | ||
| LL | impl MyTrait for dyn ObjectTrait + '_ {} | ||
| | ^^ | ||
| = note: but lifetime parameter must outlive the static lifetime |
There was a problem hiding this comment.
Future work: This diagnostic should be pointing at 214 trait MyTrait where Self: 'static { as the reason why it must outlive 'static.
| error[E0803]: cannot infer an appropriate lifetime for lifetime parameter `'_` due to conflicting requirements | ||
| --> $DIR/static-impl-obligation.rs:221:22 | ||
| | | ||
| LL | impl MyTrait for dyn ObjectTrait + '_ {} | ||
| | ^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| note: first, the lifetime cannot outlive the anonymous lifetime as defined here... | ||
| --> $DIR/static-impl-obligation.rs:221:40 | ||
| | | ||
| LL | impl MyTrait for dyn ObjectTrait + '_ {} | ||
| | ^^ | ||
| note: ...so that the types are compatible | ||
| --> $DIR/static-impl-obligation.rs:221:22 | ||
| | | ||
| LL | impl MyTrait for dyn ObjectTrait + '_ {} | ||
| | ^^^^^^^^^^^^^^^^^^^^ | ||
| = note: expected `<dyn t::ObjectTrait as t::MyTrait>` | ||
| found `<dyn t::ObjectTrait as t::MyTrait>` | ||
| = note: but, the lifetime must be valid for the static lifetime... | ||
| note: ...so that the declared lifetime parameter bounds are satisfied | ||
| --> $DIR/static-impl-obligation.rs:221:22 | ||
| | | ||
| LL | impl MyTrait for dyn ObjectTrait + '_ {} | ||
| | ^^^^^^^^^^^^^^^^^^^^ |
There was a problem hiding this comment.
The second to last note should be pointing at 214.
|
@bors r+ rollup |
…l, r=davidtwco
Point at `'static` obligations from an fn being called
Add this note to lifetime errors:
```text
error[E0521]: borrowed data escapes outside of function
--> $DIR/static-impl-obligation.rs:163:9
|
LL | fn bar<'a>(x: &'a &'a u32) {
| -- - `x` is only valid in the function body
| |
| lifetime `'a` defined here
LL | let y: &dyn Foo = x;
LL | y.hello();
| ^^^^^^^^^
| |
| `x` escapes the function body here
| argument requires that `'a` must outlive `'static`
|
note: `'static` lifetime requirement from `<(dyn o::Foo + 'static)>::hello` introduced here
--> $DIR/static-impl-obligation.rs:158:20
|
LL | impl dyn Foo + 'static where Self: 'static {
| ^^^^^^^ ^^^^^^^ lifetime requirement introduced here
| |
| lifetime requirement introduced here
LL | fn hello(&'static self) where Self: 'static {}
| ^^^^^^^^^^^^^ ^^^^^^^ lifetime requirement introduced here
| |
| lifetime requirement introduced here
```
Follow up to rust-lang#121274, taking only a subset of that unmerged PR's functionality.
Add this note to lifetime errors:
Follow up to #121274, taking only a subset of that unmerged PR's functionality.