Additional lifetime bounds in trait impl

PressRex profile image
by PressRex
Additional lifetime bounds in trait impl

I would like to understand a confusing situation I ran into with some complex associated data types. In this code (playground), the compiler complains that certain types may not live long enough, and helpfully suggests adding lifetime bounds to the function. The problem is that it's a function in a trait impl, so my first thought was that the suggestion is maybe not that helpful after all. But then I tried it out anyway, and to my surprise the compiler accepted it.

So my questions are:

  • Why am I allowed to add lifetime bounds to this trait impl fn that do not appear in the trait -- in contrast to simpler situations, where the compiler rejects it?
  • In case the answer is that the compiler figures out that the lifetime requirements are automatically satisfied, why do I have to add them manually?
  • If this is indeed the intended compiler behavior, could some additional info be added to the suggestion? Maybe a link to some documentation on additional lifetime constraints in impls.

Thanks.

Source: View source

PressRex profile image
by PressRex

Subscribe to New Posts

Lorem ultrices malesuada sapien amet pulvinar quis. Feugiat etiam ullamcorper pharetra vitae nibh enim vel.

Success! Now Check Your Email

To complete Subscribe, click the confirmation link in your inbox. If it doesn’t arrive within 3 minutes, check your spam folder.

Ok, Thanks

Read More