Skip to content

pin-project does not interoperate well with #[cfg()] #68

Closed
@jonhoo

Description

@jonhoo

Take this struct for instance:

#[pin_project]
#[derive(Debug)]
pub struct Socket {
    #[cfg_attr(unix, pin)]
    #[cfg(unix)]
    inner: tokio::net::unix::UnixStream,
    #[cfg_attr(windows, pin)]
    #[cfg(windows)]
    inner: tokio_named_pipes::NamedPipe,
}

I get the error

error[E0124]: field `inner` is already declared
  --> src/io/socket.rs:29:5
   |
26 |     inner: tokio::net::unix::UnixStream,
   |     ----------------------------------- `inner` first declared here
...
29 |     inner: tokio_named_pipes::NamedPipe,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field already declared

Even though, as far as I can tell, this should work. My guess here is that pin-project is run before the #[cfg()]s are evaluated, and ends up not propagating them, but I'm not sure?

Metadata

Metadata

Assignees

Labels

A-pin-projectionArea: #[pin_project]C-bugCategory: related to a bug.C-enhancementCategory: A new feature or an improvement for an existing one

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions