Point at explicit 'static obligations on a trait by estebank · Pull Request #129070 · rust-lang/rust (original) (raw)

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation9 Commits1 Checks6 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

estebank

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 #33652.

@rustbot

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.

labels

Aug 14, 2024

estebank

Comment on lines +12 to +13

note: but lifetime parameter must outlive the static lifetime
--> $SRC_DIR/core/src/any.rs:LL:COL

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locally this actually show the right span, not sure why the stderr doesn't show it correctly.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably has to do with the sorting of the entries. Try to put the Option<Ty> first?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, no, because we strip standard library sources in UI tests.

estebank

Comment on lines +15 to +27

| 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 { | | | | +++++++++ | |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-errors

@estebank

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.

@estebank

@bors

📌 Commit f5bae72 has been approved by davidtwco

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Aug 21, 2024

bors added a commit to rust-lang-ci/rust that referenced this pull request

Aug 21, 2024

@bors

…iaskrgr

Rollup of 9 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request

Aug 21, 2024

@bors

…iaskrgr

Rollup of 9 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

jieyouxu added a commit to jieyouxu/rust that referenced this pull request

Aug 22, 2024

@jieyouxu

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.

bors added a commit to rust-lang-ci/rust that referenced this pull request

Aug 22, 2024

@bors

…iaskrgr

Rollup of 9 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Aug 22, 2024

@rust-timer

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.

Labels

S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.