Skip to content
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

Closed
bblum opened this issue Sep 24, 2012 · 17 comments
Closed

Custom closure (and trait) "kind" bounds #3569

bblum opened this issue Sep 24, 2012 · 17 comments
Labels
A-typesystem Area: The type system C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@bblum
Copy link
Contributor

bblum commented Sep 24, 2012

Needed to make send_mapproperly 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 &muts or @muts 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 like fn:K() or TraitName:K can capture any values as long as their types do not contain the following ("mq" means any mutability qualifier):

Copy        anything with a destructor, e.g. pipes, ARCs, fn:()/Trait: without Copy
'static     &'r mq T, where 'r != 'static, fn:()/Trait: without 'static
Const       &mut T, @mut T, &const T, RWARC, Cell, RcMut, fn:()/Trait: without Const
Owned       &mq T, @mq T, Rc, RcMut, fn:()/Trait: without Owned
@nikomatsakis
Copy link
Contributor

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

@bblum
Copy link
Contributor Author

bblum commented Sep 24, 2012

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.

@nikomatsakis
Copy link
Contributor

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.

@bblum
Copy link
Contributor Author

bblum commented Sep 24, 2012

At a minimum. Don't you think that a closure should be const even if it closes over (owns) a mutable thing?

@nikomatsakis
Copy link
Contributor

No, that would certainly not be safe to put in an ARC.

@bblum
Copy link
Contributor Author

bblum commented Sep 24, 2012

oh, I see. I guess I was assuming calling a closure always makes a copy of the environment.

@nikomatsakis
Copy link
Contributor

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

@catamorphism
Copy link
Contributor

I'm closing this, reopen if you have a problem with that :-)

@bblum
Copy link
Contributor Author

bblum commented Dec 28, 2012

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.

@bblum bblum reopened this Dec 28, 2012
@catamorphism
Copy link
Contributor

Nominating for maturity milestone 1, well-defined.

@graydon
Copy link
Contributor

graydon commented May 9, 2013

sub-bug of #2202 or #6308

@nikomatsakis
Copy link
Contributor

Repurposing this issue to be the issue that represents the needs to allow closures to have custom bounds.

@graydon
Copy link
Contributor

graydon commented May 9, 2013

accepted for well-defined milestone

@bblum
Copy link
Contributor Author

bblum commented Jun 8, 2013

I think we should have these on traits, too. It would be nice to be able to store heterogeneous existentials inside of an ARC.

@nikomatsakis
Copy link
Contributor

Yes this is the plan.

@bblum
Copy link
Contributor Author

bblum commented Jul 16, 2013

This is pretty much done, except for clone, which would be harder. Opening a separate issue for that.

@bblum bblum closed this as completed Jul 16, 2013
@nickdesaulniers
Copy link

As a heads up, not sure if this comment was ever resolved.

@bblum bblum removed their assignment Jun 16, 2014
bors pushed a commit to rust-lang-ci/rust that referenced this issue May 15, 2021
Use structopt for command line arguments parsing in cargo-fmt
RalfJung pushed a commit to RalfJung/rust that referenced this issue May 5, 2024
housekeeping: update dependencies

This also pulls in the new rustc-build-sysroot that hides all the unexpected_cfgs noise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

5 participants