Remove last use of mem::uninitialized from std::io::util#62732
Remove last use of mem::uninitialized from std::io::util#62732bors merged 1 commit intorust-lang:masterfrom
Conversation
|
r? @dtolnay (rust_highfive has picked a reviewer for you, use r? to override) |
|
Adding another reviewer, since this PR involves unsafe code. r? @Amanieu |
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
658876a to
e6b1cb2
Compare
|
My impression is that the proper way of dealing with uninitialized arrays is to make the element let mut buf: [mem::MaybeUninit<u8>; super::DEFAULT_BUF_SIZE] = [mem::MaybeUninit::uninit(); super::DEFAULT_BUF_SIZE];
let slice = slice::from_raw_parts_mut(MaybeUninit::first_ptr_mut(&mut buf), super::DEFAULT_BUF_SIZE);
reader.initializer().initialize(slice);Not that it really matters in this case since we're creating a reference to slice of uninitialized data... |
That was my first inclination as well, but it looks making a slice from a MaybeUninit is an unstable library feature, and I think a handful of other methods would have to change in order for it to type check with that approach. If you think it's worth it, I can definitely go that route though |
|
It's probably not worth the trouble in this case. The slice APIs for |
src/libstd/io/util.rs
Outdated
There was a problem hiding this comment.
Maybe add a FIXME here as a reminder?
There was a problem hiding this comment.
Sounds reasonable to me, I'll add that in
e6b1cb2 to
04f0d30
Compare
|
@bors r+ |
|
📌 Commit 04f0d30 has been approved by |
Remove last use of mem::uninitialized from std::io::util Addresses rust-lang#62397 for std::io::util
Rollup of 15 pull requests Successful merges: - #61926 (Fix hyperlinks in From impls between Vec and VecDeque) - #62615 ( Only error about MSVC + PGO + unwind if we're generating code) - #62696 (Check that trait is exported or public before adding hint) - #62712 (Update the help message on error for self type) - #62728 (Fix repeated wording in slice documentation) - #62730 (Consolidate hygiene tests) - #62732 (Remove last use of mem::uninitialized from std::io::util) - #62740 (Add missing link to Infallible in TryFrom doc) - #62745 (update data_layout and features for armv7-wrs-vxworks) - #62749 (Document link_section arbitrary bytes) - #62752 (Disable Z3 in LLVM build) - #62764 (normalize use of backticks in compiler messages for librustc/lint) - #62774 (Disable simd_select_bitmask test on big endian) - #62777 (Self-referencial type now called a recursive type) - #62778 (Emit artifact notifications for dependency files) Failed merges: - #62746 ( do not use mem::uninitialized in std::io) r? @ghost
|
Looks like we collided mid-air here.^^ |
|
But i think we can do slightly better than what this PR does, by not ever having uninitialized by-value integers. So I am going to propose we still merge my PR. |
| buf | ||
| // This is still technically undefined behavior due to creating a reference | ||
| // to uninitialized data, but within libstd we can rely on more guarantees | ||
| // than if this code were in an external lib |
There was a problem hiding this comment.
This doesn't just create a reference to uninitialized data (so the comment is not entirely correct). It actually creates (in the final assume_init) uninitialized (integer) values (not behind a reference).
Addresses #62397 for std::io::util