Skip to content

Allow #[pin_project(!Unpin)] to impl !Unpin #344

@ssbr

Description

@ssbr

Suppose I have the following trait definition:

trait Trait {}
impl<T: Unpin> Trait for T {}

And I use it from another crate. Then this will not have overlapping impls:

struct Struct;
impl !Unpin for Struct {}
impl Trait for Struct {}

... because Rust understands that this doesn't overlap with the blanket impl in the trait definition. But this will not work:

struct Struct2(std::marker::PhantomPinned);
impl Trait for Struct {}

Nor will any other trick that isn't a straight up impl !Unpin.

Right now, if you use pin_project with a struct, you cannot impl !Unpin for that struct, which means that struct cannot implement Trait if it does not fall under the blanket impl. Would you accept a PR adding some way to impl !Unpin? For example, something like:

// creates an `impl !Unpin`, instead of an impl Unpin conditional on the impossible
#[pin_project(!Unpin=negative_impls)]
struct Struct { ... }

( In particular, I want this for https://github.com/google/crubit/blob/main/rs_bindings_from_cc/support/ctor.rs )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions