rust/library/core/src
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 Rollup merge of #107916 - reez12g:issue-107040, r=Amanieu 2023-05-30 12:57:38 +02:00
array Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
ascii Rename copying ascii::Char methods from as_ to to_ 2023-08-08 16:03:47 -07:00
async_iter use consistent terminology 2022-10-29 09:23:12 +02:00
cell Rollup merge of #109318 - joboet:better_fmt_placeholder, r=dtolnay 2023-07-31 22:51:12 +02:00
char impl TryFrom<char> for u16 2023-07-25 19:58:00 +02:00
cmp Merge two different equality specialization traits in core 2023-03-01 14:42:06 -08:00
convert use the correct link 2023-08-25 15:45:41 +08:00
ffi Inline strlen_rt in CStr::from_ptr 2023-08-18 09:19:09 +02:00
fmt Rollup merge of #109318 - joboet:better_fmt_placeholder, r=dtolnay 2023-07-31 22:51:12 +02:00
future Rollup merge of #109970 - danielhenrymantilla:add-poll-fn-pin-clarifications, r=thomcc 2023-06-19 19:26:25 +02:00
hash Swap out CURRENT_RUSTC_VERSION to 1.71.0 2023-05-30 07:54:29 -04:00
intrinsics Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
iter Implement Step for AsciiChar 2023-08-14 01:34:47 -04:00
macros improve panic.md edition disucssion, and nits 2023-08-28 12:11:19 +02:00
mem Auto merge of #113365 - dima74:diralik/add-deprecated-suggestions, r=workingjubilee 2023-08-22 00:02:50 +00:00
net Remove special cases that are no longer needed due to #112606 2023-08-25 03:54:28 +02:00
num Rollup merge of #114845 - scottmcm:npo-align, r=WaffleLapkin 2023-09-02 07:48:21 +02:00
ops Go into more detail about panicking in drop. 2023-08-18 07:48:10 -07:00
panic avoid triple-backtrace due to panic-during-cleanup 2023-08-27 20:02:46 +02:00
prelude Revert "Remove #[alloc_error_handler] from the compiler and library" 2023-04-25 00:08:35 +02:00
ptr Rollup merge of #114845 - scottmcm:npo-align, r=WaffleLapkin 2023-09-02 07:48:21 +02:00
slice Add a new compare_bytes intrinsic instead of calling memcmp directly 2023-08-06 15:47:40 -07:00
str Replace version placeholders with 1.73.0 2023-08-22 06:57:00 -04:00
sync Auto merge of #114034 - Amanieu:riscv-atomicbool, r=thomcc 2023-07-27 01:00:12 +00:00
task Auto merge of #96875 - SabrinaJewson:noop-waker, r=m-ou-se 2023-06-07 06:04:32 +00:00
unicode Apply changes to fix python linting errors 2023-06-16 20:56:01 -04:00
any.rs core/any: remove Provider trait 2023-08-13 13:07:53 -06:00
arch.rs move core::arch into separate file 2022-11-20 10:28:14 +01:00
ascii.rs ascii::Char-ify the escaping code 2023-05-12 19:37:02 -07:00
asserting.rs [RFC 2011] Library code 2022-05-22 07:18:32 -03:00
bool.rs core is now compilable 2023-04-16 07:20:26 +00:00
borrow.rs doc: replace wrong punctuation mark 2023-07-28 14:46:17 +02:00
cell.rs Auto merge of #114795 - RalfJung:cell-swap, r=dtolnay 2023-08-29 07:53:56 +00:00
clone.rs Explain more clearly why fn() -> T can't be #[derive(Clone)] 2023-07-30 18:04:38 +02:00
cmp.rs Optimized implementations of max, min, and clamp for bool 2023-08-10 22:38:30 -07:00
default.rs Remove default_free_fn feature 2023-07-08 12:10:12 +09:00
error.md Change default panic handler message format. 2023-07-29 11:42:50 +02:00
error.rs add missing feature(error_in_core) 2023-08-15 08:21:41 +02:00
escape.rs Rename copying ascii::Char methods from as_ to to_ 2023-08-08 16:03:47 -07:00
hint.rs Rollup merge of #108416 - pat-nel87:Issue-107957-black_box_docs, r=jyn514 2023-04-26 01:55:49 -05:00
internal_macros.rs rm const traits in libcore 2023-04-16 06:49:27 +00:00
intrinsics.rs Auto merge of #114795 - RalfJung:cell-swap, r=dtolnay 2023-08-29 07:53:56 +00:00
lib.rs Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
marker.rs Revert "Suggest using Arc on !Send/!Sync types" 2023-08-28 03:16:48 -07:00
option.rs Add alignment to the NPO guarantee 2023-08-15 02:37:34 -07:00
panic.rs Shorten lifetime of even more panic temporaries 2023-05-15 03:47:37 -07:00
panicking.rs avoid triple-backtrace due to panic-during-cleanup 2023-08-27 20:02:46 +02:00
pin.rs Document Pin memory layout 2023-05-18 01:30:12 -04:00
primitive.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
primitive_docs.rs resolve conflicts 2023-08-18 15:22:58 +08:00
result.rs Rollup merge of #112655 - WaffleLapkin:must_use_map_or, r=workingjubilee 2023-07-30 14:25:08 +02:00
time.rs Fix implementation of Duration::checked_div 2023-07-30 04:00:02 -04:00
tuple.rs Flip cfg's for bootstrap bump 2023-07-12 21:38:55 -04:00
unit.rs Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00