about summary refs log tree commit diff
path: root/compiler/rustc_pattern_analysis/src/rustc.rs
AgeCommit message (Collapse)AuthorLines
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
2024-01-30Make `PatternColumn` generic in `Cx`Nadrieril-4/+0
2024-01-27Stop using derivative in rustc_pattern_analysisLaurențiu Nicola-2/+6
2024-01-26Rollup merge of #118803 - Nadrieril:min-exhaustive-patterns, r=compiler-errorsMatthias Krüger-1/+6
Add the `min_exhaustive_patterns` feature gate ## Motivation Pattern-matching on empty types is tricky around unsafe code. For that reason, current stable rust conservatively requires arms for empty types in all but the simplest case. It has long been the intention to allow omitting empty arms when it's safe to do so. The [`exhaustive_patterns`](https://github.com/rust-lang/rust/issues/51085) feature allows the omission of all empty arms, but hasn't been stabilized because that was deemed dangerous around unsafe code. ## Proposal This feature aims to stabilize an uncontroversial subset of exhaustive_patterns. Namely: when `min_exhaustive_patterns` is enabled and the data we're matching on is guaranteed to be valid by rust's operational semantics, then we allow empty arms to be omitted. E.g.: ```rust let x: Result<T, !> = foo(); match x { // ok Ok(y) => ..., } let Ok(y) = x; // ok ``` If the place is not guaranteed to hold valid data (namely ptr dereferences, ref dereferences (conservatively) and union field accesses), then we keep stable behavior i.e. we (usually) require arms for the empty cases. ```rust unsafe { let ptr: *const Result<u32, !> = ...; match *ptr { Ok(x) => { ... } Err(_) => { ... } // still required } } let foo: Result<u32, &!> = ...; match foo { Ok(x) => { ... } Err(&_) => { ... } // still required because of the dereference } unsafe { let ptr: *const ! = ...; match *ptr {} // already allowed on stable } ``` Note that we conservatively consider that a valid reference can point to invalid data, hence we don't allow arms of type `&!` and similar cases to be omitted. This could eventually change depending on [opsem decisions](https://github.com/rust-lang/unsafe-code-guidelines/issues/413). Whenever opsem is undecided on a case, we conservatively keep today's stable behavior. I proposed this behavior in the [`never_patterns`](https://github.com/rust-lang/rust/issues/118155) feature gate but it makes sense on its own and could be stabilized more quickly. The two proposals nicely complement each other. ## Unresolved Questions Part of the question is whether this requires an RFC. I'd argue this doesn't need one since there is no design question beyond the intent to omit unreachable patterns, but I'm aware the problem can be framed in ways that require design (I'm thinking of the [original never patterns proposal](https://smallcultfollowing.com/babysteps/blog/2018/08/13/never-patterns-exhaustive-matching-and-uninhabited-types-oh-my/), which would frame this behavior as "auto-nevering" happening). EDIT: I initially proposed a future-compatibility lint as part of this feature, I don't anymore.
2024-01-25Rollup merge of #120318 - Nadrieril:share-debug-impl, r=compiler-errorsMatthias Krüger-99/+11
pattern_analysis: Reuse most of the `DeconstructedPat` `Debug` impl The `DeconstructedPat: Debug` is best-effort because we'd need `tcx` to get things like field names etc. Since rust-analyzer has a similar constraint, this PR moves most the impl to be shared between the two. While I was at it I also fixed a nit in the `IntRange: Debug` impl. r? `@compiler-errors`
2024-01-25Implement feature gate logicNadrieril-1/+6
2024-01-24Most of the `DeconstructedPat` `Debug` impl is reusableNadrieril-99/+11
2024-01-24Let `ctor_sub_tys` return any Iterator they wantNadrieril-13/+13
Since we always clone and allocate the types somewhere else ourselves, no need to ask for `Cx` to do the allocation.
2024-01-23Rename `TyCtxt::emit_spanned_lint` as `TyCtxt::emit_node_span_lint`.Nicholas Nethercote-1/+1
2024-01-20Remove Ty: Copy boundNadrieril-10/+10
2024-01-15Remove the unused `overlapping_range_endpoints` VecNadrieril-2/+0
2024-01-15Lint overlapping ranges directly from exhaustivenessNadrieril-8/+27
2024-01-12rustc_pattern_analysis no longer needs to be passed an arenaNadrieril-2/+4
2024-01-11Factor out collection of overlapping rangesNadrieril-0/+2