Skip to content

Commit

Permalink
Clarify the text of some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmcm committed Mar 12, 2023
1 parent f6a57c1 commit e975057
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,9 @@ impl<T> Option<T> {
/// It's guaranteed to be a multiple of alignment (so will always give a
/// correctly-aligned location) and to be within the allocated object, so
/// is valid to use with `offset` and to use for a zero-sized read.
///
/// FIXME: This is a horrible hack, but allows a nice optimization. It should
/// be replaced with `offset_of!` once that works on enum variants.
const SOME_BYTE_OFFSET_GUESS: isize = {
let some_uninit = Some(mem::MaybeUninit::<T>::uninit());
let payload_ref = some_uninit.as_ref().unwrap();
Expand All @@ -762,7 +765,8 @@ impl<T> Option<T> {

let max_offset = mem::size_of::<Self>() - mem::size_of::<T>();
if offset as usize <= max_offset {
// The offset is at least inside the object, so let's try it.
// There's enough space after this offset for a `T` to exist without
// overflowing the bounds of the object, so let's try it.
offset
} else {
// The offset guess is definitely wrong, so use the address
Expand Down

0 comments on commit e975057

Please sign in to comment.