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] Improve IntoBytes error messages #1712

Merged
merged 1 commit into from
Sep 21, 2024
Merged

Conversation

joshlf
Copy link
Member

@joshlf joshlf commented Sep 20, 2024

On Rust toolchains 1.78.0 or later, use
#[diagnostic::on_unimplemented] to improve the error message emitted when IntoBytes is derived on a type with inter-field padding.

@@ -28,7 +28,7 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0.1"
quote = "1.0.10"
syn = "2.0.46"
syn = { version = "2.0.46", features = ["full"] }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djkoloski Do you have a sense of how we could implement using the same trick that you pulled to avoid the full feature?

I tested locally on a MacBook Pro on low battery mode, and found that the full feature increased zerocopy-derive cargo build time from 8.9s to 13.3s. That's a large percentage, but a small absolute difference. So I'm not opposed to just sticking with this impl, but it'd be cool if we could avoid it.

@codecov-commenter
Copy link

codecov-commenter commented Sep 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.79%. Comparing base (553996e) to head (1600602).
Report is 140 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1712   +/-   ##
=======================================
  Coverage   88.79%   88.79%           
=======================================
  Files          16       16           
  Lines        5846     5846           
=======================================
  Hits         5191     5191           
  Misses        655      655           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

///
/// ```text
/// error[E0277]: the trait bound `HasPadding<Foo, true>: ShouldBe<false>` is not satisfied
/// error[E0277]: the trait bound `(): PaddingFree<Foo, true>` is not satisfied
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fallback is arguably an improvement over the previous error!

--> tests/ui-nightly/enum.rs:533:10
|
533 | #[derive(IntoBytes)]
| ^^^^^^^^^ the trait `ShouldBe<false>` is not implemented for `HasPadding<IntoBytes1, true>`
| ^^^^^^^^^ types with padding cannot implement `IntoBytes`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ridiculously good. I wonder if we could even say how many bytes of inter-field padding there with const generics, but that's just yak shaving.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #1717 to track

@joshlf joshlf added this pull request to the merge queue Sep 21, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 21, 2024
On Rust toolchains 1.78.0 or later, use
`#[diagnostic::on_unimplemented]` to improve the error message emitted
when `IntoBytes` is derived on a type with inter-field padding.
@joshlf joshlf force-pushed the into-bytes-padding-ergonomics branch from a0f7422 to 1600602 Compare September 21, 2024 17:18
@joshlf joshlf enabled auto-merge September 21, 2024 17:18
@joshlf joshlf added this pull request to the merge queue Sep 21, 2024
Merged via the queue into main with commit 63b5e78 Sep 21, 2024
86 checks passed
@joshlf joshlf deleted the into-bytes-padding-ergonomics branch September 21, 2024 17:57
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.

3 participants