2 ms·
I haven't thought about it closely enough to know whether or not it's feasible to detect recursion in this specific case of dynamic dispatch (compilers are cert
by kibwen 4y ago
I haven't thought about it closely enough to know whether or not it's feasible to detect recursion in this specific case of dynamic dispatch (compilers are certainly capable of devirtualization, after all). However, any time you see a `dyn Foo` in Rust, any method called on it will be dynamically-dispatched (unless the aforementioned devirtualization optimization happens to kick in): https://doc.rust-lang.org/std/keyword.dyn.html https://doc.rust-lang.org/std/keyword.dyn.html
- loeg 4y agoWe are not calling a method on a `dyn Foo`. The type in the original example is statically known to be `KafkaWrapper`. The reduced example case isn't even a method -- it's just an ordinary function: fn do_something() -> Pin<Box<dyn Future<Output = ()>>> { Box::pin(async { do_something().await }) } (The infinite recursion happens before anything is ever returned --- the return type is irrelevant.)
- thethirdone 4y ago> (The infinite recursion happens before anything is ever returned --- the return type is irrelevant.) This is not true, the closure is not actually called until the future is awaited. Each instance of do_something does actually return.