Skip to content

Fix zerocopy-derive hygiene on Rust 1.58 and below #847

Closed as not planned
Closed as not planned
@joshlf

Description

@joshlf

Running ./cargo.sh +msrv test --package zerocopy-derive -- --skip ui with our MSRV set to 1.58 results in the following test failure:

error[E0446]: private type `Private` in public interface
  --> zerocopy-derive/tests/priv_in_pub.rs:18:10
   |
18 | #[derive(KnownLayout, IntoBytes, FromZeros, FromBytes, Unaligned)]
   |          ^^^^^^^^^^^ can't leak private type
...
24 | struct Private(());
   | ------------------- `Private` declared as private
   |
   = note: this error originates in the derive macro `KnownLayout` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0446]: private type `Private` in public interface
  --> zerocopy-derive/tests/priv_in_pub.rs:18:23
   |
18 | #[derive(KnownLayout, IntoBytes, FromZeros, FromBytes, Unaligned)]
   |                       ^^^^^^^^^ can't leak private type
...
24 | struct Private(());
   | ------------------- `Private` declared as private
   |
   = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0446]: private type `Private` in public interface
  --> zerocopy-derive/tests/priv_in_pub.rs:18:34
   |
18 | #[derive(KnownLayout, IntoBytes, FromZeros, FromBytes, Unaligned)]
   |                                  ^^^^^^^^^ can't leak private type
...
24 | struct Private(());
   | ------------------- `Private` declared as private
   |
   = note: this error originates in the derive macro `FromZeros` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0446]: private type `Private` in public interface
  --> zerocopy-derive/tests/priv_in_pub.rs:18:45
   |
18 | #[derive(KnownLayout, IntoBytes, FromZeros, FromBytes, Unaligned)]
   |                                             ^^^^^^^^^ can't leak private type
...
24 | struct Private(());
   | ------------------- `Private` declared as private
   |
   = note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0446]: private type `Private` in public interface
  --> zerocopy-derive/tests/priv_in_pub.rs:18:56
   |
18 | #[derive(KnownLayout, IntoBytes, FromZeros, FromBytes, Unaligned)]
   |                                                        ^^^^^^^^^ can't leak private type
...
24 | struct Private(());
   | ------------------- `Private` declared as private
   |
   = note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0446`.

For the time being, we've disabled this test on versions 1.58 and earlier. This isn't a regression because our published crates do not currently support 1.58. That said, we should fix this if possible before releasing 0.8.

So far, I have found the following possible culprits:

In particular this documentation suggests that the quote! macro itself may not be the problem:

Any interpolated tokens preserve the Span information provided by their ToTokens implementation. Tokens that originate within the quote! invocation are spanned with Span::call_site().

A different span can be provided through the quote_spanned! macro.

I have not yet tried to replace all quote! invocations with quote_spanned! (passing Span::call_site()). That's the first thing to try. Next would be to consider whether an existing token passed to quote! is carrying its own span information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions