-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Custom closure (and trait) "kind" bounds #3569
Comments
I don't see why ~fn closures should be required to be const, though it is likely a good default. I have to write up the fn type proposal we discussed ... I believe it covers this use case just fine. Niko (Sent from a cramped, unreliable keyboard)null |
Oh, I mean they should be able to satisfy const requirements. Even if they have mutable data structures in their environment I think the closures themselves should still be const. Only if you can somehow change the interior of the environment, such as with @mut/&mut, should they be non-const. (I guess you can put those in fn~s just fine.) Currently the problem is you cannot put them in ARCs at all. |
I agree it should be possible. A closure is const if it closes over const things... this seems... straightforward enough, and akin to any of the other possible bounds on a closure's environment. |
At a minimum. Don't you think that a closure should be const even if it closes over (owns) a mutable thing? |
No, that would certainly not be safe to put in an ARC. |
oh, I see. I guess I was assuming calling a closure always makes a copy of the environment. |
(To be more explicit: because, if it is const, it could potentially be called many times in parallel, and if it mutates that closed over state, that would induce data races) |
I'm closing this, reopen if you have a problem with that :-) |
Unless the constness inference has changed since, I think there's still something to be done here. Functions that don't close over mutable data should be const, so send_map can be put into ARCs. |
Nominating for maturity milestone 1, well-defined. |
Repurposing this issue to be the issue that represents the needs to allow closures to have custom bounds. |
accepted for well-defined milestone |
I think we should have these on traits, too. It would be nice to be able to store heterogeneous existentials inside of an ARC. |
Yes this is the plan. |
This is pretty much done, except for clone, which would be harder. Opening a separate issue for that. |
As a heads up, not sure if this comment was ever resolved. |
Use structopt for command line arguments parsing in cargo-fmt
housekeeping: update dependencies This also pulls in the new rustc-build-sysroot that hides all the unexpected_cfgs noise.
Needed to make
send_map
properly dual-mode.The way I see it,
~fn()
s should always already be Const.&fn()
and@fn()
could perhaps be non-const if they had&mut
s or@mut
s in their environment.Can we check for this and support putting closures in arcs?
EDIT: Per @bstrie's request, here is a list of what how the kinds work. For each kind bound
K
, a closure or trait bounded likefn:K()
orTraitName:K
can capture any values as long as their types do not contain the following ("mq" means any mutability qualifier):The text was updated successfully, but these errors were encountered: