See StackOverflow question.
Summary: the compiler accepts a trait impl function returning a &'static str when the trait requires only &'a str, 'a being the life of the object, but then assumes the lifetime of the returned value is only &'a str despite direct call (not via trait).
Possible solutions I see:
- Do not demote the lifetime of a function when called via the object (not the trait), but keep both versions of the function (i.e. lifetime
&'static when called via the object and lifetime &'a when called via the trait). This is likely confusing, so (2) may be better.
- Make it an error to implement a trait function with too long a lifetime.
See StackOverflow question.
Summary: the compiler accepts a trait impl function returning a
&'static strwhen the trait requires only&'a str,'abeing the life of the object, but then assumes the lifetime of the returned value is only&'a strdespite direct call (not via trait).Possible solutions I see:
&'staticwhen called via the object and lifetime&'awhen called via the trait). This is likely confusing, so (2) may be better.