]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/panic-uninitialized-zeroed.rs
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 // ignore-wasm32-bare always compiled as panic=abort right now and this requires unwinding
12 // This test checks that instantiating an uninhabited type via `mem::{uninitialized,zeroed}` results
13 // in a runtime panic.
15 #![feature(never_type)]
17 use std
::{mem, panic}
;
30 panic
::catch_unwind(|| {
31 mem
::uninitialized
::<!>()
32 }).err().and_then(|a
| a
.downcast_ref
::<String
>().map(|s
| {
33 s
== "Attempted to instantiate uninhabited type ! using mem::uninitialized"
39 panic
::catch_unwind(|| {
41 }).err().and_then(|a
| a
.downcast_ref
::<String
>().map(|s
| {
42 s
== "Attempted to instantiate uninhabited type ! using mem::zeroed"
48 panic
::catch_unwind(|| {
49 mem
::uninitialized
::<Foo
>()
50 }).err().and_then(|a
| a
.downcast_ref
::<String
>().map(|s
| {
51 s
== "Attempted to instantiate uninhabited type Foo using mem::uninitialized"
57 panic
::catch_unwind(|| {
59 }).err().and_then(|a
| a
.downcast_ref
::<String
>().map(|s
| {
60 s
== "Attempted to instantiate uninhabited type Foo using mem::zeroed"
66 panic
::catch_unwind(|| {
67 mem
::uninitialized
::<Bar
>()
68 }).err().and_then(|a
| a
.downcast_ref
::<String
>().map(|s
| {
69 s
== "Attempted to instantiate uninhabited type Bar using mem::uninitialized"
75 panic
::catch_unwind(|| {
77 }).err().and_then(|a
| a
.downcast_ref
::<String
>().map(|s
| {
78 s
== "Attempted to instantiate uninhabited type Bar using mem::zeroed"