405 Commits

Author SHA1 Message Date
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
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
lcnr
1acd65cd6d predefined opaques use List 2025-09-26 16:33:15 +02:00
lcnr
4e44d58bbc rename search_graph::Delegate fns 2025-09-26 15:29:01 +02:00
lcnr
4a0c7cc730 fix cycle head usages tracking 2025-09-26 15:29:01 +02:00
lcnr
b83c0f0e94 canonical: yeet EvalCtxt, mk Canonicalizer private 2025-09-18 23:56:20 +02:00
lcnr
a08e6499e6 move mod canonical out of eval_ctxt 2025-09-18 23:56:20 +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
León Orell Valerian Liehr
26f3337d4e Remove DynKind 2025-09-17 04:46:46 +02:00
Michael Goulet
cf224ea1fb incompletely prefer opaque type bounds when self type bottoms out in infer 2025-09-11 12:13:03 +02:00
lcnr
0e29865434 consider the sub_unification_table in stalled_on 2025-09-11 12:13:03 +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
Matthias Krüger
1e46fa94a3 Rollup merge of #146111 - ChayimFriedman2:more-ns-specific-defid, r=lcnr
Migrate more things in the new solver to specific `DefId`s

Continuation of https://github.com/rust-lang/rust/pull/145377. I migrated the rest of the types, except aliases.

Aliases are problematic because opaques and associated types share the same type in the new solver. `@jackh726,` `@lcnr,` `@ShoyuVanilla` I'd like to hear ideas here. Anyway, even if we do nothing with them we already got a substantial improvement.

r? types
2025-09-08 16:34:55 +02: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
Chayim Refael Friedman
5d13845e5b Don't require next-solver ProbeRef to be Copy
rust-analyzer would like to use a non-interned `Probe` there.

Also rename it to `Probe` for this reason.
2025-09-04 02:09:59 +03:00
bors
a2c8b0b92c Auto merge of #145951 - lcnr:proof-tree-as-query, r=compiler-errors
cleanup and cache proof tree building

There's some cruft left over from when we had deep proof trees. We never encounter overflow when evaluating proof trees. Even if the recursion limit is `0`, we still only hit the overflow limit when evaluating nested goals of the root. The root goal simply inherits the `root_depth` of the `SearchGraph`.

Split `evaluate_root_goal_for_proof_tree` from the rest of the trait solver. This enables us to simplify the implementation of `evaluate_goal_raw` and the `ProofTreeBuilder` as we no longer need to manually track the state of the builder and can instead use separate types for that. It does require making a few internal methods into associated functions taking a `delegate` and a `span` instead of the `EvalCtxt` itself.

I've also split `SearchGraph::evaluate_goal` and `SearchGraph::evaluate_root_goal_for_proof_tree` for the same reason. Both functions don't actually share too much code, so by splitting them each version gets significantly easier to read.

Add a `query evaluate_root_goal_for_proof_tree_raw` to cache proof tree building. This requires arena allocating `inspect::Probe`. I've added a new type alias `I::ProbeRef` for this. We may need to adapt this for rust-analyzer? It would definitely be easy to remove the `Copy` bound here 🤔
2025-09-02 13:13:17 +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
Chayim Refael Friedman
6f0ebdb71a Migrate more things in the new solver to specific DefIds 2025-09-02 11:35:25 +03:00
lcnr
0edb22cdbf cleanup proof tree implementation and add cache 2025-08-29 09:35:37 +02:00
bors
41f2b6b39e Auto merge of #145978 - Zalathar:rollup-0dzk72g, r=Zalathar
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#143713 (Add a mailmap entry for gnzlbg)
 - rust-lang/rust#144275 (implement Sum and Product for Saturating(u*))
 - rust-lang/rust#144354 (fix(std): Fix undefined reference to __my_thread_exit on QNX 8.0)
 - rust-lang/rust#145387 (Remove TmpLayout in layout_of_enum)
 - rust-lang/rust#145793 (std library: use execinfo library also on NetBSD.)
 - rust-lang/rust#145884 (Test `instrument-mcount` codegen)
 - rust-lang/rust#145947 (Add more to the `[workspace.dependencies]` section in the top-level `Cargo.toml`)
 - rust-lang/rust#145972 (fix `core::marker::Destruct` doc)
 - rust-lang/rust#145977 (tests: Ignore basic-stepping.rs on riscv64)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-29 03:40:14 +00:00
bors
ef8d1d6f5b Auto merge of #145377 - ChayimFriedman2:solver-def-id, r=lcnr
Switch next solver to use a specific associated type for trait def id

The compiler just puts `DefId` in there, but rust-analyzer uses different types for each kind of item.

See [the Zulip discussion](https://rust-lang.zulipchat.com/#narrow/channel/185405-t-compiler.2Frust-analyzer/topic/Implmentating.20New.20Trait.20Solver/near/534329794). In short, it will be a tremendous help to r-a to use specific associated types, while for the solver and the compiler it's a small change. So I ported `TraitId`, as a proof of concept and it's also likely the most impactful.

r? types
2025-08-29 00:32:21 +00:00
Nicholas Nethercote
e692c97ad3 Add derive-where to [workspace.dependencies]. 2025-08-28 20:11:52 +10:00
Nicholas Nethercote
c50d2cc807 Add tracing to [workspace.dependencies]. 2025-08-27 14:21:19 +10:00
Chayim Refael Friedman
38bd8081b7 Switch next solver to use a specific associated type for trait def id
The compiler just puts `DefId` in there, but rust-analyzer uses different types for each kind of item.
2025-08-25 16:52:08 +03:00
lcnr
14b0ba6a05 support non-defining uses in HIR typeck 2025-08-25 14:20:18 +02:00
bors
f6d23413c3 Auto merge of #145796 - samueltardieu:rollup-linfi86, r=samueltardieu
Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#143898 (opt-dist: rebuild rustc when doing static LLVM builds)
 - rust-lang/rust#144452 (std/sys/fd: Relax `READ_LIMIT` on Darwin)
 - rust-lang/rust#145234 (match exhaustiveness diagnostics: show a trailing comma on singleton tuple consructors in witness patterns (and clean up a little))
 - rust-lang/rust#145515 (Optimize `char::encode_utf8`)
 - rust-lang/rust#145540 (interpret/allocation: get_range on ProvenanceMap)
 - rust-lang/rust#145670 (port `sanitize` attribute to the new parsing infrastructure)
 - rust-lang/rust#145713 (next-solver: fix `feature(const_trait_impl)` bootstrap)
 - rust-lang/rust#145729 (Remove two duplicated crates)
 - rust-lang/rust#145744 (miri: also detect aliasing of in-place argument and return place)
 - rust-lang/rust#145774 (Remove default opts from config)
 - rust-lang/rust#145781 (Remove profile section from Clippy)
 - rust-lang/rust#145782 (rustdoc: make attributes render consistently)
 - rust-lang/rust#145787 (citool: cleanup `mismatched_lifetime_syntaxes` warnings)
 - rust-lang/rust#145791 (Fix ICE when validating transmuting ZST to inhabited enum)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-23 23:30:43 +00:00