-
Notifications
You must be signed in to change notification settings - Fork 108
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
Conversation
@@ -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"] } |
There was a problem hiding this comment.
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 ReportAll modified and coverable lines are covered by tests ✅
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. |
/// | ||
/// ```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 |
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed #1717 to track
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.
a0f7422
to
1600602
Compare
On Rust toolchains 1.78.0 or later, use
#[diagnostic::on_unimplemented]
to improve the error message emitted whenIntoBytes
is derived on a type with inter-field padding.