Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,18 @@
//! }
//! ```
//!
//! This usage of [`Option`] to create safe nullable pointers is so
//! common that Rust does special optimizations to make the
//! representation of [`Option`]`<`[`Box<T>`]`>` a single pointer. Optional pointers
//! in Rust are stored as efficiently as any other pointer type.
//! # Representation
//!
//! Rust guarantees to optimise the following inner types such that an [`Option`] which contains
//! them has the same size as a pointer:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! Rust guarantees to optimise the following inner types such that an [`Option`] which contains
//! them has the same size as a pointer:
//! Rust guarantees to optimize the following types `T` such that an [`Option<T>`]
//! has the same size as a `T`:

Giving names to things helps. :) And we typically use US spelling, AFAIK.

Also maybe say that this means that one may transmute a T to an Option<T>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Fixed in f5118a5.

//!
//! * `&T`
//! * `&mut T`
//! * `extern "C" fn`
//! * [`num::NonZero*`]
//! * [`ptr::NonNull<T>`]
//! * `#[repr(transparent)]` struct around one of the types in this list.
//! * [`Box<T>`]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of ordering I think it makes more sense to add this to the top or just below the references.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Fixed in f5118a5.

//!
//! # Examples
//!
Expand Down