Skip to content

Commit 6e98731

Browse files
committed
Add tests
1 parent 714b29a commit 6e98731

File tree

2 files changed

+51
-30
lines changed

2 files changed

+51
-30
lines changed

tests/ui/pattern/never_patterns.stderr

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,84 @@
1+
// check-pass
12
#![feature(never_patterns)]
3+
#![feature(exhaustive_patterns)]
24
#![allow(incomplete_features)]
35

6+
#[derive(Copy, Clone)]
47
enum Void {}
58

69
fn main() {}
710

811
// 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;
1114
let (Ok(_x) | Err(!)) = &res;
12-
let (Ok(_x) | Err(&!)) = res.as_ref();
15+
let (Ok(_x) | Err(!)) = res.as_ref();
1316
}
1417

1518
// Check we only accept `!` where we want to.
16-
fn never_pattern_location(void: Void) {
19+
fn never_pattern_typeck(void: Void) {
1720
// 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+
}
1830
match Some(0) {
1931
None => {}
2032
Some(!),
2133
}
34+
2235
// FIXME(never_patterns): Don't accept on an arbitrary type, even if there are no more branches.
2336
match () {
2437
() => {}
2538
!,
2639
}
40+
2741
// FIXME(never_patterns): Don't accept even on an empty branch.
2842
match None::<Void> {
2943
None => {}
3044
!,
3145
}
46+
match (&[] as &[Void]) {
47+
[] => {}
48+
!,
49+
}
3250
// FIXME(never_patterns): Let alone if the emptiness is behind a reference.
3351
match None::<&Void> {
3452
None => {}
3553
!,
3654
}
55+
3756
// Participate in match ergonomics.
3857
match &void {
39-
!
58+
!,
4059
}
4160
match &&void {
42-
!
61+
!,
4362
}
4463
match &&void {
45-
&!
64+
&!,
4665
}
4766
match &None::<Void> {
4867
None => {}
49-
Some(!)
68+
Some(!),
5069
}
5170
match None::<&Void> {
5271
None => {}
5372
Some(!),
5473
}
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+
&!,
5981
}
60-
// Accept on an simple empty type.
6182
match None::<Void> {
6283
None => {}
6384
Some(!),
@@ -70,4 +91,21 @@ fn never_pattern_location(void: Void) {
7091
None => {}
7192
Some(&(_, !)),
7293
}
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+
}
73111
}

0 commit comments

Comments
 (0)