Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for FnBox() #28796
Comments
alexcrichton
added
T-libs
B-unstable
labels
Oct 1, 2015
This comment has been minimized.
This comment has been minimized.
|
The reason we don't want to stabilize Making |
This comment has been minimized.
This comment has been minimized.
charlesetc
commented
Oct 2, 2015
|
So in the stable version of rust it's impossible to call |
This comment has been minimized.
This comment has been minimized.
|
@charlesetc
The key here is that |
This comment has been minimized.
This comment has been minimized.
charlesetc
commented
Oct 2, 2015
|
Oh that makes more sense, thanks! |
This comment has been minimized.
This comment has been minimized.
kosta
commented
Oct 2, 2015
|
I don't want to be pushy, but I think this is really a major missing piece in Rusts "Closures" story - and not really mentioned on in the rust book. I understand that you want to remove special-cases for Box in the compiler and I agree that that's a worthy goal. But when will that land? If we can have Box<FnOnce> right now for the price of "a bit more Box magic" until the no-special-case-for-Box story is complete, then is that maybe the right price to pay? |
This comment has been minimized.
This comment has been minimized.
|
Nominating for discussion in 1.6 |
alexcrichton
added
the
I-nominated
label
Nov 4, 2015
This comment has been minimized.
This comment has been minimized.
|
cc me |
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this and we have two possible routes for this right now:
We're a little undecided on which route to take, so some comments would be welcome! |
alexcrichton
added
final-comment-period
and removed
I-nominated
labels
Nov 5, 2015
This comment has been minimized.
This comment has been minimized.
|
I'd vote for the former. We have enough micro-crates in the ecosystem and this is a common enough pattern that it's worth supporting in the stdlib. Edit: I want to add that I do have a use for this. I need it for one-off callbacks in wingui. Right now I'm having to wrap I don't want to have to add another crate to my build because that seems like a very heavyweight solution just to get a trait or two. |
This comment has been minimized.
This comment has been minimized.
|
@cybergeek94 you can do a bit better than that with some boilerplate: https://github.com/sfackler/r2d2/blob/master/src/thunk.rs but it's a bit of a pain. |
This comment has been minimized.
This comment has been minimized.
|
It's clunky any way you spin it. |
This comment has been minimized.
This comment has been minimized.
|
Given that we all understand that FnBox is a will-inevitably-be-deprecated-hopefully-sooner-rather-than-later hack (albeit a useful one), I would like commitment from the Rust devs on some kind of timeframe for fixing the underlying issues before letting this be stabilized. Being able to say "this will be deprecated within the next year" is much more reassuring than "this will be deprecated, uhm, iunno, sometime". |
This comment has been minimized.
This comment has been minimized.
|
What's wrong with "this will be deprecated, uhm, iunno, sometime"? If we don't have a timeline for by-value trait objects, why would we not want to have this bridge? |
This comment has been minimized.
This comment has been minimized.
dlight
commented
Nov 8, 2015
Well, the "it lives on crates.io until it's stabilized" pattern has been applied to other cases, it's a stopgap solution that's cleaner than introducing something with the intent of deprecating it. |
This comment has been minimized.
This comment has been minimized.
sinclairzx81
commented
Nov 20, 2015
|
Hi, With the current implementation of FnBox, I note that drop() is not implicitly called for captured members at the end of a boxed closure, which may (or may not) be a unintended source of leaking memory if relying solely on Rust's move semantics. I have produced a gist to demonstrate what i believe to be going on. https://play.rust-lang.org/?gist=aa96e9e0fe78a09af2eb&version=nightly I am not sure of the future of FnBox, (certainly would love to see a full blown Thanks all |
eefriedman
referenced this issue
Nov 20, 2015
Closed
Missing drop in FnOnce adapter for closures #29946
This comment has been minimized.
This comment has been minimized.
|
@sinclairzx81 Filed #29946. |
This comment has been minimized.
This comment has been minimized.
sinclairzx81
commented
Nov 20, 2015
|
@eefriedman Brilliant, thank you. |
This comment has been minimized.
This comment has been minimized.
|
I think I would stabilize this, personally. My reasoning is:
Basically, our story here is not great, but I don't see any reason to make it worse, just to avoid a deprecated item in the standard library. |
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this during triage yesterday and the decision was to stabilize. @bluss brought up a good point, however, that impl<F: ?Sized, A> FnMut<A> for Box<F> where F: FnMut<A> {
...
}does not work. An impl of impl<F: ?Sized, A> FnOnce<A> for Box<F> where F: FnOnce<A> {
...
}Unfortunately this impl can't be written for two reasons:
|
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis What's blocking |
This comment has been minimized.
This comment has been minimized.
|
Ok, so I'm wary to stabilize #![crate_type = "lib"]
#![feature(fundamental)]
#[fundamental]
trait FnBox<A> {}
#[fundamental]
trait FnOnce<A> {}
struct Box<T: ?Sized>(T);
impl<A> FnOnce<A> for Box<FnBox<A>> {}
impl<F: FnOnce<A> + ?Sized, A> FnOnce<A> for Box<F> {}This represents basically the traits that are in play here, but doesn't worry about the unsized types by value problem. Currently this code yields a coherence violation:
Yet I would think that because of the For now I'm not going to stabilize |
This comment has been minimized.
This comment has been minimized.
|
@eddyb DST by value |
This comment has been minimized.
This comment has been minimized.
|
"DST by value" or its explicit / first-class formulation, |
This comment has been minimized.
This comment has been minimized.
|
@glaebhoerl they are different:
Now for making a realistic API |
rfcbot
added
final-comment-period
and removed
proposed-final-comment-period
labels
Nov 8, 2018
This comment has been minimized.
This comment has been minimized.
earthengine
commented
Nov 9, 2018
•
|
The same code I posted above compiles (and runs), but when you run the miri check it gives ICE in the playground.
Where should I report issue for the miri check? |
This comment has been minimized.
This comment has been minimized.
|
@earthengine Report it as a separate issue (referencing this one) on this repo. |
This comment has been minimized.
This comment has been minimized.
|
Perhaps somebody should add a test for that case before we FCP? |
This comment has been minimized.
This comment has been minimized.
|
I view FCP as an opportunity for anyone to object to a proposal, or to some details of it. At this point I believe there is strong consensus that we can and will make So, while it’d probably be premature to deprecate |
This comment has been minimized.
This comment has been minimized.
This seems confusing to me. It's already fully implemented, isn't it? |
This comment has been minimized.
This comment has been minimized.
|
I meant "implementation" as opposed to design decisions, so fixing bugs is part of it. |
This comment has been minimized.
This comment has been minimized.
|
Ah, sure, I'm only trying to point out that the only bug we're aware of relates to |
Centril
added
the
T-lang
label
Nov 14, 2018
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Nov 18, 2018
|
The final comment period, with a disposition to close, as per the review above, is now complete. |
rfcbot
added
finished-final-comment-period
and removed
final-comment-period
labels
Nov 18, 2018
scottlamb
added a commit
to scottlamb/moonfire-nvr
that referenced
this issue
Jan 5, 2019
bors
added a commit
that referenced
this issue
Feb 11, 2019
bors
added a commit
that referenced
this issue
Feb 12, 2019
bors
added a commit
that referenced
this issue
Feb 12, 2019
Aaron1011
referenced this issue
Mar 18, 2019
Closed
Add tokio::spawn_lazy and supporting methods #989
This comment has been minimized.
This comment has been minimized.
|
This issue (fixing fn foo(x: Box<dyn FnOnce()>) { x(); }errors with:
|
This comment has been minimized.
This comment has been minimized.
|
That is not a hard blocker. You can easily build a one-off trait to cover the boxed once closure use case. |
This comment has been minimized.
This comment has been minimized.
|
Do you have an example or is that documented somewhere? This is the closest thing I know (playground): trait MyFnBox {
fn call_box(self: Box<Self>) -> ();
}
impl<T> MyFnBox for T where T: FnOnce() -> () {
fn call_box(self: Box<Self>) -> () {
(*self)()
}
}
fn foo(b: Box<dyn FnOnce()>) {
b.call_box()
}But it doesn't work ( |
This comment has been minimized.
This comment has been minimized.
|
Does this API specifically require taking exactly the type |
This comment has been minimized.
This comment has been minimized.
|
@sfackler I haven't spent too much time trying to use |
This comment has been minimized.
This comment has been minimized.
|
@sfackler so I performed a lot of refactorings since I tried that, and I just tried it again, and it all worked with minimal changes - sorry for the noise =/ |
This comment has been minimized.
This comment has been minimized.
earthengine
commented
Mar 20, 2019
This comment has been minimized.
This comment has been minimized.
|
Really wish #55431 can be revived and pushed forward. |
This comment has been minimized.
This comment has been minimized.
|
@gnzlbg Where is this requirement for Alternatively, you could potentially have a wrapper that exposes only a constructor with an |
abonander commentedOct 1, 2015
This is a tracking issue for the
fn_boxfeature andFnBoxtrait, which allows aBox<FnOnce(...) -> _>closure to be invoked via the"rust-call"sugar.I'm not sure what the primary concerns are. All I know is it'd be really, really nice if we could invoke a
Box<FnOnce()>somehow in safe Rust. This may or may not be the best approach.@eddyb feel free to CC anyone who might want to comment or edit this issue to add any pertinent information.