Uh oh!
There was an error while loading. Please reload this page.
Make custom trait object for Future generic - #51944
Conversation
This comment has been minimized.
This comment has been minimized.
ngg
commented
Jun 30, 2018
I get the following warnings for the Can't we simply remove that impl? |
@nikomatsakis Can you help? I'm not sure what to do. I can neither implement |
MajorBreakfast
commented
Jun 30, 2018
Crosslink #46205 |
MajorBreakfast
commented
Jun 30, 2018
I've removed the Into impls that I removed#[unstable(feature = "futures_api", issue = "50547")]impl<T,F:Future<Output = T> + Send + 'static>Into<FutureObj<T>>forPinBox<F>{fninto(self) -> FutureObj<T>{FutureObj::new(self)}}#[unstable(feature = "futures_api", issue = "50547")]impl<T,F:Future<Output = T> + Send + 'static>Into<FutureObj<T>>forBox<F>{fninto(self) -> FutureObj<T>{FutureObj::new(PinBox::from(self))}}#[unstable(feature = "futures_api", issue = "50547")]impl<T,F:Future<Output = T> + 'static>Into<LocalFutureObj<T>>forPinBox<F>{fninto(self) -> LocalFutureObj<T>{LocalFutureObj::new(self)}}#[unstable(feature = "futures_api", issue = "50547")]impl<T,F:Future<Output = T> + 'static>Into<LocalFutureObj<T>>forBox<F>{fninto(self) -> LocalFutureObj<T>{LocalFutureObj::new(PinBox::from(self))}} |
This comment has been minimized.
This comment has been minimized.
82a498c to
8343be4Compare
|
ngg
commented
Jun 30, 2018
I just tried to use it to create async trait methods (including capturing &self with the generic lifetime), it seems to work great. |
This comment has been minimized.
This comment has been minimized.
64372ed to
1cf9cfbCompareMajorBreakfast
commented
Jul 1, 2018
I've added an impl for @ngg Thats' great to hear! |
ngg
commented
Jul 1, 2018
Isn't it unsound for PinMut to implement UnsafeFutureObj? let pinbox = PinBox::new(/*...*/);let obj1 = FutureObj::new(pinbox.as_pin_mut());let obj2 = FutureObj::new(pinbox);drop(obj2);// this will drop the future
executor.spawn(obj1);// I think it's a use-after-freeOr does the life-time transfer from PinMut -> UnsafeFutureObj somehow solve this? |
ngg
commented
Jul 1, 2018
Actually it seems to work properly, it may be sound. |
559f304 to
a954f3bCompare
|
rust-highfive
commented
Jul 1, 2018
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
ngg
commented
Jul 1, 2018
For example |
6ba2a8a to
8123decCompare@ngg You're right.
|
MajorBreakfast
commented
Jul 1, 2018
@ngg Thanks BTW for all your testing :) |
bors
commented
Jul 1, 2018
☔ The latest upstream changes (presumably #51969) made this pull request unmergeable. Please resolve the merge conflicts. |
cramertj
commented
Jul 2, 2018
@mikeyhew What's the timeline on object-safe arbitrary-self-types? I'd really like to avoid these custom objects if we don't need them, but perhaps it's a necessary stopgap? That said, |
@MajorBreakfast Thanks as always for this PR!
Yeah, this is great! It's analogous to |
cramertj
commented
Jul 2, 2018
r=me with |
mikeyhew
commented
Jul 2, 2018
@cramertj they will probably be in nightly within the next month, but not sure when they will be stabilized |
cramertj
commented
Jul 2, 2018
@mikeyhew Cool! Thanks again for working on that. @MajorBreakfast I think with that timeline it's still best for us to push forward with this approach and then we can adjust as necessary-- we need both unsized rvalues and object-safe arbitrary self types before we can totally replace these faked-out trait objects. |
MajorBreakfast
commented
Jul 2, 2018
|
Great! @bors r+ p=1 (p=1 because I'd like to get breaking changes to the |
bors
commented
Jul 2, 2018
📌 Commit e666c2b has been approved by |
bors
commented
Jul 2, 2018
💡 This pull request was already approved, no need to approve it again.
|
bors
commented
Jul 2, 2018
📌 Commit e666c2b has been approved by |
ngg
commented
Jul 2, 2018
@cramertj Are you sure that |
@ngg I don't think it is accurate to say that the "struct does own |
ngg
commented
Jul 2, 2018
It will not drop |
@ngg |
@cramertj I'm not so sure... I think @ngg is right and we're violating this. I don't think that mentioning the type in the function pointer is enough. Here's what |
bors
commented
Jul 2, 2018
Make custom trait object for `Future` generic - `TaskObj` -> `FutureObj<'static, ()>` - The `impl From<...> for FutureObj<'a, T>` impls are impossible because of the type parameter `T`. The impl has to live in libstd, but `FutureObj<'a, T>` is from libcore. Therefore `Into<FutureObj<'a, T>>` was implemented instead. Edit: This didn‘t compile without warnings. I am now using non-generic Form impls. See rust-lang/futures-rs#1058 r? @cramertj Edit: Added lifetime
Yeah that's what I meant but it wouldn't matter to add |
@ngg Yeah, if you could spell |
bors
commented
Jul 2, 2018
☀️ Test successful - status-appveyor, status-travis |
TaskObj->FutureObj<'static, ()>impl From<...> for FutureObj<'a, T>impls are impossible because of the type parameterT. The impl has to live in libstd, butFutureObj<'a, T>is from libcore. ThereforeInto<FutureObj<'a, T>>was implemented instead. Edit: This didn‘t compile without warnings. I am now using non-generic Form impls.See rust-lang/futures-rs#1058
r? @cramertj
Edit: Added lifetime