Impl Trait in return position in struct versus trait lifetime capturing

It is by design, but not due to compiler limitations. The difference is more an artifact of langauge development history. In edition 2024, the non-trait method will act like the trait method. async fn also acts like trait methods today.

Here's an RFC where you can read more about RPIT capturing. And here's an in-progress RFC that will allow inline tuning of the capturing. My guess is that will be the first "complete" workaround to hit stable.

Another workaround is to define and associated type or GAT that captures less. The "define it to be impl Display" part of the playground is still unstable too, but if you're ok giving up the flexibility,[1] you can use concrete types on stable in this case (since the type is nameable).

The non-trait analogue to using an associated type or GAT will be TAIT. (Playground.)

(These unstable TAIT/GAT workarounds were intended to be the workaround, but probably aren't going to land soon enough and/or be ergonomic enough for the changes to RPIT capturing; hence RFC 3617.)


  1. changing an associated type is a breaking change ↩︎

2 Likes