File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Expand file tree Collapse file tree 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> {
745745 /// It's guaranteed to be a multiple of alignment (so will always give a
746746 /// correctly-aligned location) and to be within the allocated object, so
747747 /// 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.
748751 const SOME_BYTE_OFFSET_GUESS : isize = {
749752 let some_uninit = Some ( mem:: MaybeUninit :: < T > :: uninit ( ) ) ;
750753 let payload_ref = some_uninit. as_ref ( ) . unwrap ( ) ;
@@ -762,7 +765,8 @@ impl<T> Option<T> {
762765
763766 let max_offset = mem:: size_of :: < Self > ( ) - mem:: size_of :: < T > ( ) ;
764767 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.
766770 offset
767771 } else {
768772 // The offset guess is definitely wrong, so use the address
You can’t perform that action at this time.
0 commit comments