Skip to content

“type must outlive the static lifetime” makes no sense #41816

Open
@nagisa

Description

@nagisa

For the following code

pub trait Arbitrary: Sized + 'static {}

impl<'a, A: Clone> Arbitrary for ::std::borrow::Cow<'a, A> {}

The diagnostic looks like this:

error[E0477]: the type `std::borrow::Cow<'a, A>` does not fulfill the required lifetime
 --> <anon>:3:20
  |
3 | impl<'a, A: Clone> Arbitrary for ::std::borrow::Cow<'a, A> {}
  |                    ^^^^^^^^^
  |
  = note: type must outlive the static lifetime

The note here makes no sense, because the static lifetime is the longest lifetime of all and cannot really be outlived. We should reword the note so it doesn’t say “outlive”.

Bonus points for explaining where the lifetime requirement comes from, because it is not entirely clear what here introduces the requirement, when the trait and implementation definitions aren’t so close together.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions