rust/tests/ui/pattern
bors 1a086e49f1 Auto merge of #118796 - Nadrieril:fix-exponential-id-match-2, r=cjgillot
Exhaustiveness: Improve complexity on some wide matches

https://github.com/rust-lang/rust/issues/118437 revealed an exponential case in exhaustiveness checking. While [exponential cases are unavoidable](https://compilercrim.es/rust-np/), this one only showed up after my https://github.com/rust-lang/rust/pull/117611 rewrite of the algorithm. I remember anticipating a case like this and dismissing it as unrealistic, but here we are :').

The tricky match is as follows:
```rust
match command {
    BaseCommand { field01: true, .. } => {}
    BaseCommand { field02: true, .. } => {}
    BaseCommand { field03: true, .. } => {}
    BaseCommand { field04: true, .. } => {}
    BaseCommand { field05: true, .. } => {}
    BaseCommand { field06: true, .. } => {}
    BaseCommand { field07: true, .. } => {}
    BaseCommand { field08: true, .. } => {}
    BaseCommand { field09: true, .. } => {}
    BaseCommand { field10: true, .. } => {}
    // ...20 more of the same

    _ => {}
}
```

To fix this, this PR formalizes a concept of "relevancy" (naming is hard) that was already used to decide what patterns to report. Now we track it for every row, which in wide matches like the above can drastically cut on the number of cases we explore. After this fix, the above match is checked with linear-many cases instead of exponentially-many.

Fixes https://github.com/rust-lang/rust/issues/118437

r? `@cjgillot`
2023-12-24 14:40:36 +00:00
..
auxiliary Move /src/test to /tests 2023-01-11 09:32:08 +00:00
bindings-after-at Show number in error message even for one error 2023-11-24 19:15:52 +01:00
move-ref-patterns Show number in error message even for one error 2023-11-24 19:15:52 +01:00
usefulness Auto merge of #118796 - Nadrieril:fix-exponential-id-match-2, r=cjgillot 2023-12-24 14:40:36 +00:00
byte-string-inference.rs Revert "Structurally resolve correctly in check_pat_lit" 2023-06-24 18:41:27 +00:00
for-loop-bad-item.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
for-loop-bad-item.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
ignore-all-the-things.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
incorrect-placement-of-pattern-modifiers.fixed Account for ref and mut in the wrong place for pattern ident renaming 2023-10-30 00:15:49 +00:00
incorrect-placement-of-pattern-modifiers.rs Account for ref and mut in the wrong place for pattern ident renaming 2023-10-30 00:15:49 +00:00
incorrect-placement-of-pattern-modifiers.stderr Account for ref and mut in the wrong place for pattern ident renaming 2023-10-30 00:15:49 +00:00
integer-range-binding.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-6449.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-8351-1.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-8351-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-10392.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-11577.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-12582.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-14221.rs Change bindings_with_variant_name to deny-by-default 2023-01-20 02:26:12 -05:00
issue-14221.stderr Change bindings_with_variant_name to deny-by-default 2023-01-20 02:26:12 -05:00
issue-15080.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-17718-patterns.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-17718-patterns.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-22546.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-27320.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-52240.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-52240.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-66270-pat-struct-parser-recovery.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-66270-pat-struct-parser-recovery.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-67037-pat-tup-scrut-ty-diff-less-fields.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
issue-67776-match-same-name-enum-variant-refs.rs Change bindings_with_variant_name to deny-by-default 2023-01-20 02:26:12 -05:00
issue-67776-match-same-name-enum-variant-refs.stderr Change bindings_with_variant_name to deny-by-default 2023-01-20 02:26:12 -05:00
issue-68393-let-pat-assoc-constant.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-68393-let-pat-assoc-constant.stderr Perform match checking on THIR. 2023-04-03 15:59:21 +00:00
issue-72565.rs Avoid emitting the non_exhaustive error if other errors already occurred 2023-10-11 12:49:57 +00:00
issue-72565.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-72574-1.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-72574-1.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-72574-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-72574-2.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-74539.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-74539.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-74702.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-74702.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-74954.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-80186-mut-binding-help-suggestion.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-80186-mut-binding-help-suggestion.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-88074-pat-range-type-inference-err.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-88074-pat-range-type-inference-err.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-88074-pat-range-type-inference.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-92074-macro-ice.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-92074-macro-ice.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-94866.rs Move tests 2023-05-24 19:35:59 -03:00
issue-94866.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-95878.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-95878.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-106552.rs suggest fix for attempted integer identifier in patterns 2023-01-14 12:51:20 +13:00
issue-106552.stderr Perform match checking on THIR. 2023-04-03 15:59:21 +00:00
issue-106862.fixed error-msg: impl better suggestion for E0532 2023-03-15 22:19:54 +13:00
issue-106862.rs error-msg: impl better suggestion for E0532 2023-03-15 22:19:54 +13:00
issue-106862.stderr error-msg: impl better suggestion for E0532 2023-03-15 22:19:54 +13:00
issue-110508.rs add regression test 2023-07-01 02:28:15 -04:00
issue-114896.rs fixes #114896 2023-09-07 11:07:33 +08:00
issue-114896.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-115599.rs use PatKind::error when an ADT const value has violation 2023-10-15 19:20:06 +08:00
issue-115599.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
never_patterns.rs Disallow arm bodies on never patterns 2023-12-03 12:25:46 +01:00
never_patterns.stderr Add never_patterns feature gate 2023-11-29 03:58:29 +01:00
non-constant-in-const-path.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
non-constant-in-const-path.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
non-structural-match-types.mir.stderr Fix inline const pattern unsafety checking in THIR 2023-10-16 15:57:59 +00:00
non-structural-match-types.rs Fix inline const pattern unsafety checking in THIR 2023-10-16 15:57:59 +00:00
non-structural-match-types.thir.stderr Fix inline const pattern unsafety checking in THIR 2023-10-16 15:57:59 +00:00
pat-shadow-in-nested-binding.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-shadow-in-nested-binding.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
pat-struct-field-expr-has-type.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-struct-field-expr-has-type.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
pat-tuple-bad-type.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-tuple-bad-type.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-tuple-field-count-cross.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-tuple-field-count-cross.stderr resolve: Remove struct_field_names_untracked 2023-03-13 17:31:55 +04:00
pat-tuple-overfield.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-tuple-overfield.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-tuple-underfield.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-tuple-underfield.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-type-err-formal-param.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-type-err-formal-param.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
pat-type-err-let-stmt.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-type-err-let-stmt.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
patkind-litrange-no-expr.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
patkind-litrange-no-expr.stderr Add a note to duplicate diagnostics 2023-10-05 01:04:41 +00:00
pattern-bad-ref-box-order.fixed Suggest swapping the order of ref and box 2023-11-27 21:38:19 +09:00
pattern-bad-ref-box-order.rs Suggest swapping the order of ref and box 2023-11-27 21:38:19 +09:00
pattern-bad-ref-box-order.stderr Suggest swapping the order of ref and box 2023-11-27 21:38:19 +09:00
pattern-binding-disambiguation.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pattern-binding-disambiguation.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pattern-error-continue.rs Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
pattern-error-continue.stderr refactor(resolve): clean up the early error return caused by non-call 2023-05-10 22:35:01 +08:00
pattern-ident-path-generics.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pattern-ident-path-generics.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
pattern-tyvar-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pattern-tyvar-2.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
pattern-tyvar.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pattern-tyvar.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
range-pattern-meant-to-be-slice-rest-pattern.rs On resolve error of [rest..], suggest [rest @ ..] 2023-11-17 00:55:55 +00:00
range-pattern-meant-to-be-slice-rest-pattern.stderr On resolve error of [rest..], suggest [rest @ ..] 2023-11-17 00:55:55 +00:00
rest-pat-semantic-disallowed.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
rest-pat-semantic-disallowed.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
rest-pat-syntactic.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
rest-pat-syntactic.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
size-and-align.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
slice-array-infer.rs add more tests 2023-07-17 22:06:32 +00:00
slice-pattern-refutable.rs address review 2023-07-17 22:06:32 +00:00
slice-pattern-refutable.stderr address review 2023-07-17 22:06:32 +00:00
slice-patterns-ambiguity.rs add tests for refutable patterns 2023-07-17 22:02:09 +00:00
slice-patterns-ambiguity.stderr add tests for refutable patterns 2023-07-17 22:02:09 +00:00
slice-patterns-irrefutable.rs address review 2023-07-28 11:20:11 +00:00
slice-patterns-irrefutable.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
slice-patterns-nested.rs add test for nested pattern 2023-07-17 22:06:32 +00:00
suggest-adding-appropriate-missing-pattern-excluding-comments.fixed Perform match checking on THIR. 2023-04-03 15:59:21 +00:00
suggest-adding-appropriate-missing-pattern-excluding-comments.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
suggest-adding-appropriate-missing-pattern-excluding-comments.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00