6
6
#![ feature( never_type) ]
7
7
#![ allow( deprecated, invalid_value) ]
8
8
9
- use std:: { mem, panic} ;
10
- use std:: ptr:: NonNull ;
9
+ use std:: {
10
+ mem:: { self , MaybeUninit } ,
11
+ panic,
12
+ ptr:: NonNull ,
13
+ } ;
11
14
12
15
#[ allow( dead_code) ]
13
16
struct Foo {
@@ -40,7 +43,7 @@ fn main() {
40
43
"attempted to instantiate uninhabited type `!`"
41
44
) ;
42
45
test_panic_msg (
43
- || mem :: MaybeUninit :: < !> :: uninit ( ) . assume_init ( ) ,
46
+ || MaybeUninit :: < !> :: uninit ( ) . assume_init ( ) ,
44
47
"attempted to instantiate uninhabited type `!`"
45
48
) ;
46
49
@@ -53,7 +56,7 @@ fn main() {
53
56
"attempted to instantiate uninhabited type `Foo`"
54
57
) ;
55
58
test_panic_msg (
56
- || mem :: MaybeUninit :: < Foo > :: uninit ( ) . assume_init ( ) ,
59
+ || MaybeUninit :: < Foo > :: uninit ( ) . assume_init ( ) ,
57
60
"attempted to instantiate uninhabited type `Foo`"
58
61
) ;
59
62
@@ -66,7 +69,7 @@ fn main() {
66
69
"attempted to instantiate uninhabited type `Bar`"
67
70
) ;
68
71
test_panic_msg (
69
- || mem :: MaybeUninit :: < Bar > :: uninit ( ) . assume_init ( ) ,
72
+ || MaybeUninit :: < Bar > :: uninit ( ) . assume_init ( ) ,
70
73
"attempted to instantiate uninhabited type `Bar`"
71
74
) ;
72
75
@@ -109,5 +112,11 @@ fn main() {
109
112
let _val = mem:: zeroed :: < bool > ( ) ;
110
113
let _val = mem:: zeroed :: < OneVariant > ( ) ;
111
114
let _val = mem:: zeroed :: < Option < & ' static i32 > > ( ) ;
115
+ let _val = mem:: zeroed :: < MaybeUninit < NonNull < u32 > > > ( ) ;
116
+ let _val = mem:: uninitialized :: < MaybeUninit < bool > > ( ) ;
117
+
118
+ // We don't panic for these just to be conservative. They are UB as of now (2019-11-09).
119
+ let _val = mem:: uninitialized :: < i32 > ( ) ;
120
+ let _val = mem:: uninitialized :: < * const ( ) > ( ) ;
112
121
}
113
122
}
0 commit comments