rust/library
Matthias Krüger 1df0c21af1
Rollup merge of #114845 - scottmcm:npo-align, r=WaffleLapkin
Add alignment to the NPO guarantee

This PR [changes](https://github.com/rust-lang/rust/pull/114845#discussion_r1294363357) "same size" to "same size and alignment" in the option module's null pointer optimization docs in <https://doc.rust-lang.org/std/option/#representation>.

As far as I know, this has been true for a long time in the actual rustc implementation, but it's not in the text of those docs, so I figured I'd bring this up to FCP it.

I also see no particular reason that we'd ever *want* to have higher alignment on these.  In many of the cases it's impossible, as the minimum alignment is already the size of the type, but even if we *could* do things like on 32-bit we could say that `NonZeroU64` is 4-align but `Option<NonZeroU64>` is 8-align, I just don't see any value in doing that, so feel completely fine closing this door for the few things on which the NPO is already guaranteed.  These are basically all primitives, and should end up with the same size & alignment as those primitives.

(There's no layout guarantee for something like `Option<[u8; 3]>`, where it'd be at least plausible to consider raising the alignment from 1 to 4 on, say, some hypothetical target that doesn't have efficient unaligned 4-byte load/stores.  And even if we ever did start to offer some kind of guarantee around such a type, I doubt we'd put it under the "null pointer" optimization header.)

Screenshots for the new examples:
![image](https://github.com/rust-lang/rust/assets/18526288/a7dbff42-50b4-462e-9e27-00d511b58763)
![image](https://github.com/rust-lang/rust/assets/18526288/dfd55288-80fb-419a-bc11-26198c27f9f9)
2023-09-02 07:48:21 +02:00
..
alloc Auto merge of #113859 - Manishearth:vec-as-mut-ptr-stacked-borrow, r=dtolnay 2023-08-29 06:04:55 +00:00
backtrace@99faef833f Bump backtrace to 0.3.69 2023-08-22 15:01:14 -07:00
core Rollup merge of #114845 - scottmcm:npo-align, r=WaffleLapkin 2023-09-02 07:48:21 +02:00
panic_abort Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
panic_unwind Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
portable-simd remove repetitive words 2023-07-31 16:13:02 +08:00
proc_macro Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
profiler_builtins Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
rtstartup
rustc-std-workspace-alloc
rustc-std-workspace-core
rustc-std-workspace-std
std Auto merge of #114448 - SteveLauC:std_fs_read_doc, r=Mark-Simulacrum 2023-09-01 05:25:44 +00:00
stdarch@d77878b729 Bump stdarch 2023-06-13 21:45:04 -07:00
sysroot Expose compiler-builtins-weak-intrinsics feature for -Zbuild-std 2023-06-23 11:15:34 +01:00
test Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
unwind Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00