Skip to content

Commit

Permalink
Permit use of mem::uninitialized via allow(deprecated)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Jul 5, 2019
1 parent 8a7dded commit 007d87f
Show file tree
Hide file tree
Showing 20 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/librustc_codegen_llvm/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
1 change: 1 addition & 0 deletions src/libstd/io/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub fn copy<R: ?Sized, W: ?Sized>(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
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/sys/cloudabi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(deprecated)] // mem::uninitialized

use crate::io::ErrorKind;
use crate::mem;

Expand Down
2 changes: 2 additions & 0 deletions src/libstd/sys/sgx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
1 change: 1 addition & 0 deletions src/libterm/win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ impl<T: Write + Send + 'static> WinConsole<T> {
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);
Expand Down
1 change: 1 addition & 0 deletions src/test/run-make-fulldeps/sanitizer-memory/uninit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::mem;

fn main() {
#[allow(deprecated)]
let xs: [u8; 4] = unsafe { mem::uninitialized() };
let y = xs[0] + xs[1];
}
1 change: 1 addition & 0 deletions src/test/run-pass/for-loop-while/for-loop-has-unit-body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
}

Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/issues/issue-58212.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/panic-uninitialized-zeroed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// in a runtime panic.

#![feature(never_type)]
#![allow(deprecated)]

use std::{mem, panic};

Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/stack-probes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/structs-enums/enum-non-c-like-repr-c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/uninit-empty-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::mem;
#[derive(Clone)]
struct Foo;

#[allow(deprecated)]
pub fn main() {
unsafe {
let _x: Foo = mem::uninitialized();
Expand Down
1 change: 1 addition & 0 deletions src/test/rustdoc/issue-52873.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl<U: Unsigned, B: Bit> Add<B0> for UInt<U, B> {
impl<U: Unsigned> Add<U> for UTerm {
type Output = U;
fn add(self, _: U) -> Self::Output {
#[allow(deprecated)]
unsafe { ::std::mem::uninitialized() }
}
}
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/const-generics/issue-61422.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::mem;

fn foo<const SIZE: usize>() {
let arr: [u8; SIZE] = unsafe {
#[allow(deprecated)]
let mut array: [u8; SIZE] = mem::uninitialized();
array
};
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-48131.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-48131.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/uninhabited/uninhabited-matches-feature-gated.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(deprecated)]

enum Void {}

fn main() {
Expand Down
14 changes: 7 additions & 7 deletions src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
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
|
= 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 {};
| ^
|
= 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 {};
| ^
|
= 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 {};
| ^
|
= 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
|
= 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
|
= 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
Expand Down

0 comments on commit 007d87f

Please sign in to comment.