-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
New AsyncFn*
traits being #[fundamental]
might come with significant forward-compatibility issues
#136723
Comments
Yeah there's no reason for them to need to be fundamental; it's not like we need it for coherence in core today. Probably just an oversight from when I initially mirrored the |
There's no reason to prioritize this issue tho. @rustbot label -I-prioritize |
That’s alright if there’s no need for it. I thought a future-compatibility issue on beta is a bit like a regression on beta 🤷🏻 |
Is it? At least for types, adding ... but I don't know if there's a similar risk for traits. |
For traits it's backwards-compatible to add fundamental, since it means something completely different. For types, it means that we ignore the outermost "type constructor" for the orphan check (e.g. we allow you to impl non-local traits for |
Does that reasoning hold for the type |
Only ADTs (struct/enum/union) can be fundamental (for types). |
If it were possible for users to define their own types in stable rust that implements the For example, consider the following scenario (assuming that users can implement
I can't figure out a way for this scenario to happen with the current feature set of stable rust though... |
Of course, the issues of meta-semver-breakage… those are always easy to miss. I guess, it’s a good thing you can’t (stably) implement |
…r=compiler-errors Make `AsyncFnOnce`, `AsyncFnMut`, `AsyncFn` non-`#[fundamental]` Address the issue rust-lang#136723 on nightly (the issue will only *actually* be fixed with a beta backport).
…r=compiler-errors Make `AsyncFnOnce`, `AsyncFnMut`, `AsyncFn` non-`#[fundamental]` Address the issue rust-lang#136723 on nightly (the issue will only *actually* be fixed with a beta backport).
…r=compiler-errors Make `AsyncFnOnce`, `AsyncFnMut`, `AsyncFn` non-`#[fundamental]` Address the issue rust-lang#136723 on nightly (the issue will only *actually* be fixed with a beta backport).
Rollup merge of rust-lang#136724 - steffahn:asyncfn-non-fundamental, r=compiler-errors Make `AsyncFnOnce`, `AsyncFnMut`, `AsyncFn` non-`#[fundamental]` Address the issue rust-lang#136723 on nightly (the issue will only *actually* be fixed with a beta backport).
backport landed today 🚀 #136980 |
As far as I understand the current design of
AsyncFn*
traits allows them to become somewhat of a “sugar” for a more generalized approach in the future. Quoting from the RFC:In particular, the case for
AsyncFnOnce
seems pretty clear. It’s a future possibility (which is IMO very desirable) thatAsyncFnOnce(Args…) -> R
might be automatically implemented for any implementor ofFnOnce(Args…) -> F
that returns someF: Future<Output = R>
; either by turning it into a sort of “alias” (in a way that avoids the shortcomings mentioned in the RFC) or by finding a way to re-structure the blanket impls.In particular, IMO it’s a very relevant future possibility that
Box<dyn FnOnce(Args…) -> Pin<Box<dyn Future<Output = R> [+ Send] [+Sync]>>
could become an implementor ofAsyncFnOnce(Args…) -> R
in the future.But
#[fundamental]
kills this possibility, as the following code compiles successfully, powered by the negative reasoning that#[fundamental]
provides:(playground)
I was unable to find any prior discussion about the value of why these traits (
AsyncFn
,AsyncFnMut
,AsyncFnOnce
) are marked#[fundamental]
in the first place. I can imagine it’s perhaps by analogy toFn
,FnMut
,FnOnce
being marked as such. But this decision is an important trade-off that should be considered.As far as I can tell, there should be no issue in simply removing the
#[fundamental]
markers fromAsyncFn
,AsyncFnMut
,AsyncFnOnce
before they’re stabilized in1.85
. Testing this locally,std
still compiles find, and UI tests pass.It should always be backwards-compatible to add back the
#[fundamental]
marker later.cc @compiler-errors
@rustbot label T-compiler, T-libs-api, F-async_closure, C-discussion
The text was updated successfully, but these errors were encountered: