Commit Graph

41 Commits

Author SHA1 Message Date
Nadrieril 2a87bae48d Reveal opaque types in exhaustiveness checking 2023-12-20 14:43:00 +01:00
Nadrieril 7e4924b55d Add tests 2023-12-20 14:43:00 +01:00
Nadrieril ddef5b61f1 Don't warn an empty pattern unreachable if we're not sure the data is valid 2023-12-09 00:44:49 +01:00
Nadrieril 4e376cc104 Test empty types better 2023-12-09 00:39:59 +01:00
Nadrieril 5e470db05c Remove the precise_pointer_size_matching feature gate 2023-12-04 11:56:21 +01:00
bors ee80c8d0a8 Auto merge of #117611 - Nadrieril:linear-pass-take-4, r=cjgillot
Rewrite exhaustiveness in one pass

This is at least my 4th attempt at this in as many years x) Previous attempts were all too complicated or too slow. But we're finally here!

The previous version of the exhaustiveness algorithm computed reachability for each arm then exhaustiveness of the whole match. Since each of these steps does roughly the same things, this rewrites the algorithm to do them all in one go. I also think this makes things much simpler.

I also rewrote the documentation of the algorithm in depth. Hopefully it's up-to-date and easier to follow now. Plz comment if anything's unclear.

r? `@oli-obk` I think you're one of the rare other people to understand the exhaustiveness algorithm?

cc `@varkor` I know you're not active anymore, but if you feel like having a look you might enjoy this :D

Fixes https://github.com/rust-lang/rust/issues/79307
2023-11-26 00:14:14 +00:00
Nilstrieb 41e8d152dc Show number in error message even for one error
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-24 19:15:52 +01:00
Nadrieril cc6936d577 Fully rework the algorithm and its explanation 2023-11-22 03:25:15 +01:00
Nadrieril d744aecabf Keep rows with guards in the matrix 2023-11-22 03:25:15 +01:00
Nadrieril 98ac114847 Add some tests 2023-11-22 02:14:42 +01:00
bors fdaaaf9f92 Auto merge of #116930 - RalfJung:raw-ptr-match, r=davidtwco
patterns: reject raw pointers that are not just integers

Matching against `0 as *const i32` is fine, matching against `&42 as *const i32` is not.

This extends the existing check against function pointers and wide pointers: we now uniformly reject all these pointer types during valtree construction, and then later lint because of that. See [here](https://github.com/rust-lang/rust/pull/116930#issuecomment-1784654073) for some more explanation and context.

Also fixes https://github.com/rust-lang/rust/issues/116929.

Cc `@oli-obk` `@lcnr`
2023-11-08 20:42:32 +00:00
Nadrieril 746197c08a Tweak spans for "adt defined here" note 2023-11-03 18:26:16 +01:00
Nadrieril c19856929d Always do all the pattern checks 2023-11-02 03:19:19 +01:00
Nadrieril b60f08a66d Add regression test for pattern checks 2023-11-02 03:19:19 +01:00
Nadrieril d95f6a9532 Tweak diagnostic for consistency 2023-11-02 03:19:19 +01:00
Ralf Jung 70a8e157ab make pointer_structural_match warn-by-default 2023-10-28 17:02:18 +02:00
Nadrieril a4875ae1e2 Match usize/isize exhaustively 2023-10-27 19:56:12 +02:00
Nadrieril 11268b48a1 Add tests 2023-10-27 19:56:12 +02:00
Nadrieril d5070e32ea Lint overlapping ranges as a separate pass 2023-10-27 05:16:26 +02:00
Nadrieril 89f75ff4d0 Skip most of check_match checks in the presence of PatKind::Error 2023-10-14 13:38:04 +02:00
bors e20cb77021 Auto merge of #116391 - Nadrieril:constructorset, r=cjgillot
exhaustiveness: Rework constructor splitting

`SplitWildcard` was pretty opaque. I replaced it with a more legible abstraction: `ConstructorSet` represents the set of constructors for patterns of a given type. This clarifies responsibilities: `ConstructorSet` handles one clear task, and diagnostic-related shenanigans can be done separately.

I'm quite excited, I had has this in mind for years but could never quite introduce it. This opens up possibilities, including type-specific optimisations (like using a `FxHashSet` to collect enum variants, which had been [hackily attempted some years ago](https://github.com/rust-lang/rust/pull/76918)), my one-pass rewrite (https://github.com/rust-lang/rust/pull/116042), and future librarification.
2023-10-12 21:33:31 +00:00
Oli Scherer d1fd11f3f9 Prevent spurious unreachable pattern lints
Means you'll get more `non-exhaustive` patterns
2023-10-11 12:49:57 +00:00
Nadrieril c1b29b338d Fix handling slices of empty types 2023-10-05 00:58:14 +02:00
Nadrieril fac50e8fb3 Evaluate float consts eagerly 2023-10-01 00:00:37 +02:00
Sebastian Toh d87b87d10e Improve clarity of diagnostic message on non-exhaustive matches 2023-09-03 19:55:11 +08:00
Sebastian Toh 43dd8613a3 Add note when matching on nested non-exhaustive enums 2023-08-28 14:50:32 +08:00
Sebastian Toh a293619caa Add note that str cannot be matched exhaustively 2023-08-28 13:02:37 +08:00
Sebastian Toh 82ce7b1461 Add note when matching on tuples/ADTs containing non-exhaustive types 2023-08-21 11:18:20 +08:00
Eric Mark Martin e79b179412 add comment back 2023-06-28 01:51:53 -04:00
Eric Mark Martin fbd1e0252f add note for non-exhaustive matches with guards 2023-06-28 01:51:53 -04:00
Camille GILLOT ee27c49dfc Add NOTE annotations. 2023-05-25 18:17:02 +00:00
Camille GILLOT 320f6f43f6 Add inter-crate test. 2023-05-25 17:04:14 +00:00
Oli Scherer ad424e65d8 Always fall back to PartialEq when a constant in a pattern is not recursively structural-eq 2023-05-15 14:20:31 +00:00
Camille GILLOT 4f97540432 Reinstate confusion note. 2023-04-03 15:59:21 +00:00
Camille GILLOT 05082f57af Perform match checking on THIR. 2023-04-03 15:59:21 +00:00
Jamen Marz 73c34cbaf7 Add notes to non-structural const in pattern error message 2023-03-27 11:08:11 -04:00
mejrs 372ac9c1a2 Translate Overlap eagerly 2023-01-11 14:40:13 -08:00
mejrs 8476c517c0 Don't recommend if let if let else works 2023-01-11 14:40:07 -08:00
mejrs 31c20210b9 Migrate pattern matching 2023-01-11 14:40:02 -08:00
mejrs 5d2b9a9ed0 Migrate deconstruct_pat.rs 2023-01-11 14:39:49 -08:00
Albert Larsan cf2dff2b1e Move /src/test to /tests 2023-01-11 09:32:08 +00:00