298 Commits

Author SHA1 Message Date
León Orell Valerian Liehr
26f3337d4e
Remove DynKind 2025-09-17 04:46:46 +02:00
Nicholas Nethercote
301655eafe Revert introduction of [workspace.dependencies].
This was done in #145740 and #145947. It is causing problems for people
using r-a on anything that uses the rustc-dev rustup package, e.g. Miri,
clippy.

This repository has lots of submodules and subtrees and various
different projects are carved out of pieces of it. It seems like
`[workspace.dependencies]` will just be more trouble than it's worth.
2025-09-02 19:12:54 +10:00
Nicholas Nethercote
2b26476ccd Add rustc-hash to [workspace.dependencies]. 2025-08-28 20:11:43 +10:00
Nicholas Nethercote
ce02d34b2f Add rustc_apfloat to [workspace.dependencies]. 2025-08-28 20:10:55 +10:00
Nicholas Nethercote
c50d2cc807 Add tracing to [workspace.dependencies]. 2025-08-27 14:21:19 +10:00
Samuel Tardieu
5a14685a63
Rollup merge of #145234 - dianne:1-tuple-witnesses, r=jackh726
match exhaustiveness diagnostics: show a trailing comma on singleton tuple consructors in witness patterns (and clean up a little)

Constructor patterns of type `(T,)` are written `(pat,)`, not `(pat)`. However, exhaustiveness/usefulness diagnostics would print them as `(pat)` when e.g. providing a witness of non-exhaustiveness and suggesting adding arms to make matches exhaustive; this would result in an error when applied.
rust-analyzer already prints the trailing comma, so it doesn't need changing.

This also includes some cleanup in the second commit, with justification in the commit message.
2025-08-23 22:22:15 +02:00
Ralf Jung
e2cc7757e1 avoid unnecessary type sanity checks 2025-08-14 09:44:22 +02:00
Ralf Jung
dbc030e034 shrink TestBranch::Constant and PatRangeBoundary::Finite 2025-08-14 09:44:22 +02:00
Ralf Jung
a1acbfb050 change StrLit type to ty::Value as well 2025-08-14 09:44:22 +02:00
Ralf Jung
a171eaab42 use ty::Value instead of manual pairs of types and valtrees 2025-08-14 09:44:22 +02:00
Ralf Jung
d61fdbf266 pattern testing: store constants as valtrees 2025-08-14 09:44:19 +02:00
Ralf Jung
3f1e99dca4 PatKind: store constants as valtrees 2025-08-14 09:39:39 +02:00
dianne
8f649a7e58 clean up witness printing for tuple-like constructors
By construction, `subpatterns` contains all fields in order. Witness
patterns are constructed with all fields in order by
`WitnessPat::wild_from_ctor` and `WitnessStack::apply_constructor`, and
the order is preserved at `write_struct_like`'s call-site in
`print_witness_pat`. It's thus no longer necessary to go looking for
fields or handle missing fields.
2025-08-10 16:34:11 -07:00
dianne
9449b78621 show a trailing comma on singleton tuple constructors in witness pats 2025-08-10 15:32:14 -07:00
Trevor Gross
18abf3aa44
Rollup merge of #144545 - ChayimFriedman2:bool-witness-order, r=Nadrieril
In rustc_pattern_analysis, put `true` witnesses before `false` witnesses

In rustc it doesn't really matter what the order of the witnesses is, but I'm planning to use the witnesses for implementing the "add missing match arms" assist in rust-analyzer, and there `true` before `false` is the natural order (like `Some` before `None`), and also what the current assist does.

The current order doesn't seem to be intentional; the code was created when bool ctors became their own thing, not just int ctors, but for integer, 0 before 1 is indeed the natural order.

r? `@Nadrieril`
2025-08-08 14:22:44 -05:00
Nicholas Nethercote
704f2ca172 Tidy up Cargo.toml files.
- Add some missing `tidy-alphabetical-*` markers.
- Remove some unnecessary blank lines.
2025-07-31 19:58:04 +10:00
Chayim Refael Friedman
6bf3cbe39e In rustc_pattern_analysis, put true witnesses before false witnesses
In rustc it doesn't really matter what the order of the witnesses is, but I'm planning to use the witnesses for implementing the "add missing match arms" assist in rust-analyzer, and there `true` before `false` is the natural order (like `Some` before `None`), and also what the current assist does.

The current order doesn't seem to be intentional; the code was created when bool ctors became their own thing, not just int ctors, but for integer, 0 before 1 is indeed the natural order.
2025-07-28 02:01:39 +03:00
Trevor Gross
3f7d497c8a
Rollup merge of #144171 - Nadrieril:exhaustive-witnesses, r=davidtwco
pattern_analysis: add option to get a full set of witnesses

This adds an option to the rustc_pattern_analysis machinery to have it report a complete set of patterns when a match is non-exhaustive (by default we only guarantee to report _some_ missing patterns). This is for use in rust-analyzer.

Leaving as draft until I'm sure this is what r-a needs.

r? ghost
2025-07-26 01:15:04 -05:00
Nadrieril
af07c08c60 Silence a warning 2025-07-20 18:27:30 +02:00
Nadrieril
9b01de20e1 List all the variants of non-exhaustive enums in exhaustive mode 2025-07-20 18:27:30 +02:00
Nadrieril
2bb00741d4 pattern_analysis: add option to get a full set of witnesses 2025-07-20 18:27:30 +02:00
Nadrieril
3567ab19a0 Don't consider unstable fields always-inhabited
This reverts the hack in https://github.com/rust-lang/rust/pull/133889
now that `Pin`'s field is no longer public.
2025-07-20 18:23:18 +02:00
dianne
bb64315978 only check for mixed deref/normal constructors when needed 2025-07-04 23:47:31 -07:00
dianne
50061f3b11 always check for mixed deref pattern and normal constructors
This makes it work for box patterns and in rust-analyzer.
2025-07-04 23:47:31 -07:00
dianne
98659a339d treat box patterns as deref patterns in THIR and usefulness analysis
This removes special-casing of boxes from `rustc_pattern_analysis`, as a
first step in replacing `box_patterns` with `deref_patterns`.
Incidentally, it fixes a bug caused by box patterns being represented as
structs rather than pointers, where `exhaustive_patterns` could generate
spurious `unreachable_patterns` lints on arms required for
exhaustiveness; following the lint's advice would result in an error.
2025-07-04 01:28:35 -07:00
klensy
c76d032f01 setup CI and tidy to use typos for spellchecking and fix few typos 2025-07-03 10:51:06 +03:00
bjorn3
ba5556d239
Add #[loop_match] for improved DFA codegen
Co-authored-by: Folkert de Vries <folkert@folkertdev.nl>
2025-06-23 20:43:04 +02:00
Oli Scherer
550aed825b Use builin_index instead of hand-rolling it 2025-05-28 10:03:01 +00:00
Michael Goulet
47b9e373cb Revert "Fix stack overflow in exhaustiveness due to recursive HIR opaque type values"
This reverts commit b08e9c2a60f4dbab4bdaa733727947b3395de329.
2025-05-20 10:09:01 +00:00
est31
258e880861 Remove #![feature(let_chains)] from library and src/librustdoc 2025-05-16 16:14:24 +02:00
dianne
fb261a179d error early when mixing deref patterns with normal constructors
Without adding proper support for mixed exhaustiveness, mixing deref
patterns with normal constructors would either violate
`ConstructorSet::split`'s invariant 4 or 7. We'd either be ignoring rows
with normal constructors or we'd have problems in unspecialization from
non-disjoint constructors. Checking mixed exhaustivenss similarly to how
unions are currently checked should work, but the diagnostics for unions
are confusing. Since mixing deref patterns with normal constructors is
pretty niche (currently it only makes sense for `Cow`), emitting an
error lets us avoid committing to supporting mixed exhaustiveness
without a good answer for the diagnostics.
2025-05-06 18:53:55 -07:00
dianne
b41d8bde00 let deref patterns participate in usefulness/exhaustiveness
This does not yet handle the case of mixed deref patterns with normal
constructors; it'll ICE in `Constructor::is_covered_by`. That'll be
fixed in a later commit.
2025-05-06 18:53:55 -07:00
est31
7493e1cdf6 Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00
Jake Goulding
0117884917 Move eager translation to a method on Diag
This will allow us to eagerly translate messages on a top-level
diagnostic, such as a `LintDiagnostic`. As a bonus, we can remove the
awkward closure passed into Subdiagnostic and make better use of
`Into`.
2025-04-16 21:38:59 -04:00
Michael Goulet
b08e9c2a60 Fix stack overflow in exhaustiveness due to recursive HIR opaque type values 2025-04-07 22:41:48 +00:00
Stuart Cook
82df6229b6
Rollup merge of #139035 - nnethercote:PatKind-Missing, r=oli-obk
Add new `PatKind::Missing` variants

To avoid some ugly uses of `kw::Empty` when handling "missing" patterns, e.g. in bare fn tys. Helps with #137978. Details in the individual commits.

r? ``@oli-obk``
2025-04-07 22:29:17 +10:00
bors
17ffbc81a3 Auto merge of #138785 - lcnr:typing-mode-borrowck, r=compiler-errors,oli-obk
add `TypingMode::Borrowck`

Shares the first commit with #138499, doesn't really matter which PR to land first 😊 😁

Introduces `TypingMode::Borrowck` which unlike `TypingMode::Analysis`, uses the hidden type computed by HIR typeck as the initial value of opaques instead of an unconstrained infer var. This is a part of https://github.com/rust-lang/types-team/issues/129.

Using this new `TypingMode` is unfortunately a breaking change for now, see tests/ui/impl-trait/non-defining-uses/as-projection-term.rs. Using an inference variable as the initial value results in non-defining uses in the defining scope. We therefore only enable it if with `-Znext-solver=globally` or `-Ztyping-mode-borrowck`

To do that the PR contains the following changes:
- `TypeckResults::concrete_opaque_type` are already mapped to the definition of the opaque type
  - writeback now checks that the non-lifetime parameters of the opaque are universal
  - for this, `fn check_opaque_type_parameter_valid` is moved from `rustc_borrowck` to `rustc_trait_selection`
- we add a new `query type_of_opaque_hir_typeck` which, using the same visitors as MIR typeck, attempts to merge the hidden types from HIR typeck from all defining scopes
  - done by adding a `DefiningScopeKind` flag to toggle between using borrowck and HIR typeck
  - the visitors stop checking that the MIR type matches the HIR type. This is trivial as the HIR type are now used as the initial hidden types of the opaque. This check is useful as a safeguard when not using `TypingMode::Borrowck`, but adding it to the new structure is annoying and it's not soundness critical, so I intend to not add it back.
- add a `TypingMode::Borrowck`  which behaves just like `TypingMode::Analysis` except when normalizing opaque types
   - it uses `type_of_opaque_hir_typeck(opaque)` as the initial value after replacing its regions with new inference vars
   - it uses structural lookup in the new solver

fixes #112201, fixes #132335, fixes #137751

r? `@compiler-errors` `@oli-obk`
2025-04-04 19:54:42 +00:00
Oli Scherer
805f389da5 Remove LintExpectationId from Level variants 2025-04-03 09:22:21 +00:00
Oli Scherer
c51816ee59 Make LevelAndSource a struct 2025-04-03 09:17:55 +00:00
lcnr
509a144eed add TypingMode::Borrowck 2025-04-03 11:13:10 +02:00
Nicholas Nethercote
9f089e080c Add {ast,hir,thir}::PatKind::Missing variants.
"Missing" patterns are possible in bare fn types (`fn f(u32)`) and
similar places. Currently these are represented in the AST with
`ast::PatKind::Ident` with no `by_ref`, no `mut`, an empty ident, and no
sub-pattern. This flows through to `{hir,thir}::PatKind::Binding` for
HIR and THIR.

This is a bit nasty. It's very non-obvious, and easy to forget to check
for the exceptional empty identifier case.

This commit adds a new variant, `PatKind::Missing`, to do it properly.

The process I followed:
- Add a `Missing` variant to `{ast,hir,thir}::PatKind`.
- Chang `parse_param_general` to produce `ast::PatKind::Missing`
  instead of `ast::PatKind::Missing`.
- Look through `kw::Empty` occurrences to find functions where an
  existing empty ident check needs replacing with a `PatKind::Missing`
  check: `print_param`, `check_trait_item`, `is_named_param`.
- Add a `PatKind::Missing => unreachable!(),` arm to every exhaustive
  match identified by the compiler.
- Find which arms are actually reachable by running the test suite,
  changing them to something appropriate, usually by looking at what
  would happen to a `PatKind::Ident`/`PatKind::Binding` with no ref, no
  `mut`, an empty ident, and no subpattern.

Quite a few of the `unreachable!()` arms were never reached. This makes
sense because `PatKind::Missing` can't happen in every pattern, only
in places like bare fn tys and trait fn decls.

I also tried an alternative approach: modifying `ast::Param::pat` to
hold an `Option<P<Pat>>` instead of a `P<Pat>`, but that quickly turned
into a very large and painful change. Adding `PatKind::Missing` is much
easier.
2025-03-28 09:18:57 +11:00
bors
d8e44b722a Auto merge of #133889 - compiler-errors:inh-unstable, r=Nadrieril
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-20 14:31:34 +00:00
bors
4e2b096ed6 Auto merge of #137930 - nnethercote:use-Wunused-crate-dependencies, 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-20 04:20:13 +00:00
Nicholas Nethercote
8121958fda Use -Wunused_crate_dependencies for compiler crates.
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-20 08:59:43 +11:00
Matthias Krüger
2ab69b898a
Rollup merge of #138001 - meithecatte:privately-uninhabited, r=Nadrieril
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-19 16:52:54 +01:00
Michael Goulet
0a6a0e47d2 Dont consider fields that are forced unstable due to -Zforce-unstable-if-unmarked to be uninhabited 2025-03-18 18:24:02 +00:00
Michael Goulet
f6107ca173 Consider fields to be inhabited if they are unstable 2025-03-18 18:23:36 +00:00
Nicholas Nethercote
ff0a5fe975 Remove #![warn(unreachable_pub)] from all compiler/ crates.
It's no longer necessary now that `-Wunreachable_pub` is being passed.
2025-03-11 13:14:21 +11:00
Nicholas Nethercote
55505ab1d3 Add unreachable_pub to RUSTC_LINT_FLAGS for compiler/ crates.
And fix the new errors in the handful of crates that didn't have a
`#![warn(unreachable_pub)]`.
2025-03-11 13:14:21 +11:00
许杰友 Jieyou Xu (Joe)
063ef18fdc Revert "Use workspace lints for crates in compiler/ #138084"
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-10 18:12:47 +08:00