I tried to see the difference with godbolt. It seems that the assembly for all of those function is going to be the same (exactly as I was expecting). But using
impl Trait will create a different implementation for every instantiation, so more code bloat.
I absolutely understand why one would like to use
fn foo(t: impl Trait) since having a different monomorphisation for each type may lead to better runtime performance. But when using references, especially const references, is it useful? I would expect that all indices would be fixed anyway. And if not, could the compiler only generate the
&dyn version instead of the
&impl? Maybe with
impl, the reference can be a thin pointer, while it need to be a fat pointer for