479 Commits

Author SHA1 Message Date
Waffle Lapkin e8b6c9737e fix ty::UnevaluatedConst<I>>->AliasTerm<I> conversion 2026-04-21 12:28:25 +02:00
Waffle Lapkin 0ff2fe8eef add AliasTermTy::with_args to simplify a common-ish pattern 2026-04-21 12:28:24 +02:00
Waffle Lapkin d7986943e4 AliasTermTy refactor: fixup compiler 2026-04-21 12:28:22 +02:00
Adwin White 6279106e72 fix all errors 2026-04-20 00:18:28 +08:00
Shoyu Vanilla ace3aa319c Make region equality emits Eq constraints 2026-04-18 22:02:01 +09:00
Jana Dönszelmann 26a0fdcdcd fixup let-else on typing mode in the compiler 2026-04-14 11:05:19 +02:00
Jana Dönszelmann 63c212e62b make typing_mode getter 2026-04-10 11:42:02 +02:00
Jana Dönszelmann 0e0d12ccb3 introduce TypingModeEqWrapper and make TypingMode !Eq 2026-04-10 11:40:01 +02:00
Jacob Pratt 6bd1a6cd31 Rollup merge of #154991 - cijiugechu:fix/next-solver-transmutefrom-ice, r=Kivooeo
Fix ICE in next-solver TransmuteFrom candidate

Treat TransmuteFrom goals with non-region inference variables as ambiguous before running transmutability, matching the old solver.

Closes rust-lang/rust#153370 .
2026-04-08 23:03:59 -04:00
Jacob Pratt bcb5909a14 Rollup merge of #152859 - ShoyuVanilla:issue-152789, r=lcnr
`-Znext-solver` use the trait object's own bounds instead of goal when considering builtin object bounds

Fixes https://github.com/rust-lang/rust/issues/152789 and fixes https://github.com/rust-lang/rust/issues/151329

r? lcnr
2026-04-08 23:03:57 -04:00
cijiugechu ee135be041 Fix ICE in next-solver TransmuteFrom candidate
Treat TransmuteFrom goals with non-region inference variables as ambiguous before running transmutability, instead of computing layouts for unresolved types. The old solver already treated these goals as ambiguous, so only the next solver could hit this ICE.
2026-04-09 10:12:18 +08:00
Shoyu Vanilla ba3b486c3c Use the trait object's own bounds instead of goal when considering builtin object bounds 2026-04-09 02:13:55 +09:00
Waffle Lapkin 0f767084b8 ty::Alias refactor: fixup all the compiler code 2026-04-07 10:08:12 +02:00
Jonathan Brouwer d9e0301801 Rollup merge of #154709 - Jamesbarford:chore/revert-ty-type-alias, r=lcnr
Revert `Ty` type alias in `rustc_type_ir`

Reverting (rust-lang/rust#154270) the creation and use of `Ty` type alias in `rustc_type_ir` that was causing problems with Rust Analyser, see [discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/.23154270.20.28Ty.20alias.29.20triggers.20many.20bogus.20RA.20errors/with/583209227) for more

r? @lcnr
2026-04-02 22:13:58 +02:00
Jonathan Brouwer fc758577be Rollup merge of #153614 - lcnr:find-param-in-clause-ambig, r=BoxyUwU
`FindParamInClause` handle edge-cases

If normalization is ambiguous, we want to treat the where-bound as non-global. The affected code should pretty much always have other errors in that case. It does make reasoning about trait solver cycles and rerunning more confusing and just feels wrong ™️ I encountered this while looking into `ml-kem` (https://github.com/rust-lang/trait-system-refactor-initiative/issues/246). I don't know whether this matters in practice and don't care to look into it too deeply.

We also want to properly handle concrete aliases which mention to something mentioning a generic parameter due to another where-bound.

r? @BoxyUwU
2026-04-02 22:13:52 +02:00
lcnr 69148fd190 add mgca fixme 2026-04-02 16:29:26 +02:00
lcnr b3b29ede80 handle concrete alias norm to generic
see the added test
2026-04-02 16:29:25 +02:00
lcnr 77a9316422 FindParamInClause non-global on overflow 2026-04-02 12:32:23 +02:00
khyperia 9465366ec4 remove the o from oGCA 2026-04-02 12:06:25 +02:00
khyperia 0e2c554e74 rename opaque_generic_const_args to generic_const_args 2026-04-02 12:04:25 +02:00
James Barford-Evans e29f4f4a79 Revert Ty type alias in rustc_type_ir 2026-04-02 10:39:56 +01:00
Jonathan Brouwer 286263335b Rollup merge of #154270 - Jamesbarford:chore/move-ty-pt1, r=lcnr
Create `Ty` type alias in `rustc_type_ir`

r? lcnr

Anywhere that required the use of the trait `Ty` I used `ty::Ty<I>` otherwise it should be `Ty<I>`
2026-03-31 13:58:42 +02:00
James Barford-Evans 17e0cc3ebd Create Ty type alias in rustc_type_ir 2026-03-30 12:34:38 +01:00
Jana Dönszelmann 632ed10838 Revert "eagerly normalize during generalization"
This reverts commit 5d0863b147.
2026-03-23 12:09:34 +01:00
Jana Dönszelmann c838deca23 Revert "normalize at the start of generalize if we can"
This reverts commit f50591fc10.
2026-03-23 12:09:34 +01:00
bors ac7f9ec7da Auto merge of #151746 - jdonszelmann:eagerly-normalize-in-generalize, r=lcnr
Eagerly normalize in generalize

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/151746)*

r? @lcnr 

cc: https://github.com/rust-lang/trait-system-refactor-initiative/issues/262
2026-03-20 18:22:43 +00:00
bendn b90abe64c1 constify const Fn*: Destruct 2026-03-17 23:47:42 +07:00
Oli Scherer 1867653c81 Allow calling const closures in const items 2026-03-13 20:29:43 +00:00
Jonathan Brouwer fad370cc4a Rollup merge of #152800 - spirali:fix-FindParamInClause, r=lcnr
Adds recursion limit into FindParamInClause

Fixes rust-lang/rust#152716

r? lcnr
2026-03-09 11:49:23 +01:00
Ada Bohm 592246e2a1 Added comments 2026-03-07 22:09:35 +01:00
Ada Bohm fcddf7fa3c Propagate certainty 2026-03-05 10:08:57 +01:00
Jonathan Brouwer baa285c6fd Rollup merge of #153172 - jdonszelmann:placeholder-comment, r=lcnr
Fix comment about placeholders

r? @lcnr

When this was introduced, briefly returned an `Option`, which is what the comment refers to.
https://github.com/rust-lang/rust/pull/86993/changes/a9f1e1c440ae20f0ea99f5e265f24094f1a613a5#diff-8d11697c196da9f44774488ae0bf353283e5c6466a6dd570d7818431b73d4a44R511

Before that this code would just panic, and in the commit right after fixing review comments it does so again:
https://github.com/rust-lang/rust/pull/86993/changes/cf001dc8894ae726de96f4db032f11c22f24c393#diff-8d11697c196da9f44774488ae0bf353283e5c6466a6dd570d7818431b73d4a44R560

That comment has been copied around for 5 years now despite not reflecting the behavior hehe

Second commit has some general typos I found
2026-02-28 12:52:56 +01:00
Benno Lossin 7b428597ff add field representing types 2026-02-27 15:54:20 +01:00
Jana Dönszelmann ea2a15fb89 and some typos 2026-02-27 10:46:37 +01:00
Jana Dönszelmann 8f25f8ca50 fix comment about placeholders 2026-02-27 10:44:43 +01:00
Jana Dönszelmann f50591fc10 normalize at the start of generalize if we can 2026-02-26 14:53:57 +01:00
Jana Dönszelmann 5d0863b147 eagerly normalize during generalization 2026-02-26 11:44:24 +01:00
Ada Bohm 8b83d4b4a6 Adds recursion limit into FindParamInClause 2026-02-18 16:44:18 +01:00
Matthias Krüger 336debab2e Rollup merge of #152383 - RalfJung:BikeshedGuaranteedNoDrop, r=TaKO8Ki
BikeshedGuaranteedNoDrop trait: add comments indicating that it can be observed on stable

Not sure if that's worth it, maybe this goes without saying for all these builtin traits?
2026-02-11 13:48:50 +01:00
Ralf Jung 8c0a493e35 BikeshedGuaranteedNoDrop trait: add comments indicating that it can be observed on stable 2026-02-09 12:03:29 +01:00
Noah Lev 9a30ec8149 Implement MVP for opaque generic const arguments
This is meant to be the interim successor to generic const expressions.
Essentially, const item RHS's will be allowed to do arbitrary const
operations using generics. The limitation is that these const items will
be treated opaquely, like ADTs in nominal typing, such that uses of them
will only be equal if the same const item is referenced. In other words,
two const items with the exact same RHS will not be considered equal.

I also added some logic to check feature gates that depend on others
being enabled (like oGCA depending on mGCA).

= Coherence =

During coherence, OGCA consts should be normalized ambiguously because
they are opaque but eventually resolved to a real value. We don't want
two OGCAs that have the same value to be treated as distinct for
coherence purposes. (Just like opaque types.)

This actually doesn't work yet because there are pre-existing
fundamental issues with equate relations involving consts that need to
be normalized. The problem is that we normalize only one layer of the
const item and don't actually process the resulting anon const. Normally
the created inference variable should be handled, which in this case
would cause us to hit the anon const, but that's not happening.
Specifically, `visit_const` on `Generalizer` should be updated to be
similar to `visit_ty`.
2026-02-08 18:15:11 +00:00
James Barford-Evans 25c1365507 Part 2 refactoring of moving placeholder types to rustc_type_ir 2026-01-29 11:11:40 +00:00
Jacob Pratt d37351bbe3 Rollup merge of #148637 - rustc_dyn_incompatible, r=lcnr
Replace `#[rustc_do_not_implement_via_object]` with `#[rustc_dyn_incompatible_trait]`

Background: `#[rustc_do_not_implement_via_object]` on a trait currently still allows `dyn Trait` to exist (if the trait is otherwise dyn-compatible), it just means that `dyn Trait` does not automatically implement `Trait` via the normal object candidate. For some traits, this means that `dyn Trait` does not implement `Trait` at all (e.g. `Unsize` and `Tuple`). For some traits, this means that `dyn Trait` implements `Trait`, but with different associated types (e.g. `Pointee`, `DiscriminantKind`). Both of these cases can can cause issues with codegen , as seen in https://github.com/rust-lang/rust/issues/148089 (and https://github.com/rust-lang/rust/issues/148089#issuecomment-3447803823 ), because codegen assumes that if `dyn Trait` does not implement `Trait` (including if `dyn Trait<Assoc = T>` does not implement `Trait` with `Assoc == T`), then `dyn Trait` cannot be constructed, so vtable accesses on `dyn Trait` are unreachable, but this is not the case if `dyn Trait` has multiple supertraits: one which is `#[rustc_do_not_implement_via_object]`, and one which we are doing the vtable access to call a method from.

This PR replaces `#[rustc_do_not_implement_via_object]` with `#[rustc_dyn_incompatible_trait]`, which makes the marked trait dyn-incompatible, making `dyn Trait` not well-formed, instead of it being well-formed but not implementing `Trait`. This resolves rust-lang/rust#148089 by making it not compile.

May fix rust-lang/rust#148615

The traits that are currently marked `#[rustc_do_not_implement_via_object]` are: `Sized`, `MetaSized`, `PointeeSized`, `TransmuteFrom`, `Unsize`, `BikeshedGuaranteedNoDrop`, `DiscriminantKind`, `Destruct`, `Tuple`, `FnPtr`, `Pointee`. Of these:
* `Sized` and `FnPtr` are already not dyn-compatible (`FnPtr: Copy`, which implies `Sized`)
* `MetaSized`
    * Removed `#[rustc_do_not_implement_via_object]`. Still dyn-compatible after this change. (Has a special-case in the trait solvers to ignore the object candidate for `dyn MetaSized`, since it `dyn MetaSized: MetSized` comes from the sized candidate that all `dyn Trait` get.)
* `PointeeSized`
    * Removed `#[rustc_do_not_implement_via_object]`. It doesn't seem to have been doing anything anyway ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=a395626c8bef791b87a2d371777b7841)), since `PointeeSized` is removed before trait solving(?).
* `Pointee`, `DiscriminantKind`, `Unsize`, and `Tuple` being dyn-compatible without having `dyn Trait: Trait` (with same assoc tys) can be observed to cause codegen issues (https://github.com/rust-lang/rust/issues/148089) so should be made dyn-incompatible
* `Destruct`, `TransmuteFrom`, and `BikeshedGuaranteedNoDrop` I'm not sure if would be useful as object types, but they can be relaxed to being dyn-compatible later if it is determined they should be.

-----

<details> <summary> resolved </summary>

Questions before merge:

1. `dyn MetaSized: MetaSized` having both `SizedCandidate` and `ObjectCandidate`
    1. I'm not sure if the checks in compiler/rustc_trait_selection/src/traits/project.rs and compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs were "load-bearing" for `MetaSized` (which is the only trait that was previously `#[rustc_do_not_implement_via_object]` that is still dyn-compatible after this change). Is it fine to just remove them? Removing them (as I did in the second commit) doesn't change any UI test results.
    3. IIUC, `dyn MetaSized` could get its `MetaSized` implementation in two ways: the object candidate (the normal `dyn Trait: Trait`) that was supressed by `#[rustc_do_not_implement_via_object]`, and the `SizedCandidate` (that all `dyn Trait` get for `dyn Trait: MetaSized`). Given that `MetaSized` has no associated types or methods, is it fine that these both exist now? Or is it better to only have the `SizedCandidate` and leave these checks in (i.e. drop the second commit, and remove the FIXMEs)?
    4. Resolved: the trait solvers special-case `dyn MetaSized` to ignore the object candidate in preference to the sizedness candidate (technically the check is for any `is_sizedness_trait`, but only `MetaSized` gets this far (`Sized` is inherently dyn-incompatible, and `dyn PointeeSized` is ill-formed for other reasons)
4. Diagnostics improvements?
    1. The diagnostics are kinda bad. If you have a `trait Foo: Pointee {}`, you now get a note that reads like *Foo* "opted out of dyn-compatbility", when really `Pointee` did that.
    2. Resolved: can be improved later

  <details> <summary>diagnostic example</summary>

```rs
#![feature(ptr_metadata)]

trait C: std::ptr::Pointee {}

fn main() {
    let y: &dyn C;
}
```

```rs
error[E0038]: the trait `C` is not dyn compatible
  --> c.rs:6:17
   |
 6 |     let y: &dyn C;
   |                 ^ `C` is not dyn compatible
   |
note: for a trait to be dyn compatible it needs to allow building a vtable
      for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
  --> /home/zachary/opt_mount/zachary/Programming/rust-compiler-2/library/core/src/ptr/metadata.rs:57:1
   |
57 | #[rustc_dyn_incompatible_trait]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...because it opted out of dyn-compatbility
   |
  ::: c.rs:3:7
   |
 3 | trait C: std::ptr::Pointee {}
   |       - this trait is not dyn compatible...

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0038`.
  ```

  </details> </details>

  Still investigating "3. `compiler/rustc_hir/src/attrs/encode_cross_crate.rs`: Should `DynIncompatibleTrait` attribute be encoded cross crate?"
2026-01-21 02:04:01 -05:00
Zachary S c3205f98dd Replace #[rustc_do_not_implement_via_object] with #[rustc_dyn_incompatible_trait], which makes the marked trait dyn-incompatible.
Removes the attribute from `MetaSized` and `PointeeSized`, with a special case in the trait solvers for `MetaSized`.

`dyn MetaSized` is a perfectly cromulent type, and seems to only have had #[rustc_do_not_implement_via_object] so the builtin object
candidate does not overlap with the builtin MetaSized impl that all `dyn` types get.
Resolves this with a special case by checking `is_sizedness_trait` where the trait solvers previously checked `implement_via_object`.

`dyn PointeeSized` alone is rejected for other reasons (since `dyn PointeeSized` is considered to have no principal trait because `PointeeSized`
is removed at an earlier stage of the compiler), but `(dyn PointeeSized + Send)` is valid and equivalent to `dyn Send`.

Add suggestions from code review

Update compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs and tests

Co-authored-by: lcnr <rust@lcnr.de>
2026-01-20 12:54:40 -06:00
Shoyu Vanilla 328893e1a6 Fix an ICE on transmute goals with placeholders in param_env 2026-01-21 00:40:51 +09:00
bors 2850ca8295 Auto merge of #150859 - nnethercote:opt-Canonicalizer-flag-checks, r=lcnr
Optimize canonicalizer flag checks.

The most important change here relates to type folding: we now check the flags up front, instead of doing it in `inner_fold_ty` after checking the cache and doing a match. This is a small perf win, and matches other similar folders (e.g. `CanonicalInstantiator`).

Likewise for const folding, we now check the flags first. (There is no cache for const folding.)

Elsewhere we don't check flags before folding a predicate (unnecessary, because `fold_predicate` already checks the flags itself before doing anything else), and invert the flag checks in a couple of methods to match the standard order.

r? @lcnr
2026-01-13 17:36:45 +00:00
Matthias Krüger 79445c315e Rollup merge of #150861 - folding-cleanups, r=lcnr
Folding/`ReErased` cleanups

Various cleanups I found while reading this code closely, mostly involving folding and the use of `ReErased`.

r? @lcnr
2026-01-12 13:32:07 +01:00
rust-bors[bot] 44a5b55557 Auto merge of #150748 - nnethercote:canonicalizer-cleanups, r=lcnr
Canonicalizer cleanups

Some cleanups in and around the canonicalizers, found while I was looking closely at this code.

r? @lcnr
2026-01-11 22:58:38 +00:00
Nicholas Nethercote 46d8c2beeb Clean up src/dst transmute mess.
- Remove the vacuous `Types`, which provides extremely little value.
- Make sure `src` comes before `dst` in all transmute-related functions.
  (Currently it's a mix: sometimes `src` is first, sometimes it is
  second`.)
2026-01-12 09:22:58 +11:00
Nicholas Nethercote 35ad1705ed Optimize canonicalizer flag checks.
The most important change here relates to type folding: we now check the
flags up front, instead of doing it in `inner_fold_ty` after checking
the cache and doing a match. This is a small perf win, and matches other
similar folders (e.g. `CanonicalInstantiator`).

Likewise for const folding, we now check the flags first. (There is no
cache for const folding.)

Elsewhere we don't check flags before folding a predicate (unnecessary,
because `fold_predicate` already checks the flags itself before doing
anything else), and invert the flag checks in a couple of methods to
match the standard order.
2026-01-09 13:07:17 +11:00