-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Boxed recursive function should not require trait object #73625
Comments
|
@jonas-schievink This seems distinct from that issue, which has to do (I think) with liveness analysis. This is rather separate: the object's liveness is computed properly, the problem is that we do not allow the future to be a recursively defined type without erasure. The future in the example should be the moral equivalent of an enum with |
Ah, yeah, I think you're right. This error is emitted by the code that checks for cycles in opaque |
I faced the same issue and the error is a bit miss-leading. I had two types calling each other with distinct instances. |
@rustbot labels +I-types-nominated +T-types @rust-lang/wg-async discussed this issue and felt it was desirable to support if feasible. However, the hard questions here relate to the type system, so we are nominating this for T-types for its thoughts and tracking. |
This can be supported by removing the https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/util/struct.OpaqueTypeExpander.html#method.expand_coroutine check. However, any PR should also add necessary tests and make sure that directly recursive coroutines have good error messages. some discussions in https://rust-lang.zulipchat.com/#narrow/stream/326866-t-types.2Fnominated/topic/.2373625.3A.20Boxed.20recursive.20function.20should.20not.20require.20trait.20o.E2.80.A6 and https://rust-lang.zulipchat.com/#narrow/stream/326132-t-types.2Fmeetings/topic/2023-11-06.20planning.20meeting/near/400556344 |
this has been implemented in #117703. Closing |
The following code works (playground):
but if the trait object is removed, and the construction of
recursed
is changed to:then Rust rejects the program:
The future is boxed either way, so the use of a trait object shouldn't be required. In a thread on the internals forum, @withoutboats said:
Now there is!
The text was updated successfully, but these errors were encountered: