Skip to content

Commit 0e20788

Browse files
committed
Split tests
1 parent a5d6855 commit 0e20788

File tree

4 files changed

+115
-98
lines changed

4 files changed

+115
-98
lines changed

tests/ui/collapsible_match.rs

-39
Original file line numberDiff line numberDiff line change
@@ -95,45 +95,6 @@ fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>
9595
},
9696
None => return,
9797
}
98-
99-
// if guards on outer match
100-
{
101-
match res_opt {
102-
Ok(val) if make() => match val {
103-
Some(n) => foo(n),
104-
_ => return,
105-
},
106-
_ => return,
107-
}
108-
match res_opt {
109-
Ok(val) => match val {
110-
Some(n) => foo(n),
111-
_ => return,
112-
},
113-
_ if make() => return,
114-
_ => return,
115-
}
116-
}
117-
118-
// macro
119-
{
120-
macro_rules! mac {
121-
($outer:expr => $pat:pat, $e:expr => $inner_pat:pat, $then:expr) => {
122-
match $outer {
123-
$pat => match $e {
124-
$inner_pat => $then,
125-
_ => return,
126-
},
127-
_ => return,
128-
}
129-
};
130-
}
131-
// Lint this since the patterns are not defined by the macro.
132-
// Allows the lint to work on if_chain! for example.
133-
// Fixing the lint requires knowledge of the specific macro, but we optimistically assume that
134-
// there is still a better way to write this.
135-
mac!(res_opt => Ok(val), val => Some(n), foo(n));
136-
}
13798
}
13899

139100
fn negative_cases(res_opt: Result<Option<u32>, String>, res_res: Result<Result<u32, String>, String>) {

tests/ui/collapsible_match.stderr

+1-59
Original file line numberDiff line numberDiff line change
@@ -175,63 +175,5 @@ LL | Some(val) => match val {
175175
LL | Some(n) => foo(n),
176176
| ^^^^^^^ with this pattern
177177

178-
error: Unnecessary nested match
179-
--> $DIR/collapsible_match.rs:102:34
180-
|
181-
LL | Ok(val) if make() => match val {
182-
| __________________________________^
183-
LL | | Some(n) => foo(n),
184-
LL | | _ => return,
185-
LL | | },
186-
| |_____________^
187-
|
188-
help: The outer pattern can be modified to include the inner pattern.
189-
--> $DIR/collapsible_match.rs:102:16
190-
|
191-
LL | Ok(val) if make() => match val {
192-
| ^^^ Replace this binding
193-
LL | Some(n) => foo(n),
194-
| ^^^^^^^ with this pattern
195-
196-
error: Unnecessary nested match
197-
--> $DIR/collapsible_match.rs:109:24
198-
|
199-
LL | Ok(val) => match val {
200-
| ________________________^
201-
LL | | Some(n) => foo(n),
202-
LL | | _ => return,
203-
LL | | },
204-
| |_____________^
205-
|
206-
help: The outer pattern can be modified to include the inner pattern.
207-
--> $DIR/collapsible_match.rs:109:16
208-
|
209-
LL | Ok(val) => match val {
210-
| ^^^ Replace this binding
211-
LL | Some(n) => foo(n),
212-
| ^^^^^^^ with this pattern
213-
214-
error: Unnecessary nested match
215-
--> $DIR/collapsible_match.rs:123:29
216-
|
217-
LL | $pat => match $e {
218-
| _____________________________^
219-
LL | | $inner_pat => $then,
220-
LL | | _ => return,
221-
LL | | },
222-
| |_____________________^
223-
...
224-
LL | mac!(res_opt => Ok(val), val => Some(n), foo(n));
225-
| ------------------------------------------------- in this macro invocation
226-
|
227-
help: The outer pattern can be modified to include the inner pattern.
228-
--> $DIR/collapsible_match.rs:135:28
229-
|
230-
LL | mac!(res_opt => Ok(val), val => Some(n), foo(n));
231-
| ^^^ ^^^^^^^ with this pattern
232-
| |
233-
| Replace this binding
234-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
235-
236-
error: aborting due to 13 previous errors
178+
error: aborting due to 10 previous errors
237179

tests/ui/collapsible_match2.rs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#![warn(clippy::collapsible_match)]
2+
#![allow(clippy::needless_return, clippy::no_effect, clippy::single_match)]
3+
4+
fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>) {
5+
// if guards on outer match
6+
{
7+
match res_opt {
8+
Ok(val) if make() => match val {
9+
Some(n) => foo(n),
10+
_ => return,
11+
},
12+
_ => return,
13+
}
14+
match res_opt {
15+
Ok(val) => match val {
16+
Some(n) => foo(n),
17+
_ => return,
18+
},
19+
_ if make() => return,
20+
_ => return,
21+
}
22+
}
23+
24+
// macro
25+
{
26+
macro_rules! mac {
27+
($outer:expr => $pat:pat, $e:expr => $inner_pat:pat, $then:expr) => {
28+
match $outer {
29+
$pat => match $e {
30+
$inner_pat => $then,
31+
_ => return,
32+
},
33+
_ => return,
34+
}
35+
};
36+
}
37+
// Lint this since the patterns are not defined by the macro.
38+
// Allows the lint to work on if_chain! for example.
39+
// Fixing the lint requires knowledge of the specific macro, but we optimistically assume that
40+
// there is still a better way to write this.
41+
mac!(res_opt => Ok(val), val => Some(n), foo(n));
42+
}
43+
}
44+
45+
fn make<T>() -> T {
46+
unimplemented!()
47+
}
48+
49+
fn foo<T, U>(t: T) -> U {
50+
unimplemented!()
51+
}
52+
53+
fn main() {}

tests/ui/collapsible_match2.stderr

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
error: Unnecessary nested match
2+
--> $DIR/collapsible_match2.rs:8:34
3+
|
4+
LL | Ok(val) if make() => match val {
5+
| __________________________________^
6+
LL | | Some(n) => foo(n),
7+
LL | | _ => return,
8+
LL | | },
9+
| |_____________^
10+
|
11+
= note: `-D clippy::collapsible-match` implied by `-D warnings`
12+
help: The outer pattern can be modified to include the inner pattern.
13+
--> $DIR/collapsible_match2.rs:8:16
14+
|
15+
LL | Ok(val) if make() => match val {
16+
| ^^^ Replace this binding
17+
LL | Some(n) => foo(n),
18+
| ^^^^^^^ with this pattern
19+
20+
error: Unnecessary nested match
21+
--> $DIR/collapsible_match2.rs:15:24
22+
|
23+
LL | Ok(val) => match val {
24+
| ________________________^
25+
LL | | Some(n) => foo(n),
26+
LL | | _ => return,
27+
LL | | },
28+
| |_____________^
29+
|
30+
help: The outer pattern can be modified to include the inner pattern.
31+
--> $DIR/collapsible_match2.rs:15:16
32+
|
33+
LL | Ok(val) => match val {
34+
| ^^^ Replace this binding
35+
LL | Some(n) => foo(n),
36+
| ^^^^^^^ with this pattern
37+
38+
error: Unnecessary nested match
39+
--> $DIR/collapsible_match2.rs:29:29
40+
|
41+
LL | $pat => match $e {
42+
| _____________________________^
43+
LL | | $inner_pat => $then,
44+
LL | | _ => return,
45+
LL | | },
46+
| |_____________________^
47+
...
48+
LL | mac!(res_opt => Ok(val), val => Some(n), foo(n));
49+
| ------------------------------------------------- in this macro invocation
50+
|
51+
help: The outer pattern can be modified to include the inner pattern.
52+
--> $DIR/collapsible_match2.rs:41:28
53+
|
54+
LL | mac!(res_opt => Ok(val), val => Some(n), foo(n));
55+
| ^^^ ^^^^^^^ with this pattern
56+
| |
57+
| Replace this binding
58+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
59+
60+
error: aborting due to 3 previous errors
61+

0 commit comments

Comments
 (0)