Skip to content

Commit 9182b70

Browse files
authored
Rollup merge of rust-lang#62746 - RalfJung:deprecated, r=KodrAus
do not use assume_init in std::io Cc rust-lang#62397
2 parents eb1f631 + 7c1e405 commit 9182b70

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

src/libcore/fmt/float.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ fn float_to_decimal_common_exact<T>(fmt: &mut Formatter<'_>, num: &T,
1212
unsafe {
1313
let mut buf = MaybeUninit::<[u8; 1024]>::uninit(); // enough for f32 and f64
1414
let mut parts = MaybeUninit::<[flt2dec::Part<'_>; 4]>::uninit();
15-
// FIXME(#53491): Technically, this is calling `get_mut` on an uninitialized
16-
// `MaybeUninit` (here and elsewhere in this file). Revisit this once
15+
// FIXME(#53491): This is calling `get_mut` on an uninitialized
16+
// `MaybeUninit` (here and elsewhere in this file). Revisit this once
1717
// we decided whether that is valid or not.
18-
// Using `freeze` is *not enough*; `flt2dec::Part` is an enum!
18+
// We can do this only because we are libstd and coupled to the compiler.
19+
// (FWIW, using `freeze` would not be enough; `flt2dec::Part` is an enum!)
1920
let formatted = flt2dec::to_exact_fixed_str(flt2dec::strategy::grisu::format_exact,
2021
*num, sign, precision,
2122
false, buf.get_mut(), parts.get_mut());

src/libstd/io/util.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use crate::fmt;
44
use crate::io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoSlice, IoSliceMut};
5-
use crate::mem;
5+
use crate::mem::MaybeUninit;
66

77
/// Copies the entire contents of a reader into a writer.
88
///
@@ -43,27 +43,23 @@ use crate::mem;
4343
pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<u64>
4444
where R: Read, W: Write
4545
{
46-
let mut buf = unsafe {
47-
// This is still technically undefined behavior due to creating a reference
48-
// to uninitialized data, but within libstd we can rely on more guarantees
49-
// than if this code were in an external lib
50-
51-
// FIXME: This should probably be changed to an array of `MaybeUninit<u8>`
52-
// once the `mem::MaybeUninit` slice APIs stabilize
53-
let mut buf: mem::MaybeUninit<[u8; super::DEFAULT_BUF_SIZE]> = mem::MaybeUninit::uninit();
54-
reader.initializer().initialize(&mut *buf.as_mut_ptr());
55-
buf.assume_init()
56-
};
46+
let mut buf = MaybeUninit::<[u8; super::DEFAULT_BUF_SIZE]>::uninit();
47+
// FIXME(#53491): This is calling `get_mut` and `get_ref` on an uninitialized
48+
// `MaybeUninit`. Revisit this once we decided whether that is valid or not.
49+
// This is still technically undefined behavior due to creating a reference
50+
// to uninitialized data, but within libstd we can rely on more guarantees
51+
// than if this code were in an external lib.
52+
unsafe { reader.initializer().initialize(buf.get_mut()); }
5753

5854
let mut written = 0;
5955
loop {
60-
let len = match reader.read(&mut buf) {
56+
let len = match reader.read(unsafe { buf.get_mut() }) {
6157
Ok(0) => return Ok(written),
6258
Ok(len) => len,
6359
Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
6460
Err(e) => return Err(e),
6561
};
66-
writer.write_all(&buf[..len])?;
62+
writer.write_all(unsafe { &buf.get_ref()[..len] })?;
6763
written += len as u64;
6864
}
6965
}

src/libstd/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
// Don't link to std. We are std.
206206
#![no_std]
207207

208-
//#![warn(deprecated_in_future)] // FIXME: std still has quite a few uses of `mem::uninitialized`
208+
#![warn(deprecated_in_future)]
209209
#![warn(missing_docs)]
210210
#![warn(missing_debug_implementations)]
211211
#![deny(intra_doc_link_resolution_failure)] // rustdoc is run without -D warnings
@@ -272,6 +272,7 @@
272272
#![feature(libc)]
273273
#![feature(link_args)]
274274
#![feature(linkage)]
275+
#![feature(maybe_uninit_ref)]
275276
#![feature(mem_take)]
276277
#![feature(needs_panic_runtime)]
277278
#![feature(never_type)]

src/libstd/sync/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ pub use self::condvar::{Condvar, WaitTimeoutResult};
163163
#[stable(feature = "rust1", since = "1.0.0")]
164164
pub use self::mutex::{Mutex, MutexGuard};
165165
#[stable(feature = "rust1", since = "1.0.0")]
166+
#[cfg_attr(bootstrap, allow(deprecated_in_future))]
166167
#[allow(deprecated)]
167168
pub use self::once::{Once, OnceState, ONCE_INIT};
168169
#[stable(feature = "rust1", since = "1.0.0")]

src/libstd/sys/cloudabi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(deprecated)] // mem::uninitialized
1+
#![allow(deprecated_in_future)] // mem::uninitialized; becomes `deprecated` when nightly is 1.39
22

33
use crate::io::ErrorKind;
44
use crate::mem;

0 commit comments

Comments
 (0)