Point at explicit 'static obligations on a trait#129070
Point at explicit 'static obligations on a trait#129070bors merged 1 commit intorust-lang:masterfrom
'static obligations on a trait#129070Conversation
|
r? @davidtwco rustbot has assigned @davidtwco. Use |
| note: but lifetime parameter must outlive the static lifetime | ||
| --> $SRC_DIR/core/src/any.rs:LL:COL |
There was a problem hiding this comment.
Locally this actually show the right span, not sure why the stderr doesn't show it correctly.
There was a problem hiding this comment.
Probably has to do with the sorting of the entries. Try to put the Option<Ty> first?
There was a problem hiding this comment.
Oh, no, because we strip standard library sources in UI tests.
| error[E0310]: the parameter type `T` may not live long enough | ||
| --> $DIR/explicit-static-bound-on-trait.rs:8:23 | ||
| | | ||
| LL | Self { value: Box::new(value) } | ||
| | ^^^^^^^^^^^^^^^ | ||
| | | | ||
| | the parameter type `T` must be valid for the static lifetime... | ||
| | ...so that the type `T` will meet its required lifetime bounds | ||
| | | ||
| help: consider adding an explicit lifetime bound | ||
| | | ||
| LL | fn new<T: 'a + 'static>(value: T) -> Self { | ||
| | +++++++++ |
There was a problem hiding this comment.
This is the actual error that we should add context for in order to also support traits that are implicitly 'static because of the trait.
davidtwco
left a comment
There was a problem hiding this comment.
LGTM, r=me unless you want to experiment with compiler-errors' suggestions or your other comment isn't just something you intend to follow-up with.
compiler/rustc_trait_selection/src/error_reporting/infer/note.rs
Outdated
Show resolved
Hide resolved
Given `trait Any: 'static` and a `struct` with a `Box<dyn Any + 'a>` field, point at the `'static` bound in `Any` to explain why `'a: 'static`.
```
error[E0478]: lifetime bound not satisfied
--> f202.rs:2:12
|
2 | value: Box<dyn std::any::Any + 'a>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime `'a` as defined here
--> f202.rs:1:14
|
1 | struct Hello<'a> {
| ^^
note: but lifetime parameter must outlive the static lifetime
--> /home/gh-estebank/rust/library/core/src/any.rs:113:16
|
113 | pub trait Any: 'static {
| ^^^^^^^
```
Partially address rust-lang#33652.
|
@bors r=davidtwco |
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#127279 (use old ctx if has same expand environment during decode span) - rust-lang#127945 (Implement `debug_more_non_exhaustive`) - rust-lang#128941 ( Improve diagnostic-related lints: `untranslatable_diagnostic` & `diagnostic_outside_of_impl`) - rust-lang#129070 (Point at explicit `'static` obligations on a trait) - rust-lang#129187 (bootstrap: fix clean's remove_dir_all implementation) - rust-lang#129231 (improve submodule updates) - rust-lang#129264 (Update `library/Cargo.toml` in weekly job) - rust-lang#129284 (rustdoc: animate the `:target` highlight) - rust-lang#129302 (compiletest: use `std::fs::remove_dir_all` now that it is available) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#127279 (use old ctx if has same expand environment during decode span) - rust-lang#127945 (Implement `debug_more_non_exhaustive`) - rust-lang#128941 ( Improve diagnostic-related lints: `untranslatable_diagnostic` & `diagnostic_outside_of_impl`) - rust-lang#129070 (Point at explicit `'static` obligations on a trait) - rust-lang#129187 (bootstrap: fix clean's remove_dir_all implementation) - rust-lang#129231 (improve submodule updates) - rust-lang#129264 (Update `library/Cargo.toml` in weekly job) - rust-lang#129284 (rustdoc: animate the `:target` highlight) - rust-lang#129302 (compiletest: use `std::fs::remove_dir_all` now that it is available) r? `@ghost` `@rustbot` modify labels: rollup
Point at explicit `'static` obligations on a trait
Given `trait Any: 'static` and a `struct` with a `Box<dyn Any + 'a>` field, point at the `'static` bound in `Any` to explain why `'a: 'static`.
```
error[E0478]: lifetime bound not satisfied
--> f202.rs:2:12
|
2 | value: Box<dyn std::any::Any + 'a>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime `'a` as defined here
--> f202.rs:1:14
|
1 | struct Hello<'a> {
| ^^
note: but lifetime parameter must outlive the static lifetime
--> /home/gh-estebank/rust/library/core/src/any.rs:113:16
|
113 | pub trait Any: 'static {
| ^^^^^^^
```
Partially address rust-lang#33652.
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#127279 (use old ctx if has same expand environment during decode span) - rust-lang#127945 (Implement `debug_more_non_exhaustive`) - rust-lang#128941 ( Improve diagnostic-related lints: `untranslatable_diagnostic` & `diagnostic_outside_of_impl`) - rust-lang#129070 (Point at explicit `'static` obligations on a trait) - rust-lang#129187 (bootstrap: fix clean's remove_dir_all implementation) - rust-lang#129231 (improve submodule updates) - rust-lang#129264 (Update `library/Cargo.toml` in weekly job) - rust-lang#129284 (rustdoc: animate the `:target` highlight) - rust-lang#129302 (compiletest: use `std::fs::remove_dir_all` now that it is available) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#129070 - estebank:static-trait, r=davidtwco Point at explicit `'static` obligations on a trait Given `trait Any: 'static` and a `struct` with a `Box<dyn Any + 'a>` field, point at the `'static` bound in `Any` to explain why `'a: 'static`. ``` error[E0478]: lifetime bound not satisfied --> f202.rs:2:12 | 2 | value: Box<dyn std::any::Any + 'a>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: lifetime parameter instantiated with the lifetime `'a` as defined here --> f202.rs:1:14 | 1 | struct Hello<'a> { | ^^ note: but lifetime parameter must outlive the static lifetime --> /home/gh-estebank/rust/library/core/src/any.rs:113:16 | 113 | pub trait Any: 'static { | ^^^^^^^ ``` Partially address rust-lang#33652.
Given
trait Any: 'staticand astructwith aBox<dyn Any + 'a>field, point at the'staticbound inAnyto explain why'a: 'static.Partially address #33652.