rust/compiler/rustc_middle/src
bors 20997f6ad8 Auto merge of #83698 - erikdesjardins:undefconst, r=RalfJung,oli-obk
Use undef for uninitialized bytes in constants

Fixes #83657

This generates good code when the const is fully uninit, e.g.

```rust
#[no_mangle]
pub const fn fully_uninit() -> MaybeUninit<[u8; 10]> {
    const M: MaybeUninit<[u8; 10]> = MaybeUninit::uninit();
    M
}
```
generates
```asm
fully_uninit:
	ret
```

as you would expect.

There is no improvement, however, when it's partially uninit, e.g.

```rust
pub struct PartiallyUninit {
    x: u64,
    y: MaybeUninit<[u8; 10]>
}

#[no_mangle]
pub const fn partially_uninit() -> PartiallyUninit {
    const X: PartiallyUninit = PartiallyUninit { x: 0xdeadbeefcafe, y: MaybeUninit::uninit() };
    X
}
```
generates
```asm
partially_uninit:
	mov	rax, rdi
	mov	rcx, qword ptr [rip + .L__unnamed_1+16]
	mov	qword ptr [rdi + 16], rcx
	movups	xmm0, xmmword ptr [rip + .L__unnamed_1]
	movups	xmmword ptr [rdi], xmm0
	ret

.L__unnamed_1:
	.asciz	"\376\312\357\276\255\336\000"
	.zero	16
	.size	.L__unnamed_1, 24
```
which copies a bunch of zeros in place of the undef bytes, the same as before this change.

Edit: generating partially-undef constants isn't viable at the moment anyways due to #84565, so it's disabled
2021-08-26 10:49:25 +00:00
..
dep_graph Update DepNode's size 2021-07-10 21:46:31 +08:00
hir Fix typos “a”→“an” 2021-08-22 15:35:11 +02:00
ich rename assert_matches module 2021-07-16 09:18:14 -07:00
infer
middle Auto merge of #87739 - Aaron1011:remove-used-attrs, r=wesleywiser 2021-08-24 03:58:22 +00:00
mir Auto merge of #83698 - erikdesjardins:undefconst, r=RalfJung,oli-obk 2021-08-26 10:49:25 +00:00
query Fix typos “an”→“a” and a few different ones that appeared in the same search 2021-08-22 18:15:49 +02:00
traits Fix typos “a”→“an” 2021-08-22 15:35:11 +02:00
ty Auto merge of #88066 - LeSeulArtichaut:patterns-cleanups, r=nagisa 2021-08-26 05:23:35 +00:00
util
arena.rs
lib.rs Use if-let guards in the codebase 2021-08-25 20:24:35 +02:00
lint.rs Rename force-warns to force-warn 2021-07-21 15:41:10 +02:00
macros.rs
tests.rs
thir.rs Various pattern cleanups 2021-08-25 20:24:39 +02:00