-
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
Tracking issue for FnBox() #28796
Comments
The reason we don't want to stabilize Making |
So in the stable version of rust it's impossible to call |
@charlesetc
The key here is that |
Oh that makes more sense, thanks! |
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? |
Nominating for discussion in 1.6 |
cc me |
🔔 This issue is now entering its cycle-long final comment period 🔔 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! |
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. |
@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. |
It's clunky any way you spin it. |
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". |
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? |
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. |
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 |
@sinclairzx81 Filed #29946. |
@eefriedman Brilliant, thank you. |
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. |
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:
|
@nikomatsakis What's blocking |
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 |
@eddyb DST by value |
"DST by value" or its explicit / first-class formulation, |
@glaebhoerl they are different:
Now for making a realistic API |
@gnzlbg Where is this requirement for Alternatively, you could potentially have a wrapper that exposes only a constructor with an |
|
PR to add a deprecation warning: #61113. We can remove |
Deprecate `FnBox`. `Box<dyn FnOnce()>` can be called directly, since 1.35 FCP completion: rust-lang#28796 (comment)
Deprecate `FnBox`. `Box<dyn FnOnce()>` can be called directly, since 1.35 FCP completion: rust-lang#28796 (comment)
Deprecate `FnBox`. `Box<dyn FnOnce()>` can be called directly, since 1.35 FCP completion: rust-lang#28796 (comment)
Deprecate `FnBox`. `Box<dyn FnOnce()>` can be called directly, since 1.35 FCP completion: rust-lang#28796 (comment)
It allows for the challenge phase to accept closures that take some more context, e.g. moving non-Clone values in the challenge closure. This works in stable since Rust 1.35; cfr. rust-lang/rust#28796. This closes issue dalek-cryptography#244.
Remove `FnBox` Remove `FnBox` since we now have `Box<dyn FnOnce>`. Closes rust-lang#28796. r? @cramertj
Remove `FnBox` Remove `FnBox` since we now have `Box<dyn FnOnce>`. Closes rust-lang#28796. r? @cramertj
Remove `FnBox` Remove `FnBox` since we now have `Box<dyn FnOnce>`. Closes rust-lang#28796. r? @cramertj
Remove `FnBox` Remove `FnBox` since we now have `Box<dyn FnOnce>`. Closes rust-lang#28796. r? @cramertj
Remove `FnBox` Remove `FnBox` since we now have `Box<dyn FnOnce>`. Closes rust-lang#28796. r? @cramertj
Remove `FnBox` Remove `FnBox` since we now have `Box<dyn FnOnce>`. Closes rust-lang#28796. r? @cramertj
Since the MSRV of the crate has been updated, we can remove the workaround for rust-lang/rust#28796 and just use a Box<FnOnce> directly. Signed-off-by: Nick Stevens <nick@bitcurry.com>
Since the MSRV of the crate has been updated, we can remove the workaround for rust-lang/rust#28796 and just use a Box<FnOnce> directly. Signed-off-by: Nick Stevens <nick@bitcurry.com>
It allows for the challenge phase to accept closures that take some more context, e.g. moving non-Clone values in the challenge closure. This works in stable since Rust 1.35; cfr. rust-lang/rust#28796. This closes issue dalek-cryptography#244.
It allows for the challenge phase to accept closures that take some more context, e.g. moving non-Clone values in the challenge closure. This works in stable since Rust 1.35; cfr. rust-lang/rust#28796. This closes issue dalek-cryptography#244.
It allows for the challenge phase to accept closures that take some more context, e.g. moving non-Clone values in the challenge closure. This works in stable since Rust 1.35; cfr. rust-lang/rust#28796. This closes issue dalek-cryptography#244.
It allows for the challenge phase to accept closures that take some more context, e.g. moving non-Clone values in the challenge closure. This works in stable since Rust 1.35; cfr. rust-lang/rust#28796. This closes issue #244.
This is a tracking issue for the
fn_box
feature andFnBox
trait, 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.
The text was updated successfully, but these errors were encountered: