diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-03-12 16:30:51 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-03-12 16:30:51 -0700 |
| commit | e97505704e2043df46c99c3cbd0dd1ce3938c123 (patch) | |
| tree | 4ee5ffc04f93e174b029666bc1f0be9ee272d8de | |
| parent | f6a57c195519d1e3e1f2f84b5793b2449f6c1625 (diff) | |
| download | rust-e97505704e2043df46c99c3cbd0dd1ce3938c123.tar.gz rust-e97505704e2043df46c99c3cbd0dd1ce3938c123.zip | |
Clarify the text of some comments
| -rw-r--r-- | library/core/src/option.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/library/core/src/option.rs b/library/core/src/option.rs index c480b6ca4af..0f2475a8bde 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -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(); @@ -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 |
