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

Allow ?Sized types in some methods and structs #1647

Merged
merged 1 commit into from
Jun 10, 2019

Conversation

taiki-e
Copy link
Member

@taiki-e taiki-e commented Jun 3, 2019

No description provided.

@@ -9,13 +9,13 @@ use std::sync::Mutex as StdMutex;
use std::sync::atomic::{AtomicUsize, Ordering};

/// A futures-aware mutex.
pub struct Mutex<T> {
pub struct Mutex<T: ?Sized> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we want to reveal that this is allocated separately-- I had imagined at some point we might want to switch to using e.g. parking_lot's Mutex type which prevents an allocation here. I don't feel super strongly about it, though, since futures-util should be okay to make breaking changes to in the future. Your choice :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cramertj
I'm sorry, I'm not sure what is the problem.

  • In this pr's implementation, if T is !Sized, then Mutex itself becomes !Sized.
    use futures::lock::Mutex;
    use std::sync::Arc;
    fn foo() -> Arc<Foo<dyn Fn()>> {
        let m = Foo::new(|| {});
        Arc::new(m) as Arc<_>
    }
    fn bar() -> Foo<dyn Fn()> { //~ ERROR the size for values of type `(dyn std::ops::Fn() + 'static)` cannot be known at compilation time
        let m = Foo::new(|| {});
        m as _
    }
  • parking_lot's Mutex allows T: ?Sized, and if T is !Sized, the behavior is the same as this pr's implementation: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=a4ecc3eecc9fa5cdce41bebd5f97cf5e.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see-- I was thinking that the Mutex here was still Sized even if T: ?Sized.

@cramertj
Copy link
Member

cramertj commented Jun 7, 2019

Nice! One question re Mutex but otherwise the rest of the changes LGTM.

@cramertj cramertj merged commit 6408473 into rust-lang:master Jun 10, 2019
@taiki-e taiki-e deleted the unsize branch June 11, 2019 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants