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

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

Closed
joshlf opened this issue Feb 7, 2024 · 4 comments
Closed

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

joshlf opened this issue Feb 7, 2024 · 4 comments

Comments

@joshlf
Copy link
Member

joshlf commented Feb 7, 2024

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.

@joshlf joshlf mentioned this issue Feb 7, 2024
87 tasks
@jswrenn
Copy link
Collaborator

jswrenn commented Feb 7, 2024

This isn't a hygiene issue, since it doesn't relate to how our derive captures names. Rather, it relates to a limitation of Rust's priv-in-pub checker being lifted in 1.59 because of rust-lang/rust#90586.

Disabling the test on versions below 1.59 is a sensible — even shippable — solution. There's no soundness issue here, just an expressivity issue, and it's not unlike all of the other aspects in which new features getting added to Rust increases the expressivity of the zerocopy crate in other ways. (The only difference is that this expressivity gain doesn't require us to explicitly gate an API based on rustc version.)

@joshlf
Copy link
Member Author

joshlf commented Feb 7, 2024

Ack. I'll remove this as a 0.8 blocker.

@joshlf
Copy link
Member Author

joshlf commented Oct 6, 2024

@jswrenn Any opposition to closing this as not planned?

@jswrenn
Copy link
Collaborator

jswrenn commented Oct 6, 2024

No opposition.

@jswrenn jswrenn closed this as not planned Won't fix, can't repro, duplicate, stale Oct 6, 2024
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

No branches or pull requests

2 participants