Skip to content

Commit

Permalink
Add test for warning emitting if match is too complex
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Mar 18, 2024
1 parent 75caa89 commit 99e670f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 42 deletions.
44 changes: 6 additions & 38 deletions tests/ui/pattern/complexity_limit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
//@ check-pass

#![feature(rustc_attrs)]
#![pattern_complexity = "10000"]
// By default the complexity is 10_000_000, but we reduce it so the test takes
// (much) less time.
#![pattern_complexity = "2000000"]

#[derive(Default)]
struct BaseCommand {
Expand All @@ -21,22 +25,10 @@ struct BaseCommand {
field16: bool,
field17: bool,
field18: bool,
field19: bool,
field20: bool,
field21: bool,
field22: bool,
field23: bool,
field24: bool,
field25: bool,
field26: bool,
field27: bool,
field28: bool,
field29: bool,
field30: bool,
}

fn request_key(command: BaseCommand) {
match command { //~ ERROR: reached pattern complexity limit
match command { //~ WARN: `match` is too complex
BaseCommand { field01: true, .. } => {}
BaseCommand { field02: true, .. } => {}
BaseCommand { field03: true, .. } => {}
Expand All @@ -55,18 +47,6 @@ fn request_key(command: BaseCommand) {
BaseCommand { field16: true, .. } => {}
BaseCommand { field17: true, .. } => {}
BaseCommand { field18: true, .. } => {}
BaseCommand { field19: true, .. } => {}
BaseCommand { field20: true, .. } => {}
BaseCommand { field21: true, .. } => {}
BaseCommand { field22: true, .. } => {}
BaseCommand { field23: true, .. } => {}
BaseCommand { field24: true, .. } => {}
BaseCommand { field25: true, .. } => {}
BaseCommand { field26: true, .. } => {}
BaseCommand { field27: true, .. } => {}
BaseCommand { field28: true, .. } => {}
BaseCommand { field29: true, .. } => {}
BaseCommand { field30: true, .. } => {}

BaseCommand { field01: false, .. } => {}
BaseCommand { field02: false, .. } => {}
Expand All @@ -86,18 +66,6 @@ fn request_key(command: BaseCommand) {
BaseCommand { field16: false, .. } => {}
BaseCommand { field17: false, .. } => {}
BaseCommand { field18: false, .. } => {}
BaseCommand { field19: false, .. } => {}
BaseCommand { field20: false, .. } => {}
BaseCommand { field21: false, .. } => {}
BaseCommand { field22: false, .. } => {}
BaseCommand { field23: false, .. } => {}
BaseCommand { field24: false, .. } => {}
BaseCommand { field25: false, .. } => {}
BaseCommand { field26: false, .. } => {}
BaseCommand { field27: false, .. } => {}
BaseCommand { field28: false, .. } => {}
BaseCommand { field29: false, .. } => {}
BaseCommand { field30: false, .. } => {}
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/ui/pattern/complexity_limit.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error: reached pattern complexity limit
--> $DIR/complexity_limit.rs:39:5
warning: `match` is too complex
--> $DIR/complexity_limit.rs:31:5
|
LL | / match command {
LL | | BaseCommand { field01: true, .. } => {}
LL | | BaseCommand { field02: true, .. } => {}
LL | | BaseCommand { field03: true, .. } => {}
... |
LL | | BaseCommand { field30: false, .. } => {}
LL | | BaseCommand { field18: false, .. } => {}
LL | | }
| |_____^

error: aborting due to 1 previous error
warning: 1 warning emitted

0 comments on commit 99e670f

Please sign in to comment.