File tree 1 file changed +5
-1
lines changed
1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -745,6 +745,9 @@ impl<T> Option<T> {
745
745
/// It's guaranteed to be a multiple of alignment (so will always give a
746
746
/// correctly-aligned location) and to be within the allocated object, so
747
747
/// is valid to use with `offset` and to use for a zero-sized read.
748
+ ///
749
+ /// FIXME: This is a horrible hack, but allows a nice optimization. It should
750
+ /// be replaced with `offset_of!` once that works on enum variants.
748
751
const SOME_BYTE_OFFSET_GUESS : isize = {
749
752
let some_uninit = Some ( mem:: MaybeUninit :: < T > :: uninit ( ) ) ;
750
753
let payload_ref = some_uninit. as_ref ( ) . unwrap ( ) ;
@@ -762,7 +765,8 @@ impl<T> Option<T> {
762
765
763
766
let max_offset = mem:: size_of :: < Self > ( ) - mem:: size_of :: < T > ( ) ;
764
767
if offset as usize <= max_offset {
765
- // The offset is at least inside the object, so let's try it.
768
+ // There's enough space after this offset for a `T` to exist without
769
+ // overflowing the bounds of the object, so let's try it.
766
770
offset
767
771
} else {
768
772
// The offset guess is definitely wrong, so use the address
You can’t perform that action at this time.
0 commit comments