Files
rust/compiler/rustc_mir_transform
bors fa36a479e4 Auto merge of #156742 - adwinwhite:rigid-alias, r=lcnr
Add rigid alias marker





This PR adds a rigidness marker to `TyKind::Alias` and `ConstKind::Unevaluated`. It's used to skip renormalization of rigid aliases. The tracking issue for this is rust-lang/rust#155345.

The difficulty is that rigid aliases are only valid in their own `TypingEnv` so we need to force them back to non-rigid when entering another `TypingEnv`, either because a change to the `ParamEnv` or because we enter another `TypingMode`.

Changes to the `ParamEnv` currently only happen by moving into a new context. We now make sure that `EarlyBinder` new contains any rigid aliases, this way we have to normalize all aliases contained in it after instantiating.

Changes to the `TypingMode` are rare, and have to be manually handled.

---

The main changes in this PR are as follows:
- we add `enum IsRigid { Yes, No }` as a field to `TyKind::Alias` and `ConstKind::Unevaluated`. It is always `No` with the old solver, this makes some of the code less nice than it will be with the old solver removed.
- if we keep an alias as rigid when proving `Projection` goals we equate the expected term with that alias with `IsRigid::Yes`
- `EarlyBinder::bind` now takes the `tcx` and eagerly sets all `IsRigid` to `No`, this is necessary as moving aliases into a different `TypingEnv` may cause them to no longer be rigid
- `EarlyBinder::bind_iter` asserts that there are no rigid aliases instead of replacing them
- type relations and generalization always structurally recurse into rigid aliases
- a lot of places in the new solver can ICE when matching on `TyKind::Alias` with `IsRigid::No`

---

There's a lot of future work here:
- coherence don't actually rely on lazy norm :<
- remove eq_structurally_relating_aliases, have a special type folder for canonical responses
- yeet `AliasRelate`, lazily replace non-rigid aliases with infer var + projection goal
- `ParamEnv` normalization hack to incorrectly mark things as rigid
- eagerly normalize when adding stuff to the fulfillment ctxt :>
- change `TypeOutlives` goal handling to only expect rigid aliases
- properly expect `IsRigid::Yes`in region handling (or `yes_if_next_solver`)
- probably change `EarlyBinder::bind` to also assert that there are no rigid aliases and manually replacing rigid aliases before then where necessary

---

This PR also adds a flag `-Zrenormalize-rigid-aliases` to test whether we properly handle typing mode change.

Currently only `tests/ui/traits/next-solver/assembly/ambiguity-due-to-uniquification-4.rs` fails this check.

r? lcnr
2026-06-25 14:59:15 +00:00
..