about summary refs log tree commit diff
path: root/compiler/rustc_pattern_analysis
AgeCommit message (Collapse)AuthorLines
2024-07-24Move rustc-specific entrypoint to the `rustc` moduleNadrieril-34/+29
2024-07-23Auto merge of #128015 - Nadrieril:two-step-or-expansion, r=compiler-errorsbors-107/+86
match exhaustiveness: Expand or-patterns as a separate step To compute exhaustiveness, we must expand or-patterns. Previously, we expanded them at the same time that we pushed patterns into the matrix. This made it harder to track pattern reachability, because the or-pattern itself would never show up in the matrix so we had to recover missing information. This PR changes that: we no longer expand or-patterns as we push them into the matrix. Instead, if we find an or-pattern in the matrix we expand them in a step very much like the specialization we already do. This simplifies a bunch of things, and should greatly simplify the implementation of https://github.com/rust-lang/rust/issues/127870. r? `@compiler-errors`
2024-07-21Tweak `collect_non_exhaustive_tys`Nadrieril-1/+7
2024-07-20Expand or-patterns as a separate stepNadrieril-107/+86
2024-07-19Avoid ref when using format! in compilerYuri Astrakhan-1/+1
Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing). Inlining format args prevents accidental `&` misuse.
2024-07-18pattern lowering: make sure we never call user-defined PartialEq instancesRalf Jung-4/+14
2024-07-17Avoid comments that describe multiple `use` items.Nicholas Nethercote-3/+1
There are some comments describing multiple subsequent `use` items. When the big `use` reformatting happens some of these `use` items will be reordered, possibly moving them away from the comment. With this additional level of formatting it's not really feasible to have comments of this type. This commit removes them in various ways: - merging separate `use` items when appropriate; - inserting blank lines between the comment and the first `use` item; - outright deletion (for comments that are relatively low-value); - adding a separate "top-level" comment. We also entirely skip formatting for four library files that contain nothing but `pub use` re-exports, where reordering would be painful.
2024-06-23Replace `f16` and `f128` pattern matching stubs with real implementationsTrevor Gross-8/+69
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-20Add blank lines after module-level `//!` comments.Nicholas Nethercote-0/+4
Most modules have such a blank line, but some don't. Inserting the blank line makes it clearer that the `//!` comments are describing the entire module, rather than the `use` declaration(s) that immediately follows.
2024-06-12Use `tidy` to sort crate attributes for all compiler crates.Nicholas Nethercote-1/+3
We already do this for a number of crates, e.g. `rustc_middle`, `rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`. For the ones we don't, in many cases the attributes are a mess. - There is no consistency about order of attribute kinds (e.g. `allow`/`deny`/`feature`). - Within attribute kind groups (e.g. the `feature` attributes), sometimes the order is alphabetical, and sometimes there is no particular order. - Sometimes the attributes of a particular kind aren't even grouped all together, e.g. there might be a `feature`, then an `allow`, then another `feature`. This commit extends the existing sorting to all compiler crates, increasing consistency. If any new attribute line is added there is now only one place it can go -- no need for arbitrary decisions. Exceptions: - `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`, because they have no crate attributes. - `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's ignored in `rustfmt.toml`).
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-05-30remove tracing tree indent lineslcnr-1/+0
2024-05-23Remove `LintDiagnostic::msg`León Orell Valerian Liehr-1/+0
* instead simply set the primary message inside the lint decorator functions * it used to be this way before [#]101986 which introduced `msg` to prevent good path delayed bugs (which no longer exist) from firing under certain circumstances when lints were suppressed / silenced * this is no longer necessary for various reasons I presume * it shaves off complexity and makes further changes easier to implement
2024-05-02Stabilize exclusive_rangeRoss Smyth-1/+0
2024-04-30Remove `extern crate tracing` from numerous crates.Nicholas Nethercote-12/+8
2024-04-29Remove `extern crate rustc_middle` from numerous crates.Nicholas Nethercote-3/+1
2024-04-21Pass translation closure to add_to_diag_with() as referenceXiretza-2/+2
2024-04-08Actually create ranged int types in the type system.Oli Scherer-0/+1
2024-04-01Fix union handling in exhaustivenessNadrieril-6/+57
2024-03-31Improve debugging experienceNadrieril-7/+10
2024-03-31Rollup merge of #123242 - Nadrieril:require-contiguous-enum-indices, ↵Matthias Krüger-52/+8
r=compiler-errors pattern analysis: Require enum indices to be contiguous We had a cfg-hack to allow rust-analyzer to use non-contiguous indices for its enum variants. Unfortunately this no longer works if r-a uses the in-tree version of the crate. This PR removes the hack, and on the r-a side we'll have to use contiguous indices but that's not too hard. r? `@compiler-errors`
2024-03-30Require enum indices to be contiguousNadrieril-52/+8
2024-03-30bump tracing-tree to 0.3klensy-1/+1
Only change is https://github.com/davidbarsky/tracing-tree/pull/76 dedupes tracing-log dupes nu-ansi-term
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-80/+690
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-19Add a crate-custom test harnessNadrieril-0/+580
2024-03-19Improve the `WitnessPat: Debug` implNadrieril-76/+89
2024-03-19Report arm intersectionsNadrieril-4/+21
2024-03-18Rollup merge of #121823 - Nadrieril:never-witnesses, r=compiler-errorsMatthias Krüger-12/+55
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-9/+6
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-9/+6
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-32/+27
2024-03-13Rename `TypeCx` -> `PatCx`Nadrieril-68/+68
2024-03-13Rename `ValidityConstraint` -> `PlaceValidity`Nadrieril-20/+12
The old name came from a time where I wanted to reuse it for differentiating wildcards from bindings. I don't plan to do this anymore.
2024-03-12Don't suggest an arm when suggesting a never patternNadrieril-0/+8
2024-03-12Suggest never pattern instead of `_` for empty typesNadrieril-4/+32
2024-03-12Add `Constructor::Never`Nadrieril-8/+15
2024-03-11`DeconstructedPat.data` is always present nowNadrieril-13/+11
2024-03-11Store field indices in `DeconstructedPat` to avoid virtual wildcardsNadrieril-80/+96
2024-03-11Store pattern arity in `DeconstructedPat`Nadrieril-7/+36
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-11Rename `DecorateLint` as `LintDiagnostic`.Nicholas Nethercote-1/+1
To match `derive(LintDiagnostic)`.
2024-03-11Rename `AddToDiagnostic` as `Subdiagnostic`.Nicholas Nethercote-5/+5
To match `derive(Subdiagnostic)`. Also rename `add_to_diagnostic{,_with}` as `add_to_diag{,_with}`.
2024-03-09Lint small gaps between rangesNadrieril-12/+182
2024-03-09Make `MaybeInfiniteInt::plus_one/minus_one` fallibleNadrieril-20/+23
2024-03-05Rollup merge of #121987 - Nadrieril:abort-on-arity-mismatch, r=compiler-errorsMatthias Krüger-7/+15
pattern analysis: abort on arity mismatch This is one more PR replacing panics by `Err()` aborts. I recently audited all the `unwrap()` calls, but I had forgotten about array accesses. (Again [discovered by rust-analyzer](https://github.com/rust-lang/rust-analyzer/issues/16746)). r? ```@compiler-errors```
2024-03-05Rename `SubdiagnosticMessageOp` as `SubdiagMessageOp`.Nicholas Nethercote-2/+2
2024-03-04Abort on arity mismatchNadrieril-7/+15
As this can cause panics on array accesses later.
2024-03-03Add new `pattern_complexity` attribute to add possibility to limit and check ↵Guillaume Gomez-2/+34
recursion in pattern matching