diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-08-15 02:11:10 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-08-15 02:37:34 -0700 |
| commit | 107cd8e2678a3e3c5058f37e16ff998bbeda36f5 (patch) | |
| tree | bc8a7d3e3041ae56d64cc604fd5f31ad3b36b6de /library/core/src/num | |
| parent | a32978a5e8a3c34bb5caa1175f7404c2ede019b6 (diff) | |
| download | rust-107cd8e2678a3e3c5058f37e16ff998bbeda36f5.tar.gz rust-107cd8e2678a3e3c5058f37e16ff998bbeda36f5.zip | |
Add alignment to the NPO guarantee
As far as I know, this is always true already, but it's not in the text of the Option module docs, so I figured I'd bring this up to FCP it.
Diffstat (limited to 'library/core/src/num')
| -rw-r--r-- | library/core/src/num/nonzero.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index 5939dedbd1d..7f8d673c179 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -41,6 +41,20 @@ macro_rules! nonzero_integers { /// with the exception that `0` is not a valid instance. #[doc = concat!("`Option<", stringify!($Ty), ">` is guaranteed to be compatible with `", stringify!($Int), "`,")] /// including in FFI. + /// + /// Thanks to the [null pointer optimization], + #[doc = concat!("`", stringify!($Ty), "` and `Option<", stringify!($Ty), ">`")] + /// are guaranteed to have the same size and alignment: + /// + /// ``` + /// # use std::mem::{size_of, align_of}; + #[doc = concat!("use std::num::", stringify!($Ty), ";")] + /// + #[doc = concat!("assert_eq!(size_of::<", stringify!($Ty), ">(), size_of::<Option<", stringify!($Ty), ">>());")] + #[doc = concat!("assert_eq!(align_of::<", stringify!($Ty), ">(), align_of::<Option<", stringify!($Ty), ">>());")] + /// ``` + /// + /// [null pointer optimization]: crate::option#representation #[$stability] #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] #[repr(transparent)] |
