Commit graph

2609 commits

Author SHA1 Message Date
Lukas Bergdoll
2f3b952349 Stabilize assert_matches 2026-02-11 14:13:44 +01:00
Jonathan Brouwer
1722b8e06b
Convert to inline diagnostics in rustc_infer 2026-02-03 15:14:49 +01:00
Jonathan Brouwer
40d7cb890f
Rollup merge of #150271 - Jamesbarford:chore/refactor-struct-placeholder-pt2, r=lcnr
Move struct placeholder pt2

r? ghost
2026-01-29 17:47:29 +01:00
James Barford-Evans
25c1365507 Part 2 refactoring of moving placeholder types to rustc_type_ir 2026-01-29 11:11:40 +00:00
Adwin White
f6efe7e1d5 don't return incorrectly constrained opaques in method_autoderef_steps 2026-01-26 17:30:18 +08:00
Zalathar
7ec34defe9 Temporarily re-export assert_matches! to reduce stabilization churn 2026-01-19 18:26:53 +11:00
Nicholas Nethercote
4ae3c85a5e Use the name var_kinds more.
Variables that are collections of `CanonicalVarKind` are sometimes
called `var_kinds` and sometimes called `variables`. The former is much
better, because `variables` is (a) non-descript, and (b) often used
nearby for collections of `I::GenericArg`. I found the inconsistency
made the canonicalization code harder to understand.

This commit renames various `variables` things as `var_kinds`.
2026-01-08 13:37:34 +11:00
Nicholas Nethercote
ec5e96e58b Remove Option from fold_infer_ty return type.
It's no longer needed.
2025-12-23 07:46:12 +11:00
Nicholas Nethercote
2d10f47693 Disallow freshening an already-freshened type/const.
It never happens in practice.
2025-12-22 23:46:39 +11:00
Nicholas Nethercote
5c49aee9ec Remove InferCtxt::freshen.
Sometimes we freshen using a new `TypeFreshener`, and sometimes we
freshen with an existing `TypeFreshener`. For the former we have the
method `InferCtxt::freshen`. For the latter we just call `fold_with`.
This asymmetry has been confusing to me.

This commit removes `InferCtxt::freshen` so that all the freshening
sites consistently use `fold_with` and it's obvious if each one is using
a new or existing `TypeFreshener`.
2025-12-22 23:32:11 +11:00
Nicholas Nethercote
1bb9ff05c0 Remove InferCtxt::freshener.
I have always found this confusingly named, because it creates a new
freshener rather than returning an existing one. We can remove it and
just use `TypeFreshener::new()` at the two call sites, avoiding this
confusion.
2025-12-22 17:48:37 +11:00
Nicholas Nethercote
4652295a3e Simplify TypeFreshener methods.
`freshen_{ty,const}` take a `Result` and just do a fold if the input is
`Ok`. It's simpler to do those folds at the call site, and only call
`freshen_{ty,const}` in the `Err` case. That way we can also avoid
useless fold operations on the results of `new_{int,uint,float}`.

Also, make some `bug!` calls more concise.
2025-12-22 17:22:28 +11:00
James Barford-Evans
1986be2bcd Moved struct Placeholder<T> 2025-12-09 13:40:18 +00:00
lcnr
1b71459736 emit WF goals in relate, not in generalize 2025-12-04 15:43:05 +01:00
Adwin White
b111aed11f fudge infer vars in cause code intentionally 2025-12-01 12:40:49 +08:00
bjorn3
973c7527b4 Unify the configuration of the compiler docs
Previously it was rather inconsistent which crates got the rust logo and
which didn't and setting html_root_url was forgotten in many cases.
2025-11-05 11:25:27 +00:00
lcnr
5f312079f2 add logging to fudge_inference_if_ok 2025-11-04 12:03:19 +01:00
Matthias Krüger
844a41903e
Rollup merge of #148290 - oli-obk:push-qwxvxyopypry, r=nnethercote
Do not emit solver errors that contain error types

any follow-up errors are going to either be duplicates or often disappear if the error itself is fixed.

in this PR it mostly silences dyn-compat errors as all the other errors are already deduplicated outside of the test suite. The dyn compat errors are independent errors and I think if the dyn compatiblity depended on an error type it would not actually show, so this is PR is actually silencing independent errors, too.

I am opening this PR because I am seeing lots of `{type error}: const Trait` errors when adding more const checking. So instead of targetting just those specific errors, I wanted to try out fully avoiding such errors near the trait solver.

cc ````@rust-lang/types```` for thoughts
2025-11-02 09:10:38 +01:00
lcnr
5cbb5d0ac6 rename OpaqueHiddenType 2025-10-31 14:53:03 +01:00
Oli Scherer
cac6f8760a Do not emit solver errors that contain error types 2025-10-31 08:17:44 +00:00
Boxy Uwu
8e9b0c4ca9 rename select_where_possible and select_all_or_error 2025-10-07 23:02:23 +01:00
bors
4b9c62b4da Auto merge of #147138 - jackh726:split-canonical-bound, r=lcnr
Split Bound index into Canonical and Bound

See [#t-types/trait-system-refactor > perf &#96;async-closures/post-mono-higher-ranked-hang.rs&#96;](https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/perf.20.60async-closures.2Fpost-mono-higher-ranked-hang.2Ers.60/with/541535613) for context

Things compile and tests pass, but not sure if this actually solves the perf issue (edit: it does). Opening up this to do a perf (and maybe crater) run.

r? lcnr
2025-10-02 08:09:33 +00:00
Stuart Cook
d4a0f21290
Rollup merge of #147199 - jdonszelmann:outdated-comment-infctx, r=lcnr
remove outdated comment in (inner) `InferCtxt`

This comment seems to have stopped being relevant around 3 years ago after 9f95c605f8. A map? what map? :P

r? `@lcnr`
2025-10-01 22:15:01 +10:00
Jana Dönszelmann
bdebd479ac
remove outdated context (inner) infctx 2025-09-30 21:56:06 +02:00
Jana Dönszelmann
80e598bb12
clone region obligations instead of taking in implied bounds hack 2025-09-30 21:48:55 +02:00
jackh726
d1bbd39c59 Split Bound into Canonical and Bound 2025-09-30 12:58:28 -04:00
lcnr
c2e39c2f20 review 2025-09-26 16:37:08 +02:00
lcnr
148fd9ad3c allow method calls on opaques 2025-09-26 16:33:15 +02:00
bors
4cd91ef822 Auto merge of #145993 - lcnr:allow-calling-opaques, r=BoxyUwU
`-Znext-solver` allow `ExprKind::Call` for not-yet defined opaques

Based on https://github.com/rust-lang/rust/pull/146329. Revival of rust-lang/rust#140496. See the comment on `OpaqueTypesJank`. I've used the following document while working on this https://hackmd.io/Js61f8PRTcyaiyqS-fH9iQ.

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/181. It does introduce one subtle footgun we may want to handle before stabilization, opened https://github.com/rust-lang/trait-system-refactor-initiative/issues/230 for that. Also cc https://github.com/rust-lang/trait-system-refactor-initiative/issues/231 for deref and index operations

r? `@BoxyUwU`
2025-09-18 13:49:53 +00:00
lcnr
f4e19c6878 support calls on opaque types :< 2025-09-18 12:58:38 +02:00
Cameron Steffen
9ecca51bbe Remove ImplSubject 2025-09-17 18:37:35 -05:00
tiif
1c30399cea Add documentation for select_where_possible and select_all_or_error 2025-09-15 09:02:12 +00:00
Boxy
e379c77586 erase_regions to erase_and_anonymize_regions 2025-09-09 14:49:16 +02:00
bors
9c27f27ea3 Auto merge of #140375 - lcnr:subrelations-infcx, r=BoxyUwU
eagerly compute `sub_unification_table` again

Previously called `sub_relations`. We still only using them for diagnostics right now. This mostly reverts rust-lang/rust#119989. Necessary for type inference guidance due to not-yet defined opaque types, cc https://github.com/rust-lang/trait-system-refactor-initiative/issues/182.

We could use them for cycle detection in generalization and it seems desirable to do so in the future. However, this is unsound with the old trait solver as its cache does not track these `sub_unification_table` in any way.

We now properly track the `sub_unification_table` when canonicalizing so using them in the new solver is totally sound and the performance impact is far more manageable than I thought back in rust-lang/rust#119989.

r? `@compiler-errors`
2025-09-08 19:39:36 +00:00
lcnr
b51a3a565a review 2025-09-08 14:17:56 +02:00
lcnr
f514586408 optimize CanonicalVarValues::instantiate 2025-09-08 14:17:56 +02:00
lcnr
28a0e77d13 pass sub_relations into canonical queries 2025-09-08 14:17:56 +02:00
lcnr
2cb04b960f inline CanonicalTyVarKind 2025-09-08 14:17:56 +02:00
lcnr
67965f817d eagerly compute sub_relations again 2025-09-08 14:17:56 +02:00
Nicholas Nethercote
1e679154da Move rustc_middle::MaxUniverse to rustc_infer.
Because `rust_infer` is the only crate that uses it.
2025-09-08 06:34:32 +10:00
Marijn Schouten
0e2224b1bf rustc_infer: change top-level doc comment to inner 2025-09-05 12:43:47 +00: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
bors
75ee9ffd5e Auto merge of #145925 - lcnr:revealing-use-closures-2, r=BoxyUwU
`-Znext-solver`: support non-defining uses in closures

Cleaned up version of rust-lang/rust#139587, finishing the implementation of https://github.com/rust-lang/types-team/issues/129. This does not affect stable. The reasoning for why this is the case is subtle however.

## What does it do

We split `do_mir_borrowck` into `borrowck_collect_region_constraints` and `borrowck_check_region_constraints`, where `borrowck_collect_region_constraints` returns an enormous `CollectRegionConstraintsResult` struct which contains all the relevant data to actually handle opaque type uses and to check the region constraints later on.

`query mir_borrowck` now simply calls `BorrowCheckRootCtxt::do_mir_borrowck` which starts by iterating over all nested bodies of the current function - visiting nested bodies before their parents - and computing their `CollectRegionConstraintsResult`.

After we've collected all constraints it's time to actually compute the concrete types for the opaques defined by this function. With this PR we now compute the concrete types of opaques for each body before using them to check the non-defining uses of any of them.

After we've computed the concrete types by using all bodies, we use `apply_computed_concrete_opaque_types` for each body to constrain non-defining uses, before finally finishing with `borrowck_check_region_constraints`. We always visit nested bodies before their parents when doing this.

## `ClosureRegionRequirements`

As we only call `borrowck_collect_region_constraints` for nested bodies before type checking the parent, we can't simply use the final `ClosureRegionRequirements` of the nested body during MIR type check. We instead track that we need to apply these requirements in `deferred_closure_requirements`.

We now manually apply the final closure requirements to each body after handling opaque types.

This works, except that we may need the region constraints of nested bodies to successfully define an opaque type in the parent. This is handled by using a new `fn compute_closure_requirements_modulo_opaques` which duplicates region checking - while ignoring any errors - before we've added the constraints from `apply_computed_concrete_opaque_types`. This is necessary for a lot of async tests, as pretty much the entire function is inside of an async block while the opaque type gets defined in the parent.

As an performance optimization we only use `fn compute_closure_requirements_modulo_opaques` in case the nested body actually depends on any opaque types. Otherwise we eagerly call `borrowck_check_region_constraints` and apply the final closure region requirements right away.

## Impact on stable code

Handling the opaque type uses in the parent function now only uses the closure requirements *modulo opaques*, while it previously also considered member constraints from nested bodies. `External` regions are never valid choice regions. Also, member constraints will never constrain a member region if it is required to be outlived by an external region, as that fails the upper-bound check. 564ee21912/compiler/rustc_borrowck/src/region_infer/opaque_types/member_constraints.rs (L90-L96)

Member constraints therefore never add constraints for external regions :>

r? `@BoxyUwU`
2025-09-01 20:56:46 +00:00
lcnr
b8160e9f38 use defining uses of all bodies to constrain non-defining uses
support non-defining uses in closures
2025-09-01 22:08:03 +02:00
Nicholas Nethercote
c50d2cc807 Add tracing to [workspace.dependencies]. 2025-08-27 14:21:19 +10:00
Nicholas Nethercote
777e2d6a2a Add thin-vec to newly added [workspace.dependencies]. 2025-08-27 13:59:32 +10:00
lcnr
17ac2fc96d change HIR typeck unification handling approach 2025-08-22 13:39:38 +02:00
lcnr
f5e43d5ee3 nll-relate: improve hr opaque types support 2025-08-18 09:09:42 +02:00
lcnr
e1e1385ce0 remove from_forall 2025-08-11 09:18:46 +02:00
Amanda Stjerna
648e3fc393 Track names of existentials 2025-08-06 16:58:42 +02:00