1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // This test checks that instantiating an uninhabited type via `mem::{uninitialized,zeroed}` results
12 // in a runtime panic.
14 #![feature(never_type)]
16 use std::{mem, panic};
26 panic::catch_unwind(|| {
27 mem::uninitialized::<!>()
28 }).err().and_then(|a| a.downcast_ref::<String>().map(|s| {
29 s == "Attempted to instantiate uninhabited type ! using mem::uninitialized"
35 panic::catch_unwind(|| {
37 }).err().and_then(|a| a.downcast_ref::<String>().map(|s| {
38 s == "Attempted to instantiate uninhabited type ! using mem::zeroed"
44 panic::catch_unwind(|| {
45 mem::uninitialized::<Foo>()
46 }).err().and_then(|a| a.downcast_ref::<String>().map(|s| {
47 s == "Attempted to instantiate uninhabited type Foo using mem::uninitialized"
53 panic::catch_unwind(|| {
55 }).err().and_then(|a| a.downcast_ref::<String>().map(|s| {
56 s == "Attempted to instantiate uninhabited type Foo using mem::zeroed"