“type must outlive the static lifetime” makes no sense

3757e73
Opened by Simonas Kazlauskas at 2024-06-26 22:27:19

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.

  1. I'll fix the simple version.

    PS: and try to do the big part later on.

    Guillaume Gomez at 2017-05-09 17:24:36

  2. In addition to everything, the span is pretty bad. The type which must satisfy any of the lifetimes here is the implementor, not the trait.

    Simonas Kazlauskas at 2017-05-09 20:37:11

  3. Triage; this now says

      = note: but lifetime parameter must outlive the static lifetime
    

    So, not fixed yet!

    Steve Klabnik at 2020-03-28 19:46:58

  4. Still makes not much sense in 2022.

    Squirrel at 2022-11-26 12:28:04

  5. Still makes not much sense in 2023

    Liangsheng Yin at 2023-07-19 13:58:08

  6. Still makes not much sense in 2024

    Lane Rettig at 2024-06-26 22:27:19