Hacker News new | past | comments | ask | show | jobs | submit login

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



We 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.)


> (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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: