Skip to content

Commit 48b4105

Browse files
Add test for warning emitting if match is too complex
1 parent 8aa0221 commit 48b4105

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

tests/ui/pattern/too_complex_match.rs

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//@ check-pass
2+
3+
#![feature(rustc_attrs)]
4+
// By default the complexity is 10_000_000, but we reduce it so the test takes
5+
// (much) less time.
6+
#![pattern_complexity = "2000000"]
7+
8+
#[derive(Default)]
9+
struct BaseCommand {
10+
field01: bool,
11+
field02: bool,
12+
field03: bool,
13+
field04: bool,
14+
field05: bool,
15+
field06: bool,
16+
field07: bool,
17+
field08: bool,
18+
field09: bool,
19+
field10: bool,
20+
field11: bool,
21+
field12: bool,
22+
field13: bool,
23+
field14: bool,
24+
field15: bool,
25+
field16: bool,
26+
field17: bool,
27+
field18: bool,
28+
}
29+
30+
fn request_key(command: BaseCommand) {
31+
match command { //~ WARN: `match` is too complex
32+
BaseCommand { field01: true, .. } => {}
33+
BaseCommand { field02: true, .. } => {}
34+
BaseCommand { field03: true, .. } => {}
35+
BaseCommand { field04: true, .. } => {}
36+
BaseCommand { field05: true, .. } => {}
37+
BaseCommand { field06: true, .. } => {}
38+
BaseCommand { field07: true, .. } => {}
39+
BaseCommand { field08: true, .. } => {}
40+
BaseCommand { field09: true, .. } => {}
41+
BaseCommand { field10: true, .. } => {}
42+
BaseCommand { field11: true, .. } => {}
43+
BaseCommand { field12: true, .. } => {}
44+
BaseCommand { field13: true, .. } => {}
45+
BaseCommand { field14: true, .. } => {}
46+
BaseCommand { field15: true, .. } => {}
47+
BaseCommand { field16: true, .. } => {}
48+
BaseCommand { field17: true, .. } => {}
49+
BaseCommand { field18: true, .. } => {}
50+
51+
BaseCommand { field01: false, .. } => {}
52+
BaseCommand { field02: false, .. } => {}
53+
BaseCommand { field03: false, .. } => {}
54+
BaseCommand { field04: false, .. } => {}
55+
BaseCommand { field05: false, .. } => {}
56+
BaseCommand { field06: false, .. } => {}
57+
BaseCommand { field07: false, .. } => {}
58+
BaseCommand { field08: false, .. } => {}
59+
BaseCommand { field09: false, .. } => {}
60+
BaseCommand { field10: false, .. } => {}
61+
BaseCommand { field11: false, .. } => {}
62+
BaseCommand { field12: false, .. } => {}
63+
BaseCommand { field13: false, .. } => {}
64+
BaseCommand { field14: false, .. } => {}
65+
BaseCommand { field15: false, .. } => {}
66+
BaseCommand { field16: false, .. } => {}
67+
BaseCommand { field17: false, .. } => {}
68+
BaseCommand { field18: false, .. } => {}
69+
}
70+
}
71+
72+
fn main() {
73+
request_key(BaseCommand::default());
74+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: `match` is too complex
2+
--> $DIR/too_complex_match.rs:31:5
3+
|
4+
LL | / match command {
5+
LL | | BaseCommand { field01: true, .. } => {}
6+
LL | | BaseCommand { field02: true, .. } => {}
7+
LL | | BaseCommand { field03: true, .. } => {}
8+
... |
9+
LL | | BaseCommand { field18: false, .. } => {}
10+
LL | | }
11+
| |_____^
12+
13+
warning: 1 warning emitted
14+

0 commit comments

Comments
 (0)