about summary refs log tree commit diff
path: root/compiler/rustc_pattern_analysis/src
AgeCommit message (Collapse)AuthorLines
2025-03-20Auto merge of #133889 - compiler-errors:inh-unstable, r=Nadrierilbors-2/+6
Consider fields to be inhabited if they are unstable Fixes #133885 with a simple heuristic r? Nadrieril Not totally certain if this needs T-lang approval or a crater run.
2025-03-20Auto merge of #137930 - nnethercote:use-Wunused-crate-dependencies, ↵bors-0/+1
r=jieyouxu,Nadrieril Use `Wunused-crate-dependencies` for the compiler An implementation of https://github.com/rust-lang/compiler-team/issues/844. r? `@jieyouxu`
2025-03-20Use `-Wunused_crate_dependencies` for compiler crates.Nicholas Nethercote-0/+1
It's very useful. There are some false positives involving integration tests in `rustc_pattern_analysis` and `rustc_serialize`. There is also a false positive involving `rustc_driver_impl`'s `rustc_randomized_layouts` feature. And I removed a `rustc_span` mention in a doc comment in `rustc_log` because it wasn't integral to the comment but caused a dev-dependency.
2025-03-19Rollup merge of #138001 - meithecatte:privately-uninhabited, r=NadrierilMatthias Krüger-3/+1
mir_build: consider privacy when checking for irrefutable patterns This PR fixes #137999. Note that, since this makes the compiler reject code that was previously accepted, it will probably need a crater run. I include a commit that factors out a common code pattern into a helper function, purely because the fact that this was repeated all over the place was bothering me. Let me know if I should split that into a separate PR instead.
2025-03-18Dont consider fields that are forced unstable due to ↵Michael Goulet-5/+5
-Zforce-unstable-if-unmarked to be uninhabited
2025-03-18Consider fields to be inhabited if they are unstableMichael Goulet-1/+5
2025-03-11Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.Nicholas Nethercote-1/+0
It's no longer necessary now that `-Wunreachable_pub` is being passed.
2025-03-10Revert "Use workspace lints for crates in `compiler/` #138084"许杰友 Jieyou Xu (Joe)-0/+1
Revert <https://github.com/rust-lang/rust/pull/138084> to buy time to consider options that avoids breaking downstream usages of cargo on distributed `rustc-src` artifacts, where such cargo invocations fail due to inability to inherit `lints` from workspace root manifest's `workspace.lints` (this is only valid for the source rust-lang/rust workspace, but not really the distributed `rustc-src` artifacts). This breakage was reported in <https://github.com/rust-lang/rust/issues/138304>. This reverts commit 48caf81484b50dca5a5cebb614899a3df81ca898, reversing changes made to c6662879b27f5161e95f39395e3c9513a7b97028.
2025-03-08Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.Nicholas Nethercote-1/+0
(Except for `rustc_codegen_cranelift`.) It's no longer necessary now that `unreachable_pub` is in the workspace lints.
2025-03-07Add helper methods checking for "#[non_exhaustive] that's active"Maja Kądziołka-3/+1
A check for `#[non_exhaustive]` is often done in combination with checking whether the type is local to the crate, in a variety of ways. Create a helper method and standardize on it as the way to check for this.
2025-02-22Greatly simplify lifetime captures in edition 2024Michael Goulet-36/+29
2025-02-17Add `pattern_complexity_limit` to `Limits`.Nicholas Nethercote-11/+16
It's similar to the other limits, e.g. obtained via `get_limit`. So it makes sense to handle it consistently with the other limits. We now use `Limit`/`usize` in most places instead of `Option<usize>`, so we use `Limit::new(usize::MAX)`/`usize::MAX` to emulate how `None` used to work. The commit also adds `Limit::unlimited`.
2025-01-20Get rid of mir::Const::from_ty_constMichael Goulet-3/+1
2025-01-11rename `BitSet` to `DenseBitSet`Rémy Rakic-9/+9
This should make it clearer that this bitset is dense, with the advantages and disadvantages that it entails.
2024-12-22Begin to implement type system layer of unsafe bindersMichael Goulet-0/+1
2024-11-23no more Reveal :(lcnr-0/+2
2024-11-23 thir building: use typing_env directlylcnr-25/+13
2024-11-20Rollup merge of #132708 - estebank:const-as-binding, r=NadrierilMatthias Krüger-1/+1
Point at `const` definition when used instead of a binding in a `let` statement Modify `PatKind::InlineConstant` to be `ExpandedConstant` standing in not only for inline `const` blocks but also for `const` items. This allows us to track named `const`s used in patterns when the pattern is a single binding. When we detect that there is a refutable pattern involving a `const` that could have been a binding instead, we point at the `const` item, and suggest renaming. We do this for both `let` bindings and `match` expressions missing a catch-all arm if there's at least one single binding pattern referenced. After: ``` error[E0005]: refutable pattern in local binding --> $DIR/bad-pattern.rs:19:13 | LL | const PAT: u32 = 0; | -------------- missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable ... LL | let PAT = v1; | ^^^ pattern `1_u32..=u32::MAX` not covered | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: the matched value is of type `u32` help: introduce a variable instead | LL | let PAT_var = v1; | ~~~~~~~ ``` Before: ``` error[E0005]: refutable pattern in local binding --> $DIR/bad-pattern.rs:19:13 | LL | let PAT = v1; | ^^^ | | | pattern `1_u32..=u32::MAX` not covered | missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable | help: introduce a variable instead: `PAT_var` | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: the matched value is of type `u32` ``` CC #132582.
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-12/+24
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-17Unify expanded constants and named constants in `PatKind`Esteban Küber-2/+2
2024-11-17Fold `PatKind::NamedConstant` into `PatKind::Constant`Esteban Küber-1/+1
2024-11-17Point at `const` definition when used instead of a binding in a `let` statementEsteban Küber-1/+1
After: ``` error[E0005]: refutable pattern in local binding --> $DIR/bad-pattern.rs:19:13 | LL | const PAT: u32 = 0; | -------------- missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable ... LL | let PAT = v1; | ^^^ | | | pattern `1_u32..=u32::MAX` not covered | help: introduce a variable instead: `PAT_var` | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: the matched value is of type `u32` ``` Before: ``` error[E0005]: refutable pattern in local binding --> $DIR/bad-pattern.rs:19:13 | LL | let PAT = v1; | ^^^ | | | pattern `1_u32..=u32::MAX` not covered | missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable | help: introduce a variable instead: `PAT_var` | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: the matched value is of type `u32` ```
2024-10-27compiler: Add rustc_abi dependence to the compilerJubilee Young-2/+2
Depend on rustc_abi in compiler crates that use it indirectly but have not yet taken on that dependency, and are not entangled in my other PRs. This leaves an "excise rustc_target" step after the dust settles.
2024-10-23nightly feature tracking: get rid of the per-feature bool fieldsRalf Jung-3/+3
2024-09-29cleanup: don't clone types that are CopyMatthias Krüger-4/+4
2024-09-28remove couple redundant clonesMatthias Krüger-1/+1
2024-09-23Rollup merge of #130715 - compiler-errors:mir-build-const-eval, r=BoxyUwUMatthias Krüger-4/+7
Replace calls to `ty::Const::{try_}eval` in mir build/pattern analysis We normalize consts in writeback: #130645. This means that consts are gonna be as normalized as they're ever gonna get in MIR building and pattern analysis. Therefore we can just use `try_to_target_usize` rather than calling `eval_target_usize`. Regarding the `.expect` calls, I'm not totally certain whether they're correct given rigid unevaluated consts. But this PR shouldn't make *more* ICEs occur; we may have to squash these ICEs when mGCE comes around, tho 😺
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-10/+10
2024-09-22Replace calls to Const::eval in mir buildMichael Goulet-4/+7
2024-09-11Revert warning empty patterns as unreachableNadrieril-1/+5
2024-09-03Rollup merge of #128934 - Nadrieril:fix-empty-non-exhaustive, r=compiler-errorsMatthias Krüger-7/+1
Non-exhaustive structs may be empty This is a follow-up to a discrepancy noticed in https://github.com/rust-lang/rust/pull/122792: today, the following struct is considered inhabited (non-empty) outside its defining crate: ```rust #[non_exhaustive] pub struct UninhabitedStruct { pub never: !, // other fields } ``` `#[non_exhaustive]` on a struct should mean that adding fields to it isn't a breaking change. There is no way that adding fields to this struct could make it non-empty since the `never` field must stay and is inconstructible. I suspect this was implemented this way due to confusion with `#[non_exhaustive]` enums, which indeed should be considered non-empty outside their defining crate. I propose that we consider such a struct uninhabited (empty), just like it would be without the `#[non_exhaustive]` annotation. Code that doesn't pass today and will pass after this: ```rust // In a different crate fn empty_match_on_empty_struct<T>(x: UninhabitedStruct) -> T { match x {} } ``` This is not a breaking change. r? ``@compiler-errors``
2024-09-02Non-exhaustive structs may be emptyNadrieril-7/+1
2024-09-02chore: Fix typos in 'compiler' (batch 2)Alexander Cyon-1/+1
2024-08-29Add `warn(unreachable_pub)` to `rustc_pattern_analysis`.Nicholas Nethercote-0/+1
2024-08-15Rollup merge of #128965 - Zalathar:no-pat, r=NadrierilJubilee-112/+60
Remove `print::Pat` from the printing of `WitnessPat` After the preliminary work done in #128536, we can now get rid of `print::Pat` entirely. - First, we introduce a variant `PatKind::Print(String)`. - Then we incrementally remove each other variant of `PatKind`, by having the relevant code produce `PatKind::Print` instead. - Once `PatKind::Print` is the only remaining variant, it becomes easy to remove `print::Pat` and replace it with `String`. There is more cleanup that I have in mind, but this seemed like a natural stopping point for one PR. r? ```@Nadrieril```
2024-08-14Auto merge of #128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errorsbors-1/+1
Shrink `TyKind::FnPtr`. By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI. r? `@compiler-errors`
2024-08-11Remove `print::Pat` entirely, replacing it with `String`Zalathar-69/+35
2024-08-11Remove `PatKind::Never`Zalathar-4/+1
2024-08-11Remove `PatKind::Slice`Zalathar-17/+8
2024-08-11Remove `PatKind::Range`Zalathar-5/+1
2024-08-11Remove `PatKind::Constant`Zalathar-9/+4
2024-08-11Remove `PatKind::Ref`Zalathar-7/+7
2024-08-11Remove `PatKind::Box`Zalathar-6/+1
2024-08-11Remove `PatKind::StructLike`Zalathar-10/+11
2024-08-11Remove `PatKind::Wild`Zalathar-5/+4
2024-08-11Add `print::PatKind::Print`Zalathar-0/+3
This will allow for the gradual removal of all other variants.
2024-08-11Avoid matching on `PatKind::Wild` in `write_struct_like`Zalathar-5/+10
2024-08-11Rollup merge of #128536 - Zalathar:print-cleanup, r=NadrierilMatthias Krüger-185/+216
Preliminary cleanup of `WitnessPat` hoisting/printing Follow-up to #128430. The eventual goal is to remove `print::Pat` entirely, but in the course of working towards that I made so many small improvements that it seems wise to let those be reviewed/merged on their own first. Best reviewed commit-by-commit, most of which should be pretty simple and straightforward. r? ``@Nadrieril``
2024-08-10Stabilize `min_exhaustive_patterns`Nadrieril-19/+8
2024-08-09Shrink `TyKind::FnPtr`.Nicholas Nethercote-1/+1
By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI.