From 007d87f1719e2fcf2ff36aef8b6dc866fa276386 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Thu, 4 Jul 2019 11:24:56 -0400 Subject: [PATCH] Permit use of mem::uninitialized via allow(deprecated) --- src/librustc_codegen_llvm/common.rs | 1 + src/libstd/io/util.rs | 1 + src/libstd/sys/cloudabi/mod.rs | 2 ++ src/libstd/sys/sgx/mod.rs | 2 ++ src/libterm/win.rs | 1 + .../run-make-fulldeps/sanitizer-memory/uninit.rs | 1 + .../for-loop-while/for-loop-has-unit-body.rs | 1 + src/test/run-pass/issues/issue-58212.rs | 1 + src/test/run-pass/panic-uninitialized-zeroed.rs | 1 + src/test/run-pass/stack-probes.rs | 1 + .../enum-non-c-like-repr-c-and-int.rs | 1 + .../structs-enums/enum-non-c-like-repr-c.rs | 1 + .../structs-enums/enum-non-c-like-repr-int.rs | 1 + src/test/run-pass/uninit-empty-types.rs | 1 + src/test/rustdoc/issue-52873.rs | 1 + src/test/ui/const-generics/issue-61422.rs | 1 + src/test/ui/issues/issue-48131.rs | 1 + src/test/ui/issues/issue-48131.stderr | 4 ++-- .../uninhabited-matches-feature-gated.rs | 2 ++ .../uninhabited-matches-feature-gated.stderr | 14 +++++++------- 20 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/librustc_codegen_llvm/common.rs b/src/librustc_codegen_llvm/common.rs index f21f203fcc9..9fdc93c3ff0 100644 --- a/src/librustc_codegen_llvm/common.rs +++ b/src/librustc_codegen_llvm/common.rs @@ -170,6 +170,7 @@ impl CodegenCx<'ll, 'tcx> { pub fn const_get_real(&self, v: &'ll Value) -> Option<(f64, bool)> { unsafe { if self.is_const_real(v) { + #[allow(deprecated)] let mut loses_info: llvm::Bool = ::std::mem::uninitialized(); let r = llvm::LLVMConstRealGetDouble(v, &mut loses_info); let loses_info = if loses_info == 1 { true } else { false }; diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 7c4eae6512d..2bfd3e4ad20 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -44,6 +44,7 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< where R: Read, W: Write { let mut buf = unsafe { + #[allow(deprecated)] let mut buf: [u8; super::DEFAULT_BUF_SIZE] = mem::uninitialized(); reader.initializer().initialize(&mut buf); buf diff --git a/src/libstd/sys/cloudabi/mod.rs b/src/libstd/sys/cloudabi/mod.rs index c3b8bbd0426..3fef7552259 100644 --- a/src/libstd/sys/cloudabi/mod.rs +++ b/src/libstd/sys/cloudabi/mod.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] // mem::uninitialized + use crate::io::ErrorKind; use crate::mem; diff --git a/src/libstd/sys/sgx/mod.rs b/src/libstd/sys/sgx/mod.rs index 01f5536ed7a..3bf9ecf4080 100644 --- a/src/libstd/sys/sgx/mod.rs +++ b/src/libstd/sys/sgx/mod.rs @@ -3,6 +3,8 @@ //! This module contains the facade (aka platform-specific) implementations of //! OS level functionality for Fortanix SGX. +#![allow(deprecated)] + use crate::io::ErrorKind; use crate::os::raw::c_char; use crate::sync::atomic::{AtomicBool, Ordering}; diff --git a/src/libterm/win.rs b/src/libterm/win.rs index 6d42b01337e..14ea68d3788 100644 --- a/src/libterm/win.rs +++ b/src/libterm/win.rs @@ -108,6 +108,7 @@ impl WinConsole { let fg; let bg; unsafe { + #[allow(deprecated)] let mut buffer_info = ::std::mem::uninitialized(); if GetConsoleScreenBufferInfo(GetStdHandle(-11i32 as DWORD), &mut buffer_info) != 0 { fg = bits_to_color(buffer_info.wAttributes); diff --git a/src/test/run-make-fulldeps/sanitizer-memory/uninit.rs b/src/test/run-make-fulldeps/sanitizer-memory/uninit.rs index 163e2c5a462..cb857e3bc38 100644 --- a/src/test/run-make-fulldeps/sanitizer-memory/uninit.rs +++ b/src/test/run-make-fulldeps/sanitizer-memory/uninit.rs @@ -1,6 +1,7 @@ use std::mem; fn main() { + #[allow(deprecated)] let xs: [u8; 4] = unsafe { mem::uninitialized() }; let y = xs[0] + xs[1]; } diff --git a/src/test/run-pass/for-loop-while/for-loop-has-unit-body.rs b/src/test/run-pass/for-loop-while/for-loop-has-unit-body.rs index 009c59f2fa4..38c34d2dc2e 100644 --- a/src/test/run-pass/for-loop-while/for-loop-has-unit-body.rs +++ b/src/test/run-pass/for-loop-while/for-loop-has-unit-body.rs @@ -2,6 +2,7 @@ fn main() { // Check that the tail statement in the body unifies with something for _ in 0..3 { + #[allow(deprecated)] unsafe { std::mem::uninitialized() } } diff --git a/src/test/run-pass/issues/issue-58212.rs b/src/test/run-pass/issues/issue-58212.rs index 76437630309..d4ce6496cae 100644 --- a/src/test/run-pass/issues/issue-58212.rs +++ b/src/test/run-pass/issues/issue-58212.rs @@ -4,6 +4,7 @@ trait FromUnchecked { impl FromUnchecked for [u8; 1] { unsafe fn from_unchecked() { + #[allow(deprecated)] let mut array: Self = std::mem::uninitialized(); let _ptr = &mut array as *mut [u8] as *mut u8; } diff --git a/src/test/run-pass/panic-uninitialized-zeroed.rs b/src/test/run-pass/panic-uninitialized-zeroed.rs index 4ca4b407bd4..5026ad1ccd4 100644 --- a/src/test/run-pass/panic-uninitialized-zeroed.rs +++ b/src/test/run-pass/panic-uninitialized-zeroed.rs @@ -3,6 +3,7 @@ // in a runtime panic. #![feature(never_type)] +#![allow(deprecated)] use std::{mem, panic}; diff --git a/src/test/run-pass/stack-probes.rs b/src/test/run-pass/stack-probes.rs index 92a0cc3a07b..773d0ace90e 100644 --- a/src/test/run-pass/stack-probes.rs +++ b/src/test/run-pass/stack-probes.rs @@ -49,6 +49,7 @@ fn main() { #[allow(unconditional_recursion)] fn recurse(array: &[u64]) { unsafe { black_box(array.as_ptr() as u64); } + #[allow(deprecated)] let local: [_; 1024] = unsafe { mem::uninitialized() }; recurse(&local); } diff --git a/src/test/run-pass/structs-enums/enum-non-c-like-repr-c-and-int.rs b/src/test/run-pass/structs-enums/enum-non-c-like-repr-c-and-int.rs index c971f567d95..78d8e5e3a5d 100644 --- a/src/test/run-pass/structs-enums/enum-non-c-like-repr-c-and-int.rs +++ b/src/test/run-pass/structs-enums/enum-non-c-like-repr-c-and-int.rs @@ -69,6 +69,7 @@ fn main() { unsafe { // This should be safe, because we don't match on it unless it's fully formed, // and it doesn't have a destructor. + #[allow(deprecated)] let mut dest: MyEnum = mem::uninitialized(); while buf.len() > 0 { match parse_my_enum(&mut dest, &mut buf) { diff --git a/src/test/run-pass/structs-enums/enum-non-c-like-repr-c.rs b/src/test/run-pass/structs-enums/enum-non-c-like-repr-c.rs index 57ccf114509..1209533efda 100644 --- a/src/test/run-pass/structs-enums/enum-non-c-like-repr-c.rs +++ b/src/test/run-pass/structs-enums/enum-non-c-like-repr-c.rs @@ -69,6 +69,7 @@ fn main() { unsafe { // This should be safe, because we don't match on it unless it's fully formed, // and it doesn't have a destructor. + #[allow(deprecated)] let mut dest: MyEnum = mem::uninitialized(); while buf.len() > 0 { match parse_my_enum(&mut dest, &mut buf) { diff --git a/src/test/run-pass/structs-enums/enum-non-c-like-repr-int.rs b/src/test/run-pass/structs-enums/enum-non-c-like-repr-int.rs index d297c895da5..5dd9c1863d6 100644 --- a/src/test/run-pass/structs-enums/enum-non-c-like-repr-int.rs +++ b/src/test/run-pass/structs-enums/enum-non-c-like-repr-int.rs @@ -65,6 +65,7 @@ fn main() { unsafe { // This should be safe, because we don't match on it unless it's fully formed, // and it doesn't have a destructor. + #[allow(deprecated)] let mut dest: MyEnum = mem::uninitialized(); while buf.len() > 0 { match parse_my_enum(&mut dest, &mut buf) { diff --git a/src/test/run-pass/uninit-empty-types.rs b/src/test/run-pass/uninit-empty-types.rs index b59971b3498..4bc247a3dca 100644 --- a/src/test/run-pass/uninit-empty-types.rs +++ b/src/test/run-pass/uninit-empty-types.rs @@ -7,6 +7,7 @@ use std::mem; #[derive(Clone)] struct Foo; +#[allow(deprecated)] pub fn main() { unsafe { let _x: Foo = mem::uninitialized(); diff --git a/src/test/rustdoc/issue-52873.rs b/src/test/rustdoc/issue-52873.rs index 9138dd50def..653c004c04b 100644 --- a/src/test/rustdoc/issue-52873.rs +++ b/src/test/rustdoc/issue-52873.rs @@ -105,6 +105,7 @@ impl Add for UInt { impl Add for UTerm { type Output = U; fn add(self, _: U) -> Self::Output { + #[allow(deprecated)] unsafe { ::std::mem::uninitialized() } } } diff --git a/src/test/ui/const-generics/issue-61422.rs b/src/test/ui/const-generics/issue-61422.rs index 3ccf38e5619..68e5a52e0ac 100644 --- a/src/test/ui/const-generics/issue-61422.rs +++ b/src/test/ui/const-generics/issue-61422.rs @@ -7,6 +7,7 @@ use std::mem; fn foo() { let arr: [u8; SIZE] = unsafe { + #[allow(deprecated)] let mut array: [u8; SIZE] = mem::uninitialized(); array }; diff --git a/src/test/ui/issues/issue-48131.rs b/src/test/ui/issues/issue-48131.rs index b3cc350acf5..c8540729352 100644 --- a/src/test/ui/issues/issue-48131.rs +++ b/src/test/ui/issues/issue-48131.rs @@ -1,6 +1,7 @@ // This note is annotated because the purpose of the test // is to ensure that certain other notes are not generated. #![deny(unused_unsafe)] //~ NOTE +#![allow(deprecated)] // (test that no note is generated on this unsafe fn) pub unsafe fn a() { diff --git a/src/test/ui/issues/issue-48131.stderr b/src/test/ui/issues/issue-48131.stderr index adc36e266c2..6df065b9807 100644 --- a/src/test/ui/issues/issue-48131.stderr +++ b/src/test/ui/issues/issue-48131.stderr @@ -1,5 +1,5 @@ error: unnecessary `unsafe` block - --> $DIR/issue-48131.rs:8:9 + --> $DIR/issue-48131.rs:9:9 | LL | unsafe { /* unnecessary */ } | ^^^^^^ unnecessary `unsafe` block @@ -11,7 +11,7 @@ LL | #![deny(unused_unsafe)] | ^^^^^^^^^^^^^ error: unnecessary `unsafe` block - --> $DIR/issue-48131.rs:19:13 + --> $DIR/issue-48131.rs:20:13 | LL | unsafe { /* unnecessary */ } | ^^^^^^ unnecessary `unsafe` block diff --git a/src/test/ui/uninhabited/uninhabited-matches-feature-gated.rs b/src/test/ui/uninhabited/uninhabited-matches-feature-gated.rs index 38a52d5860d..a5360fa13c4 100644 --- a/src/test/ui/uninhabited/uninhabited-matches-feature-gated.rs +++ b/src/test/ui/uninhabited/uninhabited-matches-feature-gated.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + enum Void {} fn main() { diff --git a/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr b/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr index de7a9635770..25519ab2d6a 100644 --- a/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr +++ b/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr @@ -1,5 +1,5 @@ error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/uninhabited-matches-feature-gated.rs:5:19 + --> $DIR/uninhabited-matches-feature-gated.rs:7:19 | LL | let _ = match x { | ^ pattern `Err(_)` not covered @@ -7,7 +7,7 @@ LL | let _ = match x { = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0004]: non-exhaustive patterns: type `&Void` is non-empty - --> $DIR/uninhabited-matches-feature-gated.rs:10:19 + --> $DIR/uninhabited-matches-feature-gated.rs:12:19 | LL | let _ = match x {}; | ^ @@ -15,7 +15,7 @@ LL | let _ = match x {}; = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0004]: non-exhaustive patterns: type `(Void,)` is non-empty - --> $DIR/uninhabited-matches-feature-gated.rs:13:19 + --> $DIR/uninhabited-matches-feature-gated.rs:15:19 | LL | let _ = match x {}; | ^ @@ -23,7 +23,7 @@ LL | let _ = match x {}; = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0004]: non-exhaustive patterns: type `[Void; 1]` is non-empty - --> $DIR/uninhabited-matches-feature-gated.rs:16:19 + --> $DIR/uninhabited-matches-feature-gated.rs:18:19 | LL | let _ = match x {}; | ^ @@ -31,7 +31,7 @@ LL | let _ = match x {}; = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0004]: non-exhaustive patterns: `&[_]` not covered - --> $DIR/uninhabited-matches-feature-gated.rs:19:19 + --> $DIR/uninhabited-matches-feature-gated.rs:21:19 | LL | let _ = match x { | ^ pattern `&[_]` not covered @@ -39,7 +39,7 @@ LL | let _ = match x { = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/uninhabited-matches-feature-gated.rs:27:19 + --> $DIR/uninhabited-matches-feature-gated.rs:29:19 | LL | let _ = match x { | ^ pattern `Err(_)` not covered @@ -47,7 +47,7 @@ LL | let _ = match x { = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0005]: refutable pattern in local binding: `Err(_)` not covered - --> $DIR/uninhabited-matches-feature-gated.rs:32:9 + --> $DIR/uninhabited-matches-feature-gated.rs:34:9 | LL | let Ok(x) = x; | ^^^^^ pattern `Err(_)` not covered