From 74f9bb377a9e5051dc4f2ec22f6660c0b1c33e51 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 18 Mar 2024 13:55:24 +0100 Subject: [PATCH] Add test for warning emitting if `match` is too complex --- tests/ui/pattern/complexity_limit.rs | 44 ++++-------------------- tests/ui/pattern/complexity_limit.stderr | 11 +++--- 2 files changed, 13 insertions(+), 42 deletions(-) diff --git a/tests/ui/pattern/complexity_limit.rs b/tests/ui/pattern/complexity_limit.rs index c9a3f99bccd14..c367141153f64 100644 --- a/tests/ui/pattern/complexity_limit.rs +++ b/tests/ui/pattern/complexity_limit.rs @@ -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 { @@ -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: this pattern-match expression is taking a long time to analyze BaseCommand { field01: true, .. } => {} BaseCommand { field02: true, .. } => {} BaseCommand { field03: true, .. } => {} @@ -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, .. } => {} @@ -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, .. } => {} } } diff --git a/tests/ui/pattern/complexity_limit.stderr b/tests/ui/pattern/complexity_limit.stderr index 08d9d40fe4626..9ad198ce05542 100644 --- a/tests/ui/pattern/complexity_limit.stderr +++ b/tests/ui/pattern/complexity_limit.stderr @@ -1,14 +1,17 @@ -error: reached pattern complexity limit - --> $DIR/complexity_limit.rs:39:5 +warning: this pattern-match expression is taking a long time to analyze + --> $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 | | } | |_____^ + | + = help: to speed up checking, break it up into smaller `match`es and/or replace some patterns with guards + = note: match checking can take exponential time when many different fields of structs/tuples/arrays are involved -error: aborting due to 1 previous error +warning: 1 warning emitted