Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3c1a1c6

Browse files
committed
Add tests
1 parent 7d38181 commit 3c1a1c6

File tree

4 files changed

+90
-10
lines changed

4 files changed

+90
-10
lines changed

src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ fn main() {
4848
(1 | 1,) => {} //~ ERROR unreachable
4949
_ => {}
5050
}
51+
match 0 {
52+
(0 | 1) | 1 => {} //~ ERROR unreachable
53+
_ => {}
54+
}
55+
match 0 {
56+
0 | (0 | 0) => {}
57+
//~^ ERROR unreachable
58+
_ => {}
59+
}
60+
match None {
61+
// There is only one error that correctly points to the whole subpattern
62+
Some(0) |
63+
Some( //~ ERROR unreachable
64+
0 | 0) => {}
65+
_ => {}
66+
}
5167
match [0; 2] {
5268
[0
5369
| 0 //~ ERROR unreachable

src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,58 +77,77 @@ LL | (1 | 1,) => {}
7777
| ^
7878

7979
error: unreachable pattern
80-
--> $DIR/exhaustiveness-unreachable-pattern.rs:53:15
80+
--> $DIR/exhaustiveness-unreachable-pattern.rs:52:19
81+
|
82+
LL | (0 | 1) | 1 => {}
83+
| ^
84+
85+
error: unreachable pattern
86+
--> $DIR/exhaustiveness-unreachable-pattern.rs:56:14
87+
|
88+
LL | 0 | (0 | 0) => {}
89+
| ^^^^^
90+
91+
error: unreachable pattern
92+
--> $DIR/exhaustiveness-unreachable-pattern.rs:63:13
93+
|
94+
LL | / Some(
95+
LL | | 0 | 0) => {}
96+
| |______________________^
97+
98+
error: unreachable pattern
99+
--> $DIR/exhaustiveness-unreachable-pattern.rs:69:15
81100
|
82101
LL | | 0
83102
| ^
84103

85104
error: unreachable pattern
86-
--> $DIR/exhaustiveness-unreachable-pattern.rs:55:15
105+
--> $DIR/exhaustiveness-unreachable-pattern.rs:71:15
87106
|
88107
LL | | 0] => {}
89108
| ^
90109

91110
error: unreachable pattern
92-
--> $DIR/exhaustiveness-unreachable-pattern.rs:63:10
111+
--> $DIR/exhaustiveness-unreachable-pattern.rs:79:10
93112
|
94113
LL | [1
95114
| ^
96115

97116
error: unreachable pattern
98-
--> $DIR/exhaustiveness-unreachable-pattern.rs:75:10
117+
--> $DIR/exhaustiveness-unreachable-pattern.rs:91:10
99118
|
100119
LL | [true
101120
| ^^^^
102121

103122
error: unreachable pattern
104-
--> $DIR/exhaustiveness-unreachable-pattern.rs:82:36
123+
--> $DIR/exhaustiveness-unreachable-pattern.rs:98:36
105124
|
106125
LL | (true | false, None | Some(true
107126
| ^^^^
108127

109128
error: unreachable pattern
110-
--> $DIR/exhaustiveness-unreachable-pattern.rs:98:14
129+
--> $DIR/exhaustiveness-unreachable-pattern.rs:114:14
111130
|
112131
LL | Some(0
113132
| ^
114133

115134
error: unreachable pattern
116-
--> $DIR/exhaustiveness-unreachable-pattern.rs:117:19
135+
--> $DIR/exhaustiveness-unreachable-pattern.rs:133:19
117136
|
118137
LL | | false) => {}
119138
| ^^^^^
120139

121140
error: unreachable pattern
122-
--> $DIR/exhaustiveness-unreachable-pattern.rs:125:15
141+
--> $DIR/exhaustiveness-unreachable-pattern.rs:141:15
123142
|
124143
LL | | true) => {}
125144
| ^^^^
126145

127146
error: unreachable pattern
128-
--> $DIR/exhaustiveness-unreachable-pattern.rs:131:15
147+
--> $DIR/exhaustiveness-unreachable-pattern.rs:147:15
129148
|
130149
LL | | true,
131150
| ^^^^
132151

133-
error: aborting due to 21 previous errors
152+
error: aborting due to 24 previous errors
134153

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#![deny(unreachable_patterns)]
2+
//~^ NOTE: lint level is defined here
3+
pub enum TypeCtor {
4+
Slice,
5+
Array,
6+
}
7+
8+
pub struct ApplicationTy(TypeCtor);
9+
10+
macro_rules! ty_app {
11+
($ctor:pat) => {
12+
ApplicationTy($ctor) //~ ERROR unreachable pattern
13+
};
14+
}
15+
16+
fn _foo(ty: ApplicationTy) {
17+
match ty {
18+
ty_app!(TypeCtor::Array) | ty_app!(TypeCtor::Slice) => {} //~ NOTE: in this expansion
19+
}
20+
21+
// same as above, with the macro expanded
22+
match ty {
23+
ApplicationTy(TypeCtor::Array) | ApplicationTy(TypeCtor::Slice) => {}
24+
}
25+
}
26+
27+
fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: unreachable pattern
2+
--> $DIR/issue-80501-or-pat-and-macro.rs:12:9
3+
|
4+
LL | ApplicationTy($ctor)
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
...
7+
LL | ty_app!(TypeCtor::Array) | ty_app!(TypeCtor::Slice) => {}
8+
| ------------------------ in this macro invocation
9+
|
10+
note: the lint level is defined here
11+
--> $DIR/issue-80501-or-pat-and-macro.rs:1:9
12+
|
13+
LL | #![deny(unreachable_patterns)]
14+
| ^^^^^^^^^^^^^^^^^^^^
15+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
16+
17+
error: aborting due to previous error
18+

0 commit comments

Comments
 (0)