about summary refs log tree commit diff
path: root/compiler/rustc_pattern_analysis/src/rustc.rs
AgeCommit message (Collapse)AuthorLines
2024-07-31Use a separate pattern type for `rustc_pattern_analysis` diagnosticsZalathar-11/+15
The pattern-analysis code needs to print patterns, as part of its user-visible diagnostics. But it never actually tries to print "real" patterns! Instead, it only ever prints synthetic patterns that it has reconstructed from its own internal represenations. We can therefore simultaneously remove two obstacles to changing `thir::Pat`, by having the pattern-analysis code use its own dedicated type for building printable patterns, and then making `thir::Pat` not printable at all.
2024-07-31Print `thir::PatRange`, not its surrounding `thir::Pat`Zalathar-8/+7
This further reduces the amount of code that relies on `thir::Pat` being printable.
2024-07-29Rollup merge of #128304 - Zalathar:thir-pat-display, r=NadrierilMatthias Krüger-8/+16
Isolate the diagnostic code that expects `thir::Pat` to be printable Currently, `thir::Pat` implements `fmt::Display` (and `IntoDiagArg`) directly, for use by a few diagnostics. That makes it tricky to experiment with alternate representations for THIR patterns, because the patterns currently need to be printable on their own. That immediately rules out possibilities like storing subpatterns as a `PatId` index into a central list (instead of the current directly-owned `Box<Pat>`). This PR therefore takes an incremental step away from that obstacle, by removing `thir::Pat` from diagnostic structs in `rustc_pattern_analysis`, and hiding the pattern-printing process behind a single public `Pat::to_string` method. Doing so makes it easier to identify and update the code that wants to print patterns, and gives a place to pass in additional context in the future if necessary. --- I'm currently not sure whether switching over to `PatId` is actually desirable or not, but I think this change makes sense on its own merits, by reducing the coupling between `thir::Pat` and the pattern-analysis error types.
2024-07-29Encapsulate the printing of `WitnessPat`Zalathar-3/+11
This hides the fact that we print `WitnessPat` by converting it to `thir::Pat` and then printing that.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-2/+1
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-28Don't store `thir::Pat` in error structsZalathar-5/+5
In several cases this avoids the need to clone the underlying pattern, and then print the clone later.
2024-07-24Explain why a given pattern is considered unreachableNadrieril-0/+2
2024-07-24Move rustc-specific entrypoint to the `rustc` moduleNadrieril-0/+26
2024-07-21Tweak `collect_non_exhaustive_tys`Nadrieril-1/+7
2024-07-18pattern lowering: make sure we never call user-defined PartialEq instancesRalf Jung-4/+14
2024-06-23Replace `f16` and `f128` pattern matching stubs with real implementationsTrevor Gross-7/+43
This section of code depends on `rustc_apfloat` rather than our internal types, so this is one potential ICE that we should be able to melt now. This also fixes some missing range and match handling in `rustc_middle`.
2024-06-10ScalarInt: size mismatches are a bug, do not delay the panicRalf Jung-4/+5
2024-06-05Add `Ty` to `mir::Const::Ty`Boxy-1/+1
2024-04-29Remove `extern crate rustc_middle` from numerous crates.Nicholas Nethercote-0/+1
2024-04-08Actually create ranged int types in the type system.Oli Scherer-0/+1
2024-03-31Improve debugging experienceNadrieril-2/+0
2024-03-22Programmatically convert some of the pat ctorsMichael Goulet-1/+1
2024-03-21Rollup merge of #122644 - Nadrieril:complexity-tests, r=compiler-errorsMatthias Krüger-3/+4
pattern analysis: add a custom test harness There are two features of the pattern analysis code that are hard to test: the newly-added pattern complexity limit, and the computation of arm intersections. This PR adds some crate-specific tests for that, including an unmaintainable but pretty macro to help construct patterns. r? `````@compiler-errors`````
2024-03-20Add barest-bones deref patternsNadrieril-0/+6
Co-authored-by: Deadbeef <ent3rm4n@gmail.com>
2024-03-19Improve the `WitnessPat: Debug` implNadrieril-3/+4
2024-03-18Rollup merge of #121823 - Nadrieril:never-witnesses, r=compiler-errorsMatthias Krüger-3/+4
never patterns: suggest `!` patterns on non-exhaustive matches When a match is non-exhaustive we now suggest never patterns whenever it makes sense. r? ``@compiler-errors``
2024-03-13Rollup merge of #122437 - Nadrieril:no-after-max, r=compiler-errorsMatthias Krüger-1/+1
pattern analysis: remove `MaybeInfiniteInt::JustAfterMax` It was inherited from before half-open ranges, but it doesn't pull its weight anymore. We lose a tiny bit of diagnostic precision as can be seen in the test. I'm generally in favor of half-open ranges over explicit `x..=MAX` ranges anyway.
2024-03-13Remove `MaybeInfiniteInt::JustAfterMax`Nadrieril-1/+1
It was inherited from before half-open ranges, but it doesn't pull its weight anymore. We lose a tiny bit of diagnostic precision.
2024-03-13Rename `RustcMatchCheckCtxt` -> `RustcPatCtxt`Nadrieril-23/+18
2024-03-13Rename `TypeCx` -> `PatCx`Nadrieril-2/+2
2024-03-12Add `Constructor::Never`Nadrieril-3/+4
2024-03-11`DeconstructedPat.data` is always present nowNadrieril-4/+4
2024-03-11Store field indices in `DeconstructedPat` to avoid virtual wildcardsNadrieril-23/+26
2024-03-11Store pattern arity in `DeconstructedPat`Nadrieril-3/+20
Right now this is just `self.fields.len()` but that'll change in the next commit. `arity` will be useful for the `Debug` impl.
2024-03-09Lint small gaps between rangesNadrieril-1/+65
2024-03-09Make `MaybeInfiniteInt::plus_one/minus_one` fallibleNadrieril-3/+3
2024-03-03Add new `pattern_complexity` attribute to add possibility to limit and check ↵Guillaume Gomez-0/+5
recursion in pattern matching
2024-03-01Auto merge of #121728 - tgross35:f16-f128-step1-ty-updates, r=compiler-errorsbors-0/+2
Add stubs in IR and ABI for `f16` and `f128` This is the very first step toward the changes in https://github.com/rust-lang/rust/pull/114607 and the [`f16` and `f128` RFC](https://rust-lang.github.io/rfcs/3453-f16-and-f128.html). It adds the types to `rustc_type_ir::FloatTy` and `rustc_abi::Primitive`, and just propagates those out as `unimplemented!` stubs where necessary. These types do not parse yet so there is no feature gate, and it should be okay to use `unimplemented!`. The next steps will probably be AST support with parsing and the feature gate. r? `@compiler-errors` cc `@Nilstrieb` suggested breaking the PR up in https://github.com/rust-lang/rust/pull/120645#issuecomment-1925900572
2024-02-28Add `f16` and `f128` to `rustc_type_ir::FloatTy` and `rustc_abi::Primitive`Trevor Gross-0/+2
Make changes necessary to support these types in the compiler.
2024-02-28Rename `Skip` to `PrivateUninhabited`Nadrieril-10/+13
2024-02-28SimplifyNadrieril-46/+34
2024-02-28Don't filter out skipped fieldsNadrieril-10/+5
2024-02-28Add special `Skip` constructorNadrieril-21/+5
2024-02-28Push the decision to skip fields further downNadrieril-7/+9
2024-02-28Push down the decision to skip fieldsNadrieril-16/+22
2024-02-12Dejargnonize substShoyu Vanilla-1/+1
2024-02-06Rollup merge of #120331 - Nadrieril:no-arena, r=compiler-errorsMatthias Krüger-40/+29
pattern_analysis: use a plain `Vec` in `DeconstructedPat` The use of an arena-allocated slice in `DeconstructedPat` dates to when we needed the arena anyway for lifetime reasons. Now that we don't, I'm thinking that if `thir::Pat` can use plain old `Vec`s, maybe so can I. r? ```@ghost```
2024-02-06Add CoroutineClosure to TyKind, AggregateKind, UpvarArgsMichael Goulet-1/+2
2024-02-05Auto merge of #120313 - Nadrieril:graceful-error, r=compiler-errorsbors-1/+1
pattern_analysis: Gracefully abort on type incompatibility This leaves the option for a consumer of the crate to return `Err` instead of panicking on type error. rust-analyzer could use that (e.g. https://github.com/rust-lang/rust-analyzer/issues/15808). Since the only use of `TypeCx::bug` is in `Constructor::is_covered_by`, it is tempting to return `false` instead of `Err()`, but that would cause "non-exhaustive match" false positives. r? `@compiler-errors`
2024-02-03Rollup merge of #120517 - Nadrieril:lower-never-as-wildcard, r=compiler-errorsMatthias Krüger-2/+3
never patterns: It is correct to lower `!` to `_`. This is just a comment update but a non-trivial one: it is correct to lower `!` patterns as `_`. The reasoning is that `!` matches all the possible values of the type, since the type is empty. Moreover, we do want to warn that the `Err` is redundant in: ```rust match x { !, Err(!), } ``` which is consistent with `!` behaving like a wildcard. I did try to introduce `Constructor::Never` and it ended up needing to behave exactly like `Constructor::Wildcard`. r? ```@compiler-errors```
2024-01-31Remove `pattern_arena` from `RustcMatchCheckCtxt`Nadrieril-7/+5
2024-01-31Use a `Vec` instead of a slice in `DeconstructedPat`Nadrieril-33/+24
2024-01-31Gracefully abort on type incompatibilityNadrieril-1/+1
Since the only use of `TypeCx::bug` is in `Constructor::is_covered_by`, it is tempting to return `false` instead of `Err()`, but that would cause "non-exhaustive match" false positives.
2024-01-31It is correct to lower `!` to `_`.Nadrieril-2/+3
2024-01-30Limit the use of `PlaceCtxt`Nadrieril-1/+0