-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Closed
Labels
Description
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
&'staticwhen called via the object and lifetime&'awhen 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.
Reactions are currently unavailable