1
1
// Various tests ensuring that underscore patterns really just construct the place, but don't check its contents.
2
2
#![ feature( strict_provenance) ]
3
+ #![ feature( never_type) ]
4
+
3
5
use std:: ptr;
4
6
5
7
fn main ( ) {
@@ -9,6 +11,7 @@ fn main() {
9
11
invalid_let ( ) ;
10
12
dangling_let_type_annotation ( ) ;
11
13
invalid_let_type_annotation ( ) ;
14
+ never ( ) ;
12
15
}
13
16
14
17
fn dangling_match ( ) {
@@ -34,13 +37,25 @@ fn invalid_match() {
34
37
_ => { }
35
38
}
36
39
}
40
+
41
+ unsafe {
42
+ let x: Uninit < !> = Uninit { uninit : ( ) } ;
43
+ match x. value {
44
+ _ => { }
45
+ }
46
+ }
37
47
}
38
48
39
49
fn dangling_let ( ) {
40
50
unsafe {
41
51
let ptr = ptr:: without_provenance :: < bool > ( 0x40 ) ;
42
52
let _ = * ptr;
43
53
}
54
+
55
+ unsafe {
56
+ let ptr = ptr:: without_provenance :: < !> ( 0x40 ) ;
57
+ let _ = * ptr;
58
+ }
44
59
}
45
60
46
61
fn invalid_let ( ) {
@@ -49,6 +64,12 @@ fn invalid_let() {
49
64
let ptr = ptr:: addr_of!( val) . cast :: < bool > ( ) ;
50
65
let _ = * ptr;
51
66
}
67
+
68
+ unsafe {
69
+ let val = 3u8 ;
70
+ let ptr = ptr:: addr_of!( val) . cast :: < !> ( ) ;
71
+ let _ = * ptr;
72
+ }
52
73
}
53
74
54
75
// Adding a type annotation used to change how MIR is generated, make sure we cover both cases.
@@ -57,6 +78,11 @@ fn dangling_let_type_annotation() {
57
78
let ptr = ptr:: without_provenance :: < bool > ( 0x40 ) ;
58
79
let _: bool = * ptr;
59
80
}
81
+
82
+ unsafe {
83
+ let ptr = ptr:: without_provenance :: < !> ( 0x40 ) ;
84
+ let _: ! = * ptr;
85
+ }
60
86
}
61
87
62
88
fn invalid_let_type_annotation ( ) {
@@ -65,7 +91,28 @@ fn invalid_let_type_annotation() {
65
91
let ptr = ptr:: addr_of!( val) . cast :: < bool > ( ) ;
66
92
let _: bool = * ptr;
67
93
}
94
+
95
+ unsafe {
96
+ let val = 3u8 ;
97
+ let ptr = ptr:: addr_of!( val) . cast :: < !> ( ) ;
98
+ let _: ! = * ptr;
99
+ }
68
100
}
69
101
70
- // FIXME: we should also test `!`, not just `bool` -- but that s currently buggy:
71
- // https://github.com/rust-lang/rust/issues/117288
102
+ // Regression test from <https://github.com/rust-lang/rust/issues/117288>.
103
+ fn never ( ) {
104
+ unsafe {
105
+ let x = 3u8 ;
106
+ let x: * const ! = & x as * const u8 as * const _ ;
107
+ let _: ! = * x;
108
+ }
109
+
110
+ // Without a type annotation, make sure we don't implicitly coerce `!` to `()`
111
+ // when we do the noop `*x` (as that would require a `!` *value*, creating
112
+ // which is UB).
113
+ unsafe {
114
+ let x = 3u8 ;
115
+ let x: * const ! = & x as * const u8 as * const _ ;
116
+ let _ = * x;
117
+ }
118
+ }
0 commit comments