1
+ // check-pass
1
2
#![ feature( never_patterns) ]
3
+ #![ feature( exhaustive_patterns) ]
2
4
#![ allow( incomplete_features) ]
3
5
6
+ #[ derive( Copy , Clone ) ]
4
7
enum Void { }
5
8
6
9
fn main ( ) { }
7
10
8
11
// The classic use for empty types.
9
- fn safe_unwrap_result < T > ( res : Result < T , Void > ) {
10
- let Ok ( _x) = res; //~ ERROR refutable pattern in local binding
12
+ fn safe_unwrap_result < T : Copy > ( res : Result < T , Void > ) {
13
+ let Ok ( _x) = res;
11
14
let ( Ok ( _x) | Err ( !) ) = & res;
12
- let ( Ok ( _x) | Err ( & !) ) = res. as_ref ( ) ;
15
+ let ( Ok ( _x) | Err ( !) ) = res. as_ref ( ) ;
13
16
}
14
17
15
18
// Check we only accept `!` where we want to.
16
- fn never_pattern_location ( void : Void ) {
19
+ fn never_pattern_typeck ( void : Void ) {
17
20
// FIXME(never_patterns): Don't accept on a non-empty type.
21
+ match ( ) {
22
+ !,
23
+ }
24
+ match ( 0 , false ) {
25
+ !,
26
+ }
27
+ match ( 0 , false ) {
28
+ ( _, !) ,
29
+ }
18
30
match Some ( 0 ) {
19
31
None => { }
20
32
Some ( !) ,
21
33
}
34
+
22
35
// FIXME(never_patterns): Don't accept on an arbitrary type, even if there are no more branches.
23
36
match ( ) {
24
37
( ) => { }
25
38
!,
26
39
}
40
+
27
41
// FIXME(never_patterns): Don't accept even on an empty branch.
28
42
match None :: < Void > {
29
43
None => { }
30
44
!,
31
45
}
46
+ match ( & [ ] as & [ Void ] ) {
47
+ [ ] => { }
48
+ !,
49
+ }
32
50
// FIXME(never_patterns): Let alone if the emptiness is behind a reference.
33
51
match None :: < & Void > {
34
52
None => { }
35
53
!,
36
54
}
55
+
37
56
// Participate in match ergonomics.
38
57
match & void {
39
- !
58
+ !,
40
59
}
41
60
match & & void {
42
- !
61
+ !,
43
62
}
44
63
match & & void {
45
- & !
64
+ & !,
46
65
}
47
66
match & None :: < Void > {
48
67
None => { }
49
- Some ( !)
68
+ Some ( !) ,
50
69
}
51
70
match None :: < & Void > {
52
71
None => { }
53
72
Some ( !) ,
54
73
}
55
- // Accept on a composite empty type.
56
- match None :: < & ( u32 , Void ) > {
57
- None => { }
58
- Some ( & !) ,
74
+
75
+ // Accept on a directly empty type.
76
+ match void {
77
+ !,
78
+ }
79
+ match & void {
80
+ & !,
59
81
}
60
- // Accept on an simple empty type.
61
82
match None :: < Void > {
62
83
None => { }
63
84
Some ( !) ,
@@ -70,4 +91,21 @@ fn never_pattern_location(void: Void) {
70
91
None => { }
71
92
Some ( & ( _, !) ) ,
72
93
}
94
+ match ( & [ ] as & [ Void ] ) {
95
+ [ ] => { }
96
+ [ !] ,
97
+ }
98
+ // Accept on a composite empty type.
99
+ match None :: < & ( u32 , Void ) > {
100
+ None => { }
101
+ Some ( & !) ,
102
+ }
103
+ match None :: < & ( u32 , Void ) > {
104
+ None => { }
105
+ Some ( !) ,
106
+ }
107
+ match None :: < & Result < Void , Void > > {
108
+ None => { }
109
+ Some ( !) ,
110
+ }
73
111
}
0 commit comments