Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 045f417

Browse files
committedMar 20, 2024
Add test for warning emitting if match is too complex
1 parent ff058f8 commit 045f417

File tree

2 files changed

+13
-42
lines changed

2 files changed

+13
-42
lines changed
 

‎tests/ui/pattern/complexity_limit.rs

+6-38
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
//@ check-pass
2+
13
#![feature(rustc_attrs)]
2-
#![pattern_complexity = "10000"]
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"]
37

48
#[derive(Default)]
59
struct BaseCommand {
@@ -21,22 +25,10 @@ struct BaseCommand {
2125
field16: bool,
2226
field17: bool,
2327
field18: bool,
24-
field19: bool,
25-
field20: bool,
26-
field21: bool,
27-
field22: bool,
28-
field23: bool,
29-
field24: bool,
30-
field25: bool,
31-
field26: bool,
32-
field27: bool,
33-
field28: bool,
34-
field29: bool,
35-
field30: bool,
3628
}
3729

3830
fn request_key(command: BaseCommand) {
39-
match command { //~ ERROR: reached pattern complexity limit
31+
match command { //~ WARN: this pattern-match expression is taking a long time to analyze
4032
BaseCommand { field01: true, .. } => {}
4133
BaseCommand { field02: true, .. } => {}
4234
BaseCommand { field03: true, .. } => {}
@@ -55,18 +47,6 @@ fn request_key(command: BaseCommand) {
5547
BaseCommand { field16: true, .. } => {}
5648
BaseCommand { field17: true, .. } => {}
5749
BaseCommand { field18: true, .. } => {}
58-
BaseCommand { field19: true, .. } => {}
59-
BaseCommand { field20: true, .. } => {}
60-
BaseCommand { field21: true, .. } => {}
61-
BaseCommand { field22: true, .. } => {}
62-
BaseCommand { field23: true, .. } => {}
63-
BaseCommand { field24: true, .. } => {}
64-
BaseCommand { field25: true, .. } => {}
65-
BaseCommand { field26: true, .. } => {}
66-
BaseCommand { field27: true, .. } => {}
67-
BaseCommand { field28: true, .. } => {}
68-
BaseCommand { field29: true, .. } => {}
69-
BaseCommand { field30: true, .. } => {}
7050

7151
BaseCommand { field01: false, .. } => {}
7252
BaseCommand { field02: false, .. } => {}
@@ -86,18 +66,6 @@ fn request_key(command: BaseCommand) {
8666
BaseCommand { field16: false, .. } => {}
8767
BaseCommand { field17: false, .. } => {}
8868
BaseCommand { field18: false, .. } => {}
89-
BaseCommand { field19: false, .. } => {}
90-
BaseCommand { field20: false, .. } => {}
91-
BaseCommand { field21: false, .. } => {}
92-
BaseCommand { field22: false, .. } => {}
93-
BaseCommand { field23: false, .. } => {}
94-
BaseCommand { field24: false, .. } => {}
95-
BaseCommand { field25: false, .. } => {}
96-
BaseCommand { field26: false, .. } => {}
97-
BaseCommand { field27: false, .. } => {}
98-
BaseCommand { field28: false, .. } => {}
99-
BaseCommand { field29: false, .. } => {}
100-
BaseCommand { field30: false, .. } => {}
10169
}
10270
}
10371

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
error: reached pattern complexity limit
2-
--> $DIR/complexity_limit.rs:39:5
1+
warning: this pattern-match expression is taking a long time to analyze
2+
--> $DIR/complexity_limit.rs:31:5
33
|
44
LL | / match command {
55
LL | | BaseCommand { field01: true, .. } => {}
66
LL | | BaseCommand { field02: true, .. } => {}
77
LL | | BaseCommand { field03: true, .. } => {}
88
... |
9-
LL | | BaseCommand { field30: false, .. } => {}
9+
LL | | BaseCommand { field18: false, .. } => {}
1010
LL | | }
1111
| |_____^
12+
|
13+
= help: to speed up checking, break it up into smaller `match`es and/or replace some patterns with guards
14+
= note: match checking can take exponential time when many different fields of structs/tuples/arrays are involved
1215

13-
error: aborting due to 1 previous error
16+
warning: 1 warning emitted
1417

0 commit comments

Comments
 (0)
Failed to load comments.