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

[derive] Test with trivial_bounds feature #515

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

joshlf
Copy link
Member

@joshlf joshlf commented Oct 16, 2023

DO NOT MERGE: We need to debug this issue.

The nightly trivial_bounds causes some derive-emitted code to compile which is designed to fail compilation. This commit adds a test that ensures that the emitted code still triggers some compiler errors.

Affects #61

Closes #500

@joshlf joshlf marked this pull request as draft October 16, 2023 23:53
The nightly `trivial_bounds` causes some derive-emitted code to compile
which is designed to fail compilation. This commit adds a test that
ensures that the emitted code is still sound even with `trivial_bounds`
enabled.

Affects #61

Closes #500
@stegaBOB
Copy link

stegaBOB commented Oct 7, 2024

Hey @joshlf. We rely on static assertions in some of our crates and were considering enabling trivial_bounds as well and ended up stumbling upon this through the RFC issue. In our testing, we couldn't actually get invalid assert_impl_alls to compile. I tried with a few separate Rust versions, and from what I can tell it looks like the order the errors were emitted in the nightly this repo happened to use was unexpected. After satisfying the FromZeros requirement, the assert_impl_all error gets displayed:

error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied
  --> zerocopy-derive/tests/trivial_bounds.rs:60:18
   |
60 | assert_impl_all!(FromBytes1: FromBytes);
   |                  ^^^^^^^^^^ the trait `FromBytes` is not implemented for `NotZerocopy`
   |
   = help: the following other types implement trait `FromBytes`:
             isize
             i8
             i16
             i32
             i64
             i128
             usize
             u8
           and 38 others
note: required for `FromBytes1` to implement `FromBytes`
  --> zerocopy-derive/tests/trivial_bounds.rs:55:10
   |
55 | #[derive(FromBytes, FromZeroes)]
   |          ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::{closure#0}::assert_impl_all`
  --> zerocopy-derive/tests/trivial_bounds.rs:60:1
   |
60 | assert_impl_all!(FromBytes1: FromBytes);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all`
   = note: this error originates in the derive macro `FromBytes` which comes from the expansion of the macro `assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)

Amusingly, in the nightly 5 days later (2023-10-26 instead of 2023-10-21), all the errors are shown as expected. Presumably some change fixed the error ordering or something.

Is the zerocopy crate still interested in adding trivial_bounds?

@joshlf
Copy link
Member Author

joshlf commented Oct 10, 2024

Huh fascinating! I'll have to resurrect this PR and try again.

Yes, we're still interested in trivial_bounds: specifically to support #1769.

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.

Confirm that #![feature(trivial_bounds)] doesn't permit bypassing derive-emitted trait bounds
2 participants