Skip to content

Commit 22e5ad0

Browse files
committed
Add tests
1 parent 9d6d5d4 commit 22e5ad0

File tree

2 files changed

+191
-0
lines changed

2 files changed

+191
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#![feature(never_type)]
2+
#![feature(exhaustive_patterns)]
3+
#![feature(type_alias_impl_trait)]
4+
#![feature(non_exhaustive_omitted_patterns_lint)]
5+
#![deny(unreachable_patterns)]
6+
// Test that the lint traversal handles opaques correctly
7+
#![deny(non_exhaustive_omitted_patterns)]
8+
9+
fn main() {}
10+
11+
#[derive(Copy, Clone)]
12+
enum Void {}
13+
14+
fn return_never_rpit(x: Void) -> impl Copy {
15+
if false {
16+
match return_never_rpit(x) {}
17+
//~^ERROR non-empty
18+
}
19+
x
20+
}
21+
fn friend_of_return_never_rpit(x: Void) {
22+
match return_never_rpit(x) {}
23+
}
24+
25+
type T = impl Copy;
26+
//~^ERROR unconstrained
27+
fn return_never_tait(x: Void) -> T {
28+
if false {
29+
match return_never_tait(x) {}
30+
//~^ERROR non-empty
31+
}
32+
x
33+
}
34+
fn friend_of_return_never_tait(x: Void) {
35+
match return_never_tait(x) {}
36+
}
37+
38+
fn option_never(x: Void) -> Option<impl Copy> {
39+
if true {
40+
match option_never(x) {
41+
None => {}
42+
Some(_) => {}
43+
}
44+
match option_never(x) {
45+
None => {}
46+
_ => {}
47+
}
48+
}
49+
Some(x)
50+
}
51+
52+
fn inner_never(x: Void) {
53+
type T = impl Copy;
54+
//~^ERROR unconstrained
55+
let y: T = x;
56+
match y {}
57+
//~^ERROR non-empty
58+
}
59+
60+
// This one caused ICE https://github.com/rust-lang/rust/issues/117100.
61+
fn inner_tuple() {
62+
type T = impl Copy;
63+
let foo: T = Some((1u32, 2u32));
64+
match foo {
65+
_ => {}
66+
Some((a, b)) => {} //~ERROR unreachable
67+
}
68+
}
69+
70+
type U = impl Copy;
71+
//~^ERROR unconstrained
72+
fn unify_never(x: Void, u: U) -> U {
73+
if true { match u {} } else { x }
74+
//~^ERROR non-empty
75+
}
76+
77+
type V = impl Copy;
78+
fn infer_in_match(x: Option<V>) {
79+
match x {
80+
None => {}
81+
Some((a, b)) => {}
82+
Some((mut x, mut y)) => {
83+
//~^ERROR unreachable
84+
x = 42;
85+
y = "foo";
86+
}
87+
}
88+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
error[E0004]: non-exhaustive patterns: type `impl Copy` is non-empty
2+
--> $DIR/impl-trait.rs:16:15
3+
|
4+
LL | match return_never_rpit(x) {}
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: the matched value is of type `impl Copy`
8+
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
9+
|
10+
LL ~ match return_never_rpit(x) {
11+
LL + _ => todo!(),
12+
LL + }
13+
|
14+
15+
error[E0004]: non-exhaustive patterns: type `T` is non-empty
16+
--> $DIR/impl-trait.rs:29:15
17+
|
18+
LL | match return_never_tait(x) {}
19+
| ^^^^^^^^^^^^^^^^^^^^
20+
|
21+
= note: the matched value is of type `T`
22+
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
23+
|
24+
LL ~ match return_never_tait(x) {
25+
LL + _ => todo!(),
26+
LL + }
27+
|
28+
29+
error: unconstrained opaque type
30+
--> $DIR/impl-trait.rs:25:10
31+
|
32+
LL | type T = impl Copy;
33+
| ^^^^^^^^^
34+
|
35+
= note: `T` must be used in combination with a concrete type within the same module
36+
37+
error[E0004]: non-exhaustive patterns: type `inner_never::T` is non-empty
38+
--> $DIR/impl-trait.rs:56:11
39+
|
40+
LL | match y {}
41+
| ^
42+
|
43+
= note: the matched value is of type `inner_never::T`
44+
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
45+
|
46+
LL ~ match y {
47+
LL + _ => todo!(),
48+
LL + }
49+
|
50+
51+
error: unconstrained opaque type
52+
--> $DIR/impl-trait.rs:53:14
53+
|
54+
LL | type T = impl Copy;
55+
| ^^^^^^^^^
56+
|
57+
= note: `T` must be used in combination with a concrete type within the same item
58+
59+
error: unreachable pattern
60+
--> $DIR/impl-trait.rs:66:9
61+
|
62+
LL | _ => {}
63+
| - matches any value
64+
LL | Some((a, b)) => {}
65+
| ^^^^^^^^^^^^ unreachable pattern
66+
|
67+
note: the lint level is defined here
68+
--> $DIR/impl-trait.rs:5:9
69+
|
70+
LL | #![deny(unreachable_patterns)]
71+
| ^^^^^^^^^^^^^^^^^^^^
72+
73+
error[E0004]: non-exhaustive patterns: type `U` is non-empty
74+
--> $DIR/impl-trait.rs:73:21
75+
|
76+
LL | if true { match u {} } else { x }
77+
| ^
78+
|
79+
= note: the matched value is of type `U`
80+
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
81+
|
82+
LL ~ if true { match u {
83+
LL + _ => todo!(),
84+
LL ~ } } else { x }
85+
|
86+
87+
error: unconstrained opaque type
88+
--> $DIR/impl-trait.rs:70:10
89+
|
90+
LL | type U = impl Copy;
91+
| ^^^^^^^^^
92+
|
93+
= note: `U` must be used in combination with a concrete type within the same module
94+
95+
error: unreachable pattern
96+
--> $DIR/impl-trait.rs:82:9
97+
|
98+
LL | Some((mut x, mut y)) => {
99+
| ^^^^^^^^^^^^^^^^^^^^
100+
101+
error: aborting due to 9 previous errors
102+
103+
For more information about this error, try `rustc --explain E0004`.

0 commit comments

Comments
 (0)