-
Notifications
You must be signed in to change notification settings - Fork 653
Make BoxFuture and LocalBoxFuture a concrete type with #[must_use] #1691
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
e5d5b07
to
de0f9d6
Compare
Currently BoxFuture is type alias for Pin<Box<...>>, that leads to accidental mistakes, when user does not call await/poll on result of function that returns BoxFuture. We had multiple problems with that Some notes on PR: * I understand that for some projects this might be breaking change - if someone have hardcoded Pin<Box<...>> as a type of variable returned by .boxed, they would have to change it BoxedFuture once this diff lands, but I believe this is reasonable trade off. * I am not sure what to do with Debug implementation for BoxFuture - ok to just suppress warning for this type? * I don't fully understand what UnsafeFutureObj is, I mostly copied implementation from Pin<Box<...>>, but please take a look at it carefully to make sure I did not miss something.
de0f9d6
to
4e0d99b
Compare
This seems like a big limitation in the |
Note that this is Pin<Box<..>>, not just Box<...> |
So my feeling that rust-lang/rust#62262 could take a while (and might not even happen, some people voice concerns about propagating must_use through structs). What are your thoughts on merging this diff to solve the problem of unused boxed futures? I think pretty much all other future wrappers (AndThen, etc) already are concrete types, is there reason not to convert BoxFuture? |
@Nemo157 what do you think? Would it make sense to merge this? |
I'm on the fence with this, it makes sense if we're not going to have I think one thing that would help is to add impl<'a, T: Future + 'a> BoxFuture<'a, T> {
pub fn pin(x: T) -> Self {
Self::new(Box::pin(x))
}
} that way code that is currently Box::pin(async move { ... }) can transition to BoxFuture::pin(async { ... }) (using @cramertj you've probably got a better idea how badly moving this to a concrete type would affect large codebases. |
I'm unsure about this. It does seem unfortunate that |
@cramertj for my education - why type alias is more preferred then concrete type, e.g. why would we want to shift back to alias? |
Primarily that it's a simpler mental model for users-- it's more transparent, and easy to see that it's "just" a boxed trait object rather than something special. |
Even if this PR is merged, considering that must_use does not work with |
I agree with @taiki-e. I'm going to go ahead and close this PR-- I don't think this is something we want to do.Thanks for the PR, though-- I appreciate you calling attention to this. |
Currently BoxFuture is type alias for Pin<Box<...>>, so it can not have
#[must_wait]
. That leads to accidental mistakes, when user does not call await/poll on result of function that returns BoxFuture. We had multiple problems with thatSome notes on PR:
I understand that for some projects this might be breaking change - if someone have hardcoded Pin<Box<...>> as a type of variable returned by .boxed, they would have to change it BoxedFuture once this diff lands, but I believe this is reasonable trade off.
I am not sure what to do with Debug implementation for BoxFuture - ok to just suppress warning for this type?
I don't fully understand what UnsafeFutureObj is, I mostly copied implementation from Pin<Box<...>>, but please take a look at it carefully to make sure I did not miss something.