about summary refs log tree commit diff
path: root/compiler/rustc_pattern_analysis/src
AgeCommit message (Collapse)AuthorLines
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-30Require enum indices to be contiguousNadrieril-52/+8
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/+116
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/+6
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/+174
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
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-29Rollup merge of #121000 - Nadrieril:keep_all_fields, r=compiler-errorsGuillaume Gomez-88/+98
pattern_analysis: rework how we hide empty private fields Consider this: ```rust mod foo { pub struct Bar { pub a: bool, b: !, } } fn match_a_bar(bar: foo::Bar) -> bool { match bar { Bar { a, .. } => a, } } ``` Because the field `b` is private, matches outside the module are not allowed to observe the fact that `Bar` is empty. In particular `match bar {}` is valid within the module `foo` but an error outside (assuming `exhaustive_patterns`). We currently handle this by hiding the field `b` when it's both private and empty. This means that the pattern `Bar { a, .. }` is lowered to `Bar(a, _)` if we're inside of `foo` and to `Bar(a)` outside. This involves a bit of a dance to keep field indices straight. But most importantly this makes pattern lowering depend on the module. In this PR, I instead do nothing special when lowering. Only during analysis do we track whether a place must be skipped. r? `@compiler-errors`
2024-02-29Rollup merge of #121735 - Nadrieril:no-panic-on-type-error, r=compiler-errorsMatthias Krüger-4/+4
pattern analysis: Don't panic when encountering unexpected constructor Tiny PR to fix https://github.com/rust-lang/rust-analyzer/issues/16656 r? ``@compiler-errors``
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-33/+38
2024-02-28SimplifyNadrieril-46/+34
2024-02-28Don't filter out skipped fieldsNadrieril-22/+28
2024-02-28Add special `Skip` constructorNadrieril-22/+15
2024-02-28Push the decision to skip fields further downNadrieril-14/+26
2024-02-28Push down the decision to skip fieldsNadrieril-16/+22
2024-02-28Don't panic when encountering unexpected constructorNadrieril-4/+4
2024-02-28Rename `DiagnosticBuilder` as `Diag`.Nicholas Nethercote-2/+2
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
2024-02-25Rollup merge of #121324 - Nadrieril:unspecialize, r=cjgillotMatthias Krüger-15/+21
pattern_analysis: factor out unspecialization Just moving a dense bit of logic into its own method.
2024-02-23compiler: clippy::complexity fixesMatthias Krüger-10/+6
2024-02-20Auto merge of #120576 - nnethercote:merge-Diagnostic-DiagnosticBuilder, ↵bors-2/+6
r=davidtwco Overhaul `Diagnostic` and `DiagnosticBuilder` Implements the first part of https://github.com/rust-lang/compiler-team/issues/722, which moves functionality and use away from `Diagnostic`, onto `DiagnosticBuilder`. Likely follow-ups: - Move things around, because this PR was written to minimize diff size, so some things end up in sub-optimal places. E.g. `DiagnosticBuilder` has impls in both `diagnostic.rs` and `diagnostic_builder.rs`. - Rename `Diagnostic` as `DiagInner` and `DiagnosticBuilder` as `Diag`. r? `@davidtwco`