Skip to content

Commit 364bbff

Browse files
committed
Add tests
1 parent 9d6d5d4 commit 364bbff

File tree

2 files changed

+220
-0
lines changed

2 files changed

+220
-0
lines changed
+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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 option_never2(x: Void) -> impl Copy {
53+
if true {
54+
match option_never2(x) {
55+
None => {}
56+
Some(_) => {} //~ERROR unreachable
57+
}
58+
match option_never2(x) {
59+
None => {}
60+
_ => {} //~ERROR unreachable
61+
}
62+
match option_never2(x) {
63+
None => {}
64+
}
65+
}
66+
Some(x)
67+
}
68+
69+
fn inner_never(x: Void) {
70+
type T = impl Copy;
71+
//~^ERROR unconstrained
72+
let y: T = x;
73+
match y {}
74+
//~^ERROR non-empty
75+
}
76+
77+
// This one caused ICE https://github.com/rust-lang/rust/issues/117100.
78+
fn inner_tuple() {
79+
type T = impl Copy;
80+
let foo: T = Some((1u32, 2u32));
81+
match foo {
82+
_ => {}
83+
Some((a, b)) => {} //~ERROR unreachable
84+
}
85+
}
86+
87+
type U = impl Copy;
88+
//~^ERROR unconstrained
89+
fn unify_never(x: Void, u: U) -> U {
90+
if true { match u {} } else { x }
91+
//~^ERROR non-empty
92+
}
93+
94+
type V = impl Copy;
95+
fn infer_in_match(x: Option<V>) {
96+
match x {
97+
None => {}
98+
Some((a, b)) => {}
99+
Some((mut x, mut y)) => {
100+
//~^ERROR unreachable
101+
x = 42;
102+
y = "foo";
103+
}
104+
}
105+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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: unreachable pattern
38+
--> $DIR/impl-trait.rs:56:13
39+
|
40+
LL | Some(_) => {}
41+
| ^^^^^^^
42+
|
43+
note: the lint level is defined here
44+
--> $DIR/impl-trait.rs:5:9
45+
|
46+
LL | #![deny(unreachable_patterns)]
47+
| ^^^^^^^^^^^^^^^^^^^^
48+
49+
error: unreachable pattern
50+
--> $DIR/impl-trait.rs:60:13
51+
|
52+
LL | _ => {}
53+
| ^
54+
55+
error[E0004]: non-exhaustive patterns: type `inner_never::T` is non-empty
56+
--> $DIR/impl-trait.rs:73:11
57+
|
58+
LL | match y {}
59+
| ^
60+
|
61+
= note: the matched value is of type `inner_never::T`
62+
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
63+
|
64+
LL ~ match y {
65+
LL + _ => todo!(),
66+
LL + }
67+
|
68+
69+
error: unconstrained opaque type
70+
--> $DIR/impl-trait.rs:70:14
71+
|
72+
LL | type T = impl Copy;
73+
| ^^^^^^^^^
74+
|
75+
= note: `T` must be used in combination with a concrete type within the same item
76+
77+
error: unreachable pattern
78+
--> $DIR/impl-trait.rs:83:9
79+
|
80+
LL | _ => {}
81+
| - matches any value
82+
LL | Some((a, b)) => {}
83+
| ^^^^^^^^^^^^ unreachable pattern
84+
85+
error[E0004]: non-exhaustive patterns: type `U` is non-empty
86+
--> $DIR/impl-trait.rs:90:21
87+
|
88+
LL | if true { match u {} } else { x }
89+
| ^
90+
|
91+
= note: the matched value is of type `U`
92+
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
93+
|
94+
LL ~ if true { match u {
95+
LL + _ => todo!(),
96+
LL ~ } } else { x }
97+
|
98+
99+
error: unconstrained opaque type
100+
--> $DIR/impl-trait.rs:87:10
101+
|
102+
LL | type U = impl Copy;
103+
| ^^^^^^^^^
104+
|
105+
= note: `U` must be used in combination with a concrete type within the same module
106+
107+
error: unreachable pattern
108+
--> $DIR/impl-trait.rs:99:9
109+
|
110+
LL | Some((mut x, mut y)) => {
111+
| ^^^^^^^^^^^^^^^^^^^^
112+
113+
error: aborting due to 11 previous errors
114+
115+
For more information about this error, try `rustc --explain E0004`.

0 commit comments

Comments
 (0)