diff options
author | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-03-11 15:32:54 -0800 |
---|---|---|
committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-03-11 17:44:43 -0800 |
commit | b2c717fa338dd3e917008484c4bf55886041f743 (patch) | |
tree | c8c203c011ef038f7a2ddeb0a9c09b760a9def4d /compiler/rustc_lint_defs | |
parent | 19c53768af6e48514238e4224b5bf5ecd51bc7b1 (diff) | |
download | rust-b2c717fa338dd3e917008484c4bf55886041f743.tar.gz |
`MaybeUninit::assume_init_read` should have `noundef` load metadata
I was looking into `array::IntoIter` optimization, and noticed that it wasn't annotating the loads with `noundef` for simple things like `array::IntoIter<i32, N>`.
Turned out to be a more general problem as `MaybeUninit::assume_init_read` isn't marking the load as initialized (<https://rust.godbolt.org/z/Mxd8TPTnv>), which is unfortunate since that's basically its reason to exist.
This PR lowers `ptr::read(p)` to `copy *p` in MIR, which fortuitiously also improves the IR we give to LLVM for things like `mem::replace`.
Diffstat (limited to 'compiler/rustc_lint_defs')
-rw-r--r-- | compiler/rustc_lint_defs/src/builtin.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 46ec1a2dca1..91966e75b5f 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -1026,12 +1026,13 @@ declare_lint! { /// ### Example /// /// ```rust,compile_fail - /// #![feature(const_ptr_read)] + /// #![feature(const_mut_refs)] /// const FOO: () = unsafe { /// let x = &[0_u8; 4]; /// let y = x.as_ptr().cast::<u32>(); - /// y.read(); // the address of a `u8` array is unknown and thus we don't know if - /// // it is aligned enough for reading a `u32`. + /// let mut z = 123; + /// y.copy_to_nonoverlapping(&mut z, 1); // the address of a `u8` array is unknown + /// // and thus we don't know if it is aligned enough for copying a `u32`. /// }; /// ``` /// |