Commit graph

434 commits

Author SHA1 Message Date
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
Nicholas Nethercote
b222cf3874 Tweak variable cloning. 2026-01-08 15:03:56 +11:00
Nicholas Nethercote
eb1645653b Update a comment.
I did some measurements. The current choice of 16 is fine.
2026-01-08 15:03:56 +11:00
Nicholas Nethercote
f824083970 Make Canonicalizer::variables owned.
Currently it's a mutable reference, but it doesn't need to be, because
what's passed in is always a mutable reference to an empty `Vec`. This
requires returning variables in a few extra places, which is fine. It
makes the handling of `variables` the same as the handling of
`var_kinds` and `variable_lookup_table`.
2026-01-08 15:03:56 +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
0ad7701b04 Remove variables arg from Canonicalizer::canonicalize_response.
It's an empty `Vec` at both call sites, and so is unnecessary.
2026-01-08 13:37:34 +11:00
Nicholas Nethercote
5ca112fb97 Factor out duplicated code in Canonicalizer::finalize. 2026-01-08 13:37:34 +11:00
Nicholas Nethercote
a4da8e8cef Remove some unnecessary braces in patterns. 2026-01-08 13:37:34 +11:00
AprilNEA
4421270516
Merge associated_const_equality feature gate into MGCA
This removes `associated_const_equality` as a separate feature gate and makes it part of `min_generic_const_args` (mgca).

Key changes:
  - Remove `associated_const_equality` from unstable features, add to removed
  - Update all test files to use `min_generic_const_args` instead
  - Preserve the original "associated const equality is incomplete" error message by specially handling `sym::associated_const_equality` spans in `feature_gate.rs`
  - Rename FIXME(associated_const_equality) to FIXME(mgca)
2026-01-05 12:31:42 +08:00
Esteban Küber
97c7742151 revert one change from rustc_next_trait_solver 2025-12-12 17:55:26 +00:00
Esteban Küber
a49c175380 #![deny(clippy::manual_let_else)] in some rustc modules 2025-12-12 17:53:19 +00:00
Esteban Küber
146711fc24 Use let...else instead of match foo { ... _ => return }; and if let ... else return 2025-12-12 17:52:39 +00:00
Matthias Krüger
d67a12dfff
Rollup merge of #148256 - lcnr:orphan-check, r=spastorino,WaffleLapkin
remove support for `typeof`

see https://github.com/rust-lang/compiler-team/issues/940 closes https://github.com/rust-lang/rust/issues/148700

This also enables checks for invariants previously broken by `typeof` again.

r? types
2025-11-27 15:59:11 +01:00
Stuart Cook
aa98135ace
Rollup merge of #149307 - lapla-cogito:deny_const_auto_trait, r=fmease
Deny const auto traits

close rust-lang/rust#149285

The AST validation now detects and rejects const auto traits. Additionally, I updated an existing test that was using `const unsafe auto trait`.

r? fmease
2025-11-26 23:32:08 +11:00
lapla
ae699c8e78
Avoid ICE when handling const auto traits in the next-gen solver 2025-11-26 01:28:40 +09:00
lcnr
feb13036ef remove support for type-of 2025-11-25 10:19:44 +01:00
Adwin White
525cdc75dc skip checking supertraits in assembly_object_bound_candidate for NormalizesTo goal 2025-11-25 11:36:16 +08:00
lcnr
15b02a94b1 move GAT inference prevention hack 2025-11-12 14:59:28 +01:00
lcnr
2570c2322b add test for assoc type norm wf check 2025-11-11 11:05:47 +01:00
joboet
7c430e7646
automatically implement TrivialClone for closures and tuples
If each of the component types is `TrivialClone`, the closure/tuple itself can be trivially cloned.
2025-11-09 17:31:19 +01:00
bors
72b21e1a64 Auto merge of #139558 - camelid:mgca-const-items, r=oli-obk,BoxyUwU
mgca: Add ConstArg representation for const items

tracking issue: rust-lang/rust#132980
fixes rust-lang/rust#131046
fixes rust-lang/rust#134641

As part of implementing `min_generic_const_args`, we need to distinguish const items that can be used in the type system, such as in associated const equality projections, from const items containing arbitrary const code, which must be kept out of the type system. Specifically, all "type consts" must be either concrete (no generics) or generic with a trivial expression like `N` or a path to another type const item.

To syntactically distinguish these cases, we require, for now at least, that users annotate all type consts with the `#[type_const]` attribute. Then, we validate that the const's right-hand side is indeed eligible to be a type const and represent it differently in the HIR.

We accomplish this representation using a new `ConstItemRhs` enum in the HIR, and a similar but simpler enum in the AST. When `#[type_const]` is **not** applied to a const (e.g. on stable), we represent const item right-hand sides (rhs's) as HIR bodies, like before. However, when the attribute is applied, we instead lower to a `hir::ConstArg`. This syntactically distinguishes between trivial const args (paths) and arbitrary expressions, which are represented using `AnonConst`s. Then in `generics_of`, we can take advantage of the existing machinery to bar the `AnonConst` rhs's from using parent generics.
2025-11-08 22:31:33 +00:00
Noah Lev
9864a2fbca add const_of_item query and use it in normalization 2025-11-08 13:50:47 -05:00
Matthias Krüger
fc318986f3
Rollup merge of #148292 - adwinwhite:assemble_object_candidate, r=lcnr
Un-shadow object bound candidate in `NormalizesTo` goal if self_ty is trait object

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/244

r? lcnr
2025-11-06 12:29:58 +01:00
Adwin White
e2ac9d92d9 Apply suggestions 2025-10-31 20:31:49 +08:00
Matthias Krüger
149ad71e05
Rollup merge of #144291 - oli-obk:const_trait_alias, r=fee1-dead
Constify trait aliases

Allow `const trait Foo = Bar + [const] Baz;` trait alias declarations. Their rules are the same as with super traits of const traits. So `[const] Baz` or `const Baz` is only required for `[const] Foo` or `const Foo` bounds respectively.

tracking issue rust-lang/rust#41517 (part of the general trait alias feature gate, but I can split it out into a separate const trait alias feature gate. I just assumed that const traits would stabilize before trait aliases, and we'd want to stabilize trait aliases together with const trait aliases at the same time)

r? ``@compiler-errors`` ``@fee1-dead``
2025-10-31 02:39:14 +01:00
Adwin White
2fbb751985 Un-shadow object bound candidate in NormalizesTo goal 2025-10-30 20:22:45 +08:00
Oli Scherer
544a5a3e0e Make const trait aliases work in next solver 2025-10-30 08:05:37 +00:00
Deadbeef
744c670812 Add built-in const impls for Clone and Copy 2025-10-26 19:40:59 +00:00
lcnr
561e3cede2 gamer 2025-10-24 15:34:45 +02:00
bors
4d94478977 Auto merge of #147826 - Muscraft:update-typos, r=Noratrieb
Update typos

I saw that `typos` was a few versions out of date and figured it would be a good idea to update it. Upgrading to `1.38.1` adds the [July](https://github.com/crate-ci/typos/issues/1331), [August](https://github.com/crate-ci/typos/issues/1345), and [September](https://github.com/crate-ci/typos/issues/1370) dictionary updates. As part of this change, I also sorted the configuration file.
2025-10-22 13:11:47 +00:00
bors
37ec98f5d3 Auto merge of #146725 - lcnr:eager-instantiate-binder, r=BoxyUwU
`-Znext-solver` instantiate predicate binder without recanonicalizing goal

This strengthens the leak check to match the old trait solver. The new trait solver now also instantiates higher ranked goals in the same scope as candidate selection, so the leak check in each candidate detects placeholder errors involving this higher ranked goal.

E.g. let's look at tests/ui/higher-ranked/leak-check/leak-check-in-selection-2.rs
```rust
trait Trait<T, U> {}
impl<'a> Trait<&'a str, &'a str> for () {}
impl<'a> Trait<&'a str, String> for () {}
fn impls_trait<T: for<'a> Trait<&'a str, U>, U>() {}

fn main() {
    impls_trait::<(), _>();
}
```
Here proving `(): for<'a> Trait<&'a str, ?u>` via `impl<'a> Trait<&'a str, &'a str> for ()` equates `?u` with `&'!a str` which results in a leak check error as `?u` cannot name `'a`. If this leak check error happens while considering candidates we drop the first impl and infer `?u` to `String`. If not, this remains ambiguous.

This behavior is a bit iffy, see the FCP proposal in rust-lang/rust#119820 for more details on why this current behavior is somewhat undesirable. However, considering placeholders from higher-ranked goals for candidate selection does allow more code to compile and a lot of the code *feels like it should compile*. **This caused us to revert the change of rust-lang/rust#119820 in rust-lang/rust#127568.**

I originally expected that we can avoid breakage with the new solver differently here, e.g. by considering OR-region constraints. However, doing so is a significant change and I don't have a great idea for how that should work. Matching the old solver behavior for now should not make this cleaner approach any more difficult in the future, so let's just go with what actually allows us to stabilize the new solver for now.

This PR changing the new solver to match the behavior of the old one wrt the leak check. As the new solver is already used by default in coherence, this allows more code to compile, see `tests/ui/higher-ranked/leak-check/leak-check-in-selection-7-coherence.rs`:
```rust
struct W<T, U>(T, U);

trait Trait<T> {}
// using this impl results in a higher-ranked region error.
impl<'a> Trait<W<&'a str, &'a str>> for () {}
impl<'a> Trait<W<&'a str, String>> for () {}

trait NotString {}
impl NotString for &str {}
impl NotString for u32 {}

trait Overlap<U> {}
impl<T: for<'a> Trait<W<&'a str, U>>, U> Overlap<U> for T {}
impl<U: NotString> Overlap<U> for () {}

fn main() {}
```

This behavior is quite arbitrary and not something I expect users to rely on in practice, however, it should still go through an FCP imo.

r? `@BoxyUwU` originally implemented by `@compiler-errors` in https://github.com/rust-lang/rust/pull/136997. Closes https://github.com/rust-lang/trait-system-refactor-initiative/issues/120.
2025-10-21 21:09:46 +00:00
bors
869fb4679f Auto merge of #147723 - ChayimFriedman2:ns-types, r=BoxyUwU
Make `UnevaluatedConst` have a specific ID type in the new solver

For the benefit of rust-analyzer.

r? types
2025-10-21 14:43:26 +00:00
Scott Schafer
12f6b9697f
chore: Update typos to 1.38.1 2025-10-20 12:20:15 -06:00
Michael Goulet
5508b471bd instantiate predicate binder without recanonicalizing goal in new solver 2025-10-20 10:31:08 +02:00
Chayim Refael Friedman
4efd70d5f0 Make more new-trait-solver-things have specific ID type 2025-10-15 16:31:03 +03:00
David Wood
676d9cfa8b
trait_sel: prefer only nested alias bounds 2025-10-15 09:35:05 +01:00
David Wood
321a47eb2c
trait_sel: sizedness goals prefer alias candidates
For sizedness, default and auto trait predicates, now prefer non-param
candidates if any exist. As these traits do not have generic parameters,
it never makes sense to prefer an non-alias candidate, as there can
never be a more permissive candidate.
2025-10-15 09:35:04 +01:00
Stuart Cook
4321adfbe0
Rollup merge of #147266 - lcnr:fix-search_graph, r=BoxyUwU
fix 2 search graph bugs

wooooooooops, i should really run the fuzzer even when not changing the structure of the search graph as a whole :3 fixes the `ml-kem` ICE in the next-solver crater run

r? ````@BoxyUwU````
2025-10-14 16:30:58 +11:00
lcnr
36283bcb7e fix RebaseReason::Ambiguity
we should not get the certainty from the current result of the
provisional cache entry
2025-10-02 12:10:58 +02: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
jackh726
d1bbd39c59 Split Bound into Canonical and Bound 2025-09-30 12:58:28 -04:00
lcnr
5139facb36 add tests 2025-09-30 12:02:43 +02:00
lcnr
07806a1132 cleanup try_evaluate_added_goals 2025-09-29 15:28:33 +02:00
lcnr
098a56890f Fn-trait goals, eagerly instantiate binder
to avoid overflow from proving `for<'a> opaque<'a>: Sized`
2025-09-29 15:28:33 +02:00
Matthias Krüger
cb4c3ad41c
Rollup merge of #147061 - lcnr:provisional-cache-woops, r=BoxyUwU
fix rebasing cycle heads when not reaching a fixpoint

fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/232

annoyingly subtle, imagine the following proof tree

- A (no cycle head usages, final result Y)
  - *ignored* B (depends on A with provisional result X)
    - A (cycle, provisional result X)
- B (using the cache entry here incorrectly assumes A has final result X)

r? ``@BoxyUwU``
2025-09-28 09:15:25 +02:00
lcnr
148fd9ad3c allow method calls on opaques 2025-09-26 16:33:15 +02:00