11// Various tests ensuring that underscore patterns really just construct the place, but don't check its contents.
22#![ feature( strict_provenance) ]
3+ #![ feature( never_type) ]
4+
35use std:: ptr;
46
57fn main ( ) {
@@ -9,6 +11,7 @@ fn main() {
911 invalid_let ( ) ;
1012 dangling_let_type_annotation ( ) ;
1113 invalid_let_type_annotation ( ) ;
14+ never ( ) ;
1215}
1316
1417fn dangling_match ( ) {
@@ -34,13 +37,25 @@ fn invalid_match() {
3437 _ => { }
3538 }
3639 }
40+
41+ unsafe {
42+ let x: Uninit < !> = Uninit { uninit : ( ) } ;
43+ match x. value {
44+ _ => { }
45+ }
46+ }
3747}
3848
3949fn dangling_let ( ) {
4050 unsafe {
4151 let ptr = ptr:: without_provenance :: < bool > ( 0x40 ) ;
4252 let _ = * ptr;
4353 }
54+
55+ unsafe {
56+ let ptr = ptr:: without_provenance :: < !> ( 0x40 ) ;
57+ let _ = * ptr;
58+ }
4459}
4560
4661fn invalid_let ( ) {
@@ -49,6 +64,12 @@ fn invalid_let() {
4964 let ptr = ptr:: addr_of!( val) . cast :: < bool > ( ) ;
5065 let _ = * ptr;
5166 }
67+
68+ unsafe {
69+ let val = 3u8 ;
70+ let ptr = ptr:: addr_of!( val) . cast :: < !> ( ) ;
71+ let _ = * ptr;
72+ }
5273}
5374
5475// 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() {
5778 let ptr = ptr:: without_provenance :: < bool > ( 0x40 ) ;
5879 let _: bool = * ptr;
5980 }
81+
82+ unsafe {
83+ let ptr = ptr:: without_provenance :: < !> ( 0x40 ) ;
84+ let _: ! = * ptr;
85+ }
6086}
6187
6288fn invalid_let_type_annotation ( ) {
@@ -65,7 +91,28 @@ fn invalid_let_type_annotation() {
6591 let ptr = ptr:: addr_of!( val) . cast :: < bool > ( ) ;
6692 let _: bool = * ptr;
6793 }
94+
95+ unsafe {
96+ let val = 3u8 ;
97+ let ptr = ptr:: addr_of!( val) . cast :: < !> ( ) ;
98+ let _: ! = * ptr;
99+ }
68100}
69101
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