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.
This is such a cursed bound.
There was a problem hiding this comment.
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.
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 😛
| --> 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 |
Closes #1708