2019-08-06 21:11:52 +00:00
|
|
|
// ignore-tidy-linelength
|
|
|
|
// This test checks that calling `mem::{uninitialized,zeroed}` with certain types results
|
|
|
|
// in a lint.
|
|
|
|
|
|
|
|
#![feature(never_type)]
|
|
|
|
#![allow(deprecated)]
|
|
|
|
#![deny(invalid_value)]
|
|
|
|
|
2019-08-07 06:42:50 +00:00
|
|
|
use std::mem::{self, MaybeUninit};
|
|
|
|
|
|
|
|
enum Void {}
|
|
|
|
|
|
|
|
struct Ref(&'static i32);
|
2019-08-12 07:24:13 +00:00
|
|
|
struct RefPair((&'static i32, i32));
|
2019-08-07 06:42:50 +00:00
|
|
|
|
|
|
|
struct Wrap<T> { wrapped: T }
|
2019-08-12 07:24:13 +00:00
|
|
|
enum WrapEnum<T> { Wrapped(T) }
|
2019-08-07 06:42:50 +00:00
|
|
|
|
|
|
|
#[allow(unused)]
|
|
|
|
fn generic<T: 'static>() {
|
|
|
|
unsafe {
|
|
|
|
let _val: &'static T = mem::zeroed(); //~ ERROR: does not permit zero-initialization
|
|
|
|
let _val: &'static T = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
|
|
|
|
|
|
|
|
let _val: Wrap<&'static T> = mem::zeroed(); //~ ERROR: does not permit zero-initialization
|
|
|
|
let _val: Wrap<&'static T> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
|
|
|
|
}
|
|
|
|
}
|
2019-08-06 21:11:52 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
unsafe {
|
|
|
|
let _val: ! = mem::zeroed(); //~ ERROR: does not permit zero-initialization
|
|
|
|
let _val: ! = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
|
|
|
|
|
2019-08-07 06:42:50 +00:00
|
|
|
let _val: (i32, !) = mem::zeroed(); //~ ERROR: does not permit zero-initialization
|
|
|
|
let _val: (i32, !) = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
|
|
|
|
|
|
|
|
let _val: Void = mem::zeroed(); //~ ERROR: does not permit zero-initialization
|
|
|
|
let _val: Void = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
|
|
|
|
|
2019-08-06 21:11:52 +00:00
|
|
|
let _val: &'static i32 = mem::zeroed(); //~ ERROR: does not permit zero-initialization
|
|
|
|
let _val: &'static i32 = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
|
|
|
|
|
2019-08-07 06:42:50 +00:00
|
|
|
let _val: Ref = mem::zeroed(); //~ ERROR: does not permit zero-initialization
|
|
|
|
let _val: Ref = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
|
|
|
|
|
2019-08-06 21:11:52 +00:00
|
|
|
let _val: fn() = mem::zeroed(); //~ ERROR: does not permit zero-initialization
|
|
|
|
let _val: fn() = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
|
|
|
|
|
2019-08-07 06:42:50 +00:00
|
|
|
let _val: Wrap<fn()> = mem::zeroed(); //~ ERROR: does not permit zero-initialization
|
|
|
|
let _val: Wrap<fn()> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
|
|
|
|
|
2019-08-12 07:24:13 +00:00
|
|
|
let _val: WrapEnum<fn()> = mem::zeroed(); //~ ERROR: does not permit zero-initialization
|
|
|
|
let _val: WrapEnum<fn()> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
|
|
|
|
|
|
|
|
let _val: Wrap<(RefPair, i32)> = mem::zeroed(); //~ ERROR: does not permit zero-initialization
|
|
|
|
let _val: Wrap<(RefPair, i32)> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
|
|
|
|
|
2019-08-06 21:11:52 +00:00
|
|
|
// Some types that should work just fine.
|
|
|
|
let _val: Option<&'static i32> = mem::zeroed();
|
|
|
|
let _val: Option<fn()> = mem::zeroed();
|
2019-08-07 06:42:50 +00:00
|
|
|
let _val: MaybeUninit<&'static i32> = mem::zeroed();
|
2019-08-06 21:11:52 +00:00
|
|
|
let _val: bool = mem::zeroed();
|
|
|
|
let _val: i32 = mem::zeroed();
|
|
|
|
}
|
|
|
|
}
|