2019-08-06 23:11:52 +02: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 08:42:50 +02:00
|
|
|
use std::mem::{self, MaybeUninit};
|
|
|
|
|
|
|
|
enum Void {}
|
|
|
|
|
|
|
|
struct Ref(&'static i32);
|
|
|
|
|
|
|
|
struct Wrap<T> { wrapped: T }
|
|
|
|
|
|
|
|
#[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 23:11:52 +02: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 08:42:50 +02: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 23:11:52 +02: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 08:42:50 +02: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 23:11:52 +02: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 08:42:50 +02: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-06 23:11:52 +02:00
|
|
|
// Some types that should work just fine.
|
|
|
|
let _val: Option<&'static i32> = mem::zeroed();
|
|
|
|
let _val: Option<fn()> = mem::zeroed();
|
2019-08-07 08:42:50 +02:00
|
|
|
let _val: MaybeUninit<&'static i32> = mem::zeroed();
|
2019-08-06 23:11:52 +02:00
|
|
|
let _val: bool = mem::zeroed();
|
|
|
|
let _val: i32 = mem::zeroed();
|
|
|
|
}
|
|
|
|
}
|