-
Notifications
You must be signed in to change notification settings - Fork 127
Improve IntoBytes derive error message #1713
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
Conversation
e38839b to
b42cfb6
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1713 +/- ##
=======================================
Coverage 88.79% 88.79%
=======================================
Files 16 16
Lines 5843 5846 +3
=======================================
+ Hits 5188 5191 +3
Misses 655 655 ☔ View full report in Codecov by Sentry. |
| #[inline(always)] | ||
| #[must_use] | ||
| #[allow(clippy::needless_maybe_sized)] | ||
| pub const fn size_of<T: Sized + ?core::marker::Sized>() -> usize { |
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 such a cursed bound.
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.
I just stumbled across this randomly: why is that bound there? Wouldn't any T automatically also be core::mem::Sized due to the trait bound of __size_of::Sized? Thanks!
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.
From a correctness perspective, you're right. However, without ?core::marker::Sized, when Rust encounters a type that is unsized that is passed to this size_of, it emits a Sized error first and bails, so it never gets to the point of discovering that the Sized bound (our bespoke Sized trait) isn't satisfied, and so it never emits our custom diagnostic. Adding ?core::marker::Sized "uncovers" our unsatisfied trait bound so that the desired diagnostic actually gets emitted.
It is, as all things in proc macro land, mildly cursed 😛
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.
@joshlf thanks for the explanation!
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.
np!
| --> tests/ui-nightly/struct.rs:129:8 | ||
| | | ||
| 129 | b: [u8], | ||
| | ^^^^ `IntoBytes` needs all field types to be `Sized` in order to determine whether there is inter-field padding |
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.
NICE!
Closes #1708