File tree 3 files changed +51
-10
lines changed
3 files changed +51
-10
lines changed Original file line number Diff line number Diff line change @@ -131,18 +131,9 @@ fn test_discriminant_send_sync() {
131
131
}
132
132
133
133
#[ test]
134
+ #[ cfg( not( bootstrap) ) ]
134
135
fn assume_init_good ( ) {
135
136
const TRUE : bool = unsafe { MaybeUninit :: < bool > :: new ( true ) . assume_init ( ) } ;
136
137
137
138
assert ! ( TRUE ) ;
138
139
}
139
-
140
- #[ test]
141
- fn assume_init_bad ( ) {
142
- const _BAD: ( ) = unsafe {
143
- MaybeUninit :: < !> :: uninit ( ) . assume_init ( ) ;
144
- //~^ ERROR the type `!` does not permit being left uninitialized
145
- //~| ERROR this code causes undefined behavior when executed
146
- //~| ERROR help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
147
- } ;
148
- }
Original file line number Diff line number Diff line change
1
+ #![ feature( never_type) ]
2
+ #![ feature( const_maybe_uninit_assume_init) ]
3
+
4
+ fn main ( ) {
5
+ use std:: mem:: MaybeUninit ;
6
+
7
+ const _BAD: ( ) = unsafe {
8
+ MaybeUninit :: < !> :: uninit ( ) . assume_init ( ) ;
9
+ //~^ ERROR: the type `!` does not permit being left uninitialized
10
+ //~| this code causes undefined behavior when executed
11
+ //~| WARN: the type `!` does not permit being left uninitialized
12
+ } ;
13
+ }
Original file line number Diff line number Diff line change
1
+ error: any use of this value will cause an error
2
+ --> $SRC_DIR/core/src/mem/maybe_uninit.rs:LL:COL
3
+ |
4
+ LL | intrinsics::assert_inhabited::<T>();
5
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6
+ | |
7
+ | attempted to instantiate uninhabited type `!`
8
+ | inside `MaybeUninit::<!>::assume_init` at $SRC_DIR/core/src/mem/maybe_uninit.rs:LL:COL
9
+ | inside `_BAD` at $DIR/assume-type-intrinsics.rs:8:9
10
+ |
11
+ ::: $DIR/assume-type-intrinsics.rs:7:5
12
+ |
13
+ LL | / const _BAD: () = unsafe {
14
+ LL | | MaybeUninit::<!>::uninit().assume_init();
15
+ LL | |
16
+ LL | |
17
+ LL | |
18
+ LL | |
19
+ LL | | };
20
+ | |______-
21
+ |
22
+ = note: `#[deny(const_err)]` on by default
23
+
24
+ warning: the type `!` does not permit being left uninitialized
25
+ --> $DIR/assume-type-intrinsics.rs:8:9
26
+ |
27
+ LL | MaybeUninit::<!>::uninit().assume_init();
28
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29
+ | |
30
+ | this code causes undefined behavior when executed
31
+ | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
32
+ |
33
+ = note: `#[warn(invalid_value)]` on by default
34
+ = note: the `!` type has no valid value
35
+
36
+ error: aborting due to previous error; 1 warning emitted
37
+
You can’t perform that action at this time.
0 commit comments