about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/traits/select
AgeCommit message (Collapse)AuthorLines
2025-10-03Don't normalize higher-ranked assumptions if they're not usedMichael Goulet-13/+18
2025-09-27Rename various "concrete opaque type" terminology to say "hidden type"Boxy Uwu-1/+1
2025-09-17Remove `DynKind`León Orell Valerian Liehr-12/+10
2025-08-13`fn new_coroutine_witness_for_coroutine` woopslcnr-43/+18
2025-08-10Ignore coroutine witness type region args in auto trait confirmationMichael Goulet-2/+15
2025-07-31Remove the witness type from coroutine argsMichael Goulet-6/+12
2025-07-31Stall coroutines based off of ty::Coroutine, not ty::CoroutineWitnessMichael Goulet-28/+34
2025-07-28use let chains in mir, resolve, targetKivooeo-20/+17
2025-07-20Consider param-env for fast pathMichael Goulet-1/+1
2025-07-18Auto merge of #143545 - compiler-errors:coroutine-obl, r=oli-obkbors-23/+75
`-Zhigher-ranked-assumptions`: Consider WF of coroutine witness when proving outlives assumptions ### TL;DR This PR introduces an unstable flag `-Zhigher-ranked-assumptions` which tests out a new algorithm for dealing with some of the higher-ranked outlives problems that come from auto trait bounds on coroutines. See: * rust-lang/rust#110338 While it doesn't fix all of the issues, it certainly fixed many of them, so I'd like to get this landed so people can test the flag on their own code. ### Background Consider, for example: ```rust use std::future::Future; trait Client { type Connecting<'a>: Future + Send where Self: 'a; fn connect(&self) -> Self::Connecting<'_>; } fn call_connect<C>(c: C) -> impl Future + Send where C: Client + Send + Sync, { async move { c.connect().await } } ``` Due to the fact that we erase the lifetimes in a coroutine, we can think of the interior type of the async block as something like: `exists<'r, 's> { C, &'r C, C::Connecting<'s> }`. The first field is the `c` we capture, the second is the auto-ref that we perform on the call to `.connect()`, and the third is the resulting future we're awaiting at the first and only await point. Note that every region is uniquified differently in the interior types. For the async block to be `Send`, we must prove that both of the interior types are `Send`. First, we have an `exists<'r, 's>` binder, which needs to be instantiated universally since we treat the regions in this binder as *unknown*[^exist]. This gives us two types: `{ &'!r C, C::Connecting<'!s> }`. Proving `&'!r C: Send` is easy due to a [`Send`](https://doc.rust-lang.org/nightly/std/marker/trait.Send.html#impl-Send-for-%26T) impl for references. Proving `C::Connecting<'!s>: Send` can only be done via the item bound, which then requires `C: '!s` to hold (due to the `where Self: 'a` on the associated type definition). Unfortunately, we don't know that `C: '!s` since we stripped away any relationship between the interior type and the param `C`. This leads to a bogus borrow checker error today! ### Approach Coroutine interiors are well-formed by virtue of them being borrow-checked, as long as their callers are invoking their parent functions in a well-formed way, then substitutions should also be well-formed. Therefore, in our example above, we should be able to deduce the assumption that `C: '!s` holds from the well-formedness of the interior type `C::Connecting<'!s>`. This PR introduces the notion of *coroutine assumptions*, which are the outlives assumptions that we can assume hold due to the well-formedness of a coroutine's interior types. These are computed alongside the coroutine types in the `CoroutineWitnessTypes` struct. When we instantiate the binder when proving an auto trait for a coroutine, we instantiate the `CoroutineWitnessTypes` and stash these newly instantiated assumptions in the region storage in the `InferCtxt`. Later on in lexical region resolution or MIR borrowck, we use these registered assumptions to discharge any placeholder outlives obligations that we would otherwise not be able to prove. ### How well does it work? I've added a ton of tests of different reported situations that users have shared on issues like rust-lang/rust#110338, and an (anecdotally) large number of those examples end up working straight out of the box! Some limitations are described below. ### How badly does it not work? The behavior today is quite rudimentary, since we currently discharge the placeholder assumptions pretty early in region resolution. This manifests itself as some limitations on the code that we accept. For example, `tests/ui/async-await/higher-ranked-auto-trait-11.rs` continues to fail. In that test, we must prove that a placeholder is equal to a universal for a param-env candidate to hold when proving an auto trait, e.g. `'!1 = 'a` is required to prove `T: Trait<'!1>` in a param-env that has `T: Trait<'a>`. Unfortunately, at that point in the MIR body, we only know that the placeholder is equal to some body-local existential NLL var `'?2`, which only gets equated to the universal `'a` when being stored into the return local later on in MIR borrowck. This could be fixed by integrating these assumptions into the type outlives machinery in a more first-class way, and delaying things to the end of MIR typeck when we know the full relationship between existential and universal NLL vars. Doing this integration today is quite difficult today. `tests/ui/async-await/higher-ranked-auto-trait-11.rs` fails because we don't compute the full transitive outlives relations between placeholders. In that test, we have in our region assumptions that some `'!1 = '!2` and `'!2 = '!3`, but we must prove `'!1 = '!3`. This can be fixed by computing the set of coroutine outlives assumptions in a more transitive way, or as I mentioned above, integrating these assumptions into the type outlives machinery in a more first-class way, since it's already responsible for the transitive outlives assumptions of universals. ### Moving forward I'm still quite happy with this implementation, and I'd like to land it for testing. I may work on overhauling both the way we compute these coroutine assumptions and also how we deal with the assumptions during (lexical/nll) region checking. But for now, I'd like to give users a chance to try out this new `-Zhigher-ranked-assumptions` flag to uncover more shortcomings. [^exist]: Instantiating this binder with infer regions would be incomplete, since we'd be asking for *some* instantiation of the interior types, not proving something for *all* instantiations of the interior types.
2025-07-17Eagerly unify coroutine witness in old solverMichael Goulet-9/+39
2025-07-15Add alias for ArgOutlivesPredicateMichael Goulet-1/+1
2025-07-15Consider outlives assumptions when proving auto traits for coroutine interiorsMichael Goulet-23/+75
2025-07-15Add the core logic in old and new solverstiif-1/+9
2025-07-08Instantiate binder for Copy/Clone/Sized eagerlyMichael Goulet-196/+222
2025-07-08Instantiate auto trait before computing higher-ranked constituent typesMichael Goulet-16/+23
2025-07-07remove `has_nested`lcnr-59/+52
2025-07-03Remove PointerLike traitMichael Goulet-78/+1
2025-07-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-1/+1
2025-07-01Remove support for dyn*Michael Goulet-1/+0
2025-06-27Auto merge of #142223 - compiler-errors:perf-wf, r=lcnrbors-0/+4
Fast path for WF goals in new solver Hopefully self-explanatory.
2025-06-26Rollup merge of #142927 - compiler-errors:note-find-const, r=BoxyUwUMichael Goulet-1/+1
Add note to `find_const_ty_from_env` Add a note to `find_const_ty_from_env` to explain why it has an `unwrap` which "often" causes ICEs. Also, uplift it into the new trait solver. This avoids needing to go through the interner to call this method which is otherwise an inherent method in the compiler. I can remove this part if desired. r? `@boxyuwu`
2025-06-25Remove some glob imports from the type systemMichael Goulet-27/+30
2025-06-24Apply fast path to old solver tooMichael Goulet-0/+4
2025-06-23Add note to find_const_ty_from_envMichael Goulet-1/+1
2025-06-16trait_sel: skip elaboration of sizedness supertraitDavid Wood-5/+28
As a performance optimization, skip elaborating the supertraits of `Sized`, and if a `MetaSized` obligation is being checked, then look for a `Sized` predicate in the parameter environment. This makes the `ParamEnv` smaller which should improve compiler performance as it avoids all the iteration over the larger `ParamEnv`.
2025-06-16trait_sel: `{Meta,Pointee}Sized` on `?Sized` typesDavid Wood-19/+39
Expand the automatic implementation of `MetaSized` and `PointeeSized` so that it is also implemented on non-`Sized` types, just not `ty::Foreign` (extern type).
2025-06-16trait_sel: `{Meta,Pointee}Sized` on `Sized` typesDavid Wood-0/+8
Introduce the `MetaSized` and `PointeeSized` traits as supertraits of `Sized` and initially implement it on everything that currently implements `Sized` to isolate any changes that simply adding the traits introduces.
2025-06-13Rollup merge of #141352 - lcnr:no-builtin-preference, r=compiler-errorsJubilee-1/+12
builtin dyn impl no guide inference cc https://github.com/rust-lang/rust/pull/141347 we can already slightly restrict this behavior in the old solver, so why not do so. Needs crater and an FCP. r? `@compiler-errors`
2025-06-09transmutability: shift abstraction boundaryJack Wrenn-97/+46
Previously, `rustc_transmute`'s layout representations were genericized over `R`, a reference. Now, it's instead genericized over representations of type and region. This allows us to move reference transmutability logic from `rustc_trait_selection` to `rustc_transmutability` (and thus unit test it independently of the compiler), and — in a follow-up PR — will make it possible to support analyzing function pointer transmutability with minimal surgery.
2025-06-05Replace some `Option<Span>` with `Span` and use DUMMY_SP instead of NoneOli Scherer-13/+15
2025-06-03Add `iter` macroOli Scherer-3/+19
This adds an `iter!` macro that can be used to create movable generators. This also adds a yield_expr feature so the `yield` keyword can be used within iter! macro bodies. This was needed because several unstable features each need `yield` expressions, so this allows us to stabilize them separately from any individual feature. Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de> Co-authored-by: Jieyou Xu <jieyouxu@outlook.com> Co-authored-by: Travis Cross <tc@traviscross.com>
2025-06-03builtin dyn impl no guide inferencelcnr-1/+12
2025-05-27Rename unpack to kindMichael Goulet-1/+1
2025-05-22Auto merge of #141396 - matthiaskrgr:rollup-feg050g, r=matthiaskrgrbors-1/+1
Rollup of 7 pull requests Successful merges: - #135562 (Add ignore value suggestion in closure body) - #139635 (Finalize repeat expr inference behaviour with inferred repeat counts) - #139668 (Handle regions equivalent to 'static in non_local_bounds) - #140218 (HIR ty lowering: Clean up & refactor the lowering of type-relative paths) - #140435 (use uX::from instead of _ as uX in non - const contexts) - #141130 (rustc_on_unimplemented cleanups) - #141286 (Querify `coroutine_hidden_types`) Failed merges: - #140247 (Don't build `ParamEnv` and do trait solving in `ItemCtxt`s when lowering IATs) r? `@ghost` `@rustbot` modify labels: rollup
2025-05-22Rollup merge of #141286 - compiler-errors:querify-coroutine, r=oli-obkMatthias Krüger-1/+1
Querify `coroutine_hidden_types` This is necessary if we ever want to add implied bounds that would be used for higher-ranked coroutine auto trait goals (e.g. future implements `Send`). Modest perf regression in `hyper` full build which (afaict?) is the only async stress test, so definitely worth it IMO. r? oli-obk
2025-05-22Don't allow poly_select in new solverMichael Goulet-3/+5
2025-05-21Auto merge of #140386 - oli-obk:match-on-lang-item-kind, r=compiler-errorsbors-85/+91
Match on lang item kind instead of using an if/else chain Similar to how the new solver does this. Just noticed while I was adding a new entry to the chain 😆
2025-05-20Querify coroutine_hidden_typesMichael Goulet-1/+1
2025-05-17Rollup merge of #140208 - compiler-errors:wf-coinductive, r=lcnrMatthias Krüger-1/+6
Make well-formedness predicates no longer coinductive This PR makes well-formedness no longer coinductive. It was made coinductive in https://github.com/rust-lang/rust/pull/98542, but AFAICT this was only to fix UI tests since we stopped lowering `where Ty:` to an empty-region outlives predicate but to a WF predicate instead. Arguably it should lower to something completely different, something like a "type mentioned no-op predicate", but well-formedness serves this purpose fine today, and since no code (according to crater) relies on this coinductive behavior, we'd like to avoid having to emulate it in the new solver. Fixes #123456 (I didn't want to add a test since it seems low-value to have a ICE test for a fuzzer minimization that is basically garbage code.) Fixes #109764 (not sure if this behavior is emulatable w/o coinductive WF?) Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/169 r? lcnr
2025-05-16Auto merge of #140978 - davidtwco:deep-reject-in-match-norm-trait-ref, r=lcnrbors-2/+8
trait_sel: deep reject `match_normalize_trait_ref` Spotted during an in-person review of #137944 at RustWeek: `match_normalize_trait_ref` could be using `DeepRejectCtxt` to exit early as an optimisation for projection candidates, like is done with param candidates. r? `@lcnr` cc `@oli-obk`
2025-05-13trait_sel: deep reject `match_normalize_trait_ref`David Wood-2/+8
Spotted during an in-person review of unrelated changes, `match_normalize_trait_ref` could be using `DeepRejectCtxt` to exit early as an optimisation for prejection candidates, like is done in param candidates.
2025-05-08normalization: avoid incompletely constraining GAT argslcnr-3/+4
2025-05-01Set groundwork for proper const normalizationBoxy-1/+0
2025-04-30Use less rustc_type_ir in the compiler codebaseRomain Perier-6/+3
This commit does the following: - Replaces use of rustc_type_ir by rustc_middle - Removes the rustc_type_ir dependency - The DelayedSet type is exposed by rustc_middle so everything can be accessed through rustc_middle in a coherent manner.
2025-04-29Also match on the lang item in confirmationOli Scherer-10/+5
2025-04-29Always check the lang item firstOli Scherer-16/+8
2025-04-29Replace if/elseif chain with matchOli Scherer-62/+81
2025-04-29Adjust testsMichael Goulet-1/+3
2025-04-29Wf is not coinductiveMichael Goulet-1/+4