about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/traits
AgeCommit message (Collapse)AuthorLines
2025-10-03Don't normalize higher-ranked assumptions if they're not usedMichael Goulet-13/+18
2025-10-02Auto merge of #147138 - jackh726:split-canonical-bound, r=lcnrbors-2/+4
Split Bound index into Canonical and Bound See [#t-types/trait-system-refactor > perf `async-closures/post-mono-higher-ranked-hang.rs`](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-09-30Rollup merge of #147184 - jdonszelmann:bevy-outlives-bound, r=lcnrMatthias Krüger-1/+7
Fix the bevy implied bounds hack for the next solver The diff is trivial, of course, and basically what you already suggested. Mostly dug around a bunch to learn. I hope this is roughly what you had in mind. Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/236. r? `@lcnr`
2025-09-30clone region obligations instead of taking in implied bounds hackJana Dönszelmann-1/+7
2025-09-30Split Bound into Canonical and Boundjackh726-2/+4
2025-09-27Rename various "concrete opaque type" terminology to say "hidden type"Boxy Uwu-1/+1
2025-09-26allow method calls on opaqueslcnr-2/+9
2025-09-24imrpove type_op failure ICElcnr-3/+3
2025-09-18Auto merge of #146727 - matthiaskrgr:rollup-98812uj, r=matthiaskrgrbors-0/+4
Rollup of 6 pull requests Successful merges: - rust-lang/rust#146434 (c-variadic: allow c-variadic inherent and trait methods) - rust-lang/rust#146487 (Improve `core::num` coverage) - rust-lang/rust#146597 (Add span for struct tail recursion limit error) - rust-lang/rust#146622 (Add regression test for issue rust-lang/rust#91831) - rust-lang/rust#146717 (Clean up universe evaluation during type test evaluation) - rust-lang/rust#146723 (Include patch in release notes) r? `@ghost` `@rustbot` modify labels: rollup
2025-09-18Rollup merge of #146597 - modhanami:add-struct-tail-recursion-limit-span, ↵Matthias Krüger-0/+1
r=oli-obk Add span for struct tail recursion limit error Fixes rust-lang/rust#135629 Changes 1. Add span to RecursionLimitReached 2. Add ObligationCause parameter to struct_tail_raw 4. Update call sites to pass nearby ObligationCause or create one 5. Update affected .stderr
2025-09-18Rollup merge of #146434 - folkertdev:c-variadic-inherent-methods, ↵Matthias Krüger-0/+3
r=workingjubilee c-variadic: allow c-variadic inherent and trait methods tracking issue: https://github.com/rust-lang/rust/issues/44930 Continuing the work of https://github.com/rust-lang/rust/pull/146342, allow inherent and trait methods to be c-variadic. However, a trait that contains a c-variadic method is no longer dyn-compatible. There is, presumably, some way to make c-variadic methods dyn-compatible. However currently, we don't have confidence that it'll work reliably: when methods from a `dyn` object are cast to a function pointer, a `ReifyShim` is created. If that shim is c-variadic, it would need to forward the C variable argument list. That does appear to work, because the `va_list` is not represented in MIR at all in this case, so the registers from the call site are untouched by the shim and can be read by the actual implementation. That just does not seem like a solid implementation. Also, intuitively, why would c-variadic function, primarily needed for FFI, need to be used with `dyn` objects at all? We can revisit this limitation if a need arises. r? `@workingjubilee`
2025-09-18Auto merge of #145993 - lcnr:allow-calling-opaques, r=BoxyUwUbors-1/+18
`-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-18support calls on opaque types :<lcnr-1/+18
2025-09-18Rollup merge of #146664 - fmease:clean-up-dyn, r=jdonszelmannStuart Cook-16/+14
Clean up `ty::Dynamic` 1. As a follow-up to PR rust-lang/rust#143036, remove `DynKind` entirely. 2. Inside HIR ty lowering, consolidate modules `dyn_compatibility` and `lint` into `dyn_trait` * `dyn_compatibility` wasn't about dyn compatibility itself, it's about lowering trait object types * `lint` contained dyn-Trait-specific diagnostics+lints only
2025-09-17Remove `DynKind`León Orell Valerian Liehr-16/+14
2025-09-16Add span for struct tail recursion limit errorTawan Muadmuenwai-0/+1
2025-09-16Rollup merge of #145095 - tiif:unstable_const_param, r=BoxyUwUStuart Cook-15/+23
Migrate `UnsizedConstParamTy` to unstable impl of `ConstParamTy_` Now that we have ``#[unstable_feature_bound]``, we can remove ``UnsizedConstParamTy`` that was meant to be an unstable impl of stable type and ``ConstParamTy_`` trait. r? `@BoxyUwU`
2025-09-15Add check to make sure ConstParamTy impls of certain types are gated with ↵tiif-15/+23
#[unstable_feature_bound(unsized_const_params)]
2025-09-12Split AssocContainer::{InherentImpl,TraitImpl}Cameron Steffen-1/+1
2025-09-12Rename AssocItemContainer -> AssocContainerCameron Steffen-1/+1
2025-09-11c-variadic: allow trait methods to be c-variadicFolkert de Vries-0/+3
but a C-variadic method makes a trait dyn-incompatible. That is because methods from dyn traits, when cast to a function pointer, create a shim. That shim can't really forward the c-variadic arguments.
2025-09-09Driveby fixesBoxy-0/+2
2025-09-09erase_regions to erase_and_anonymize_regionsBoxy-6/+6
2025-08-28Auto merge of #145807 - zachs18:only-consider-auto-traits-empty, ↵bors-1/+6
r=compiler-errors When determining if a trait has no entries for the purposes of omitting vptrs from subtrait vtables, consider its transitive supertraits' entries, instead of just its own entries. When determining if a non-first supertrait vptr can be omitted from a subtrait vtable, check if the supertrait or any of its (transitive) supertraits have methods, instead of only checking if the supertrait itself has methods. This fixes the soundness issue where a vptr would be omitted for a supertrait with no methods but that itself had a supertrait with methods, while still optimizing the case where the supertrait is "truly" empty (it has no own vtable entries, and none of its (transitive) supertraits have any own vtable entries). Fixes <https://github.com/rust-lang/rust/issues/145752> ----- Old description: ~~Treat all non-auto traits as non-empty (possibly having methods) for purposes of determining if we need to emit a vptr for a non-direct supertrait (and for new "sibling" entries after a direct or non-direct supertrait).~~ This fixes (I believe) the soundness issue, ~~but regresses vtable sizes and possibly upcasting perf in some cases when using trait hierarchies with empty non-auto traits (see `tests/ui/traits/vtable/multiple-markers.stderr`) since we use vptrs in some cases where we could re-use the vtable.~~ Fixes <https://github.com/rust-lang/rust/issues/145752> Re-opens (not anymore) <https://github.com/rust-lang/rust/issues/114942> Should not affect <https://github.com/rust-lang/rust/issues/131813> (i.e. the soundness issue is still fixed, ~~though the relevant vtables in the `trait Evil` example will be larger now~~) cc implementation history <https://github.com/rust-lang/rust/pull/131864> <https://github.com/rust-lang/rust/pull/113856> ----- ~~It should be possible to check if a trait has any methods from itself *or* supertraits (instead of just from itself), but to fix the immediate soundness issue, just assume any non-auto trait could have methods. A more optimistic check can be implemented later (or if someone does it soon it could just supercede this PR :smile:).~~ Done in latest push `@rustbot` label A-dyn-trait F-trait_upcasting
2025-08-25Only consider auto traits empty for the purposes of omitting vptrs from ↵Zachary S-1/+6
subtrait vtables
2025-08-22change HIR typeck unification handling approachlcnr-10/+15
2025-08-21Rollup merge of #145627 - compiler-errors:const-supertrait-dyn-compat, ↵Jacob Pratt-4/+23
r=fee1-dead Unconditionally-const supertraits are considered not dyn compatible Let's save some space in the design of const traits by making `dyn Trait` where `trait Trait: const Super` not dyn compatible. Such a trait cannot satisfy `dyn Trait: Trait`; we could in the future make this dyn compatible but *NOT* implement `Trait`, but that's a bit weird and seems like it needs to be independently justified moving forward. Fixes https://github.com/rust-lang/rust/issues/145198 r? fee1-dead
2025-08-20Unconditionally-const supertraits are considered not dyn compatibleMichael Goulet-4/+23
2025-08-19Rollup merge of #145537 - zachs18:metasized-negative-bound-fix, r=davidtwco许杰友 Jieyou Xu (Joe)-3/+5
Do not consider a `T: !Sized` candidate to satisfy a `T: !MetaSized` obligation. This example should fail to compile (and does under this PR, with the old and new solvers), but currently compiles successfully ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=6e0e5d0ae0cdf0571dea97938fb4a86d)), because (IIUC) the old solver's `lazily_elaborate_sizedness_candidate`/callers and the new solver's `TraitPredicate::fast_reject_assumption`/`match_assumption` consider a `T: _ Sized` candidate to satisfy a `T: _ MetaSized` obligation, for either polarity `_`, when that should only hold for positive polarity. ```rs #![feature(negative_bounds)] #![feature(sized_hierarchy)] use std::marker::MetaSized; fn foo<T: !MetaSized>() {} fn bar<T: !Sized + MetaSized>() { foo::<T>(); //~^ ERROR the trait bound `T: !MetaSized` is not satisfied // error under this PR } ``` Only observable with the internal-only `feature(negative_bounds)`, so might just be "wontfix". This example is added as a test in this PR (as well as testing that `foo<()>` and `foo<str>` are disallowed for `fn foo<T: !MetaSized`). cc `@davidtwco` for `feature(sized_hierarchy)` Maybe similar to 91c53c9 from <https://github.com/rust-lang/rust/pull/143307>
2025-08-19Rollup merge of #145338 - lcnr:coroutine-witness-yikes, r=compiler-errors许杰友 Jieyou Xu (Joe)-43/+18
actually provide the correct args to coroutine witnesses rust-lang/rust#145194 accidentally provided all arguments of the closure to the witness, but the witness only takes the generic parameters of the defining scope: https://github.com/rust-lang/rust/blob/216cdb7b22b637cef75b7225c642cb7587192643/compiler/rustc_hir_typeck/src/closure.rs#L164 Fixes rust-lang/rust#145288
2025-08-17Do not consider a `T: !Sized` candidate to satisfy a `T: !MetaSized` obligation.Zachary S-3/+5
2025-08-13Cleanup assoc parent utilsCameron Steffen-1/+1
2025-08-13`fn new_coroutine_witness_for_coroutine` woopslcnr-43/+18
2025-08-11Rollup merge of #145194 - compiler-errors:coro-witness-re, r=lcnrStuart Cook-2/+15
Ignore coroutine witness type region args in auto trait confirmation ## The problem Consider code like: ``` async fn process<'a>() { Box::pin(process()).await; } fn require_send(_: impl Send) {} fn main() { require_send(process()); } ``` When proving that the coroutine `{coroutine@process}::<'?0>: Send`, we end up instantiating a nested goal `{witness@process}::<'?0>: Send` by synthesizing a witness type from the coroutine's args: Proving a coroutine witness type implements an auto trait requires looking up the coroutine's witness types. The witness types are a binder that look like `for<'r> { Pin<Box<{coroutine@process}::<'r>>> }`. We instantiate this binder with placeholders and prove `Send` on the witness types. This ends up eventually needing to prove something like `{coroutine@process}::<'!1>: Send`. Repeat this process, and we end up in an overflow during fulfillment, since fulfillment does not use freshening. This can be visualized with a trait stack that ends up looking like: * `{coroutine@process}::<'?0>: Send` * `{witness@process}::<'?0>: Send` * `Pin<Box<{coroutine@process}::<'!1>>>: Send` * `{coroutine@process}::<'!1>: Send` * ... * `{coroutine@process}::<'!2>: Send` * `{witness@process}::<'!2>: Send` * ... * overflow! The problem here specifically comes from the first step: synthesizing a witness type from the coroutine's args. ## Why wasn't this an issue before? Specifically, before 63f6845e570305a92eaf855897768617366164d6, this wasn't an issue because we were instead extracting the witness from the coroutine type itself. It turns out that given some `{coroutine@process}::<'?0>`, the witness type was actually something like `{witness@process}::<'erased>`! So why do we end up with a witness type with `'erased` in its args? This is due to the fact that opaque type inference erases all regions from the witness. This is actually explicitly part of opaque type inference -- changing this to actually visit the witness types actually replicates this overflow even with 63f6845e570305a92eaf855897768617366164d6 reverted: https://github.com/rust-lang/rust/blob/ca77504943887037504c7fc0b9bf06dab3910373/compiler/rustc_borrowck/src/type_check/opaque_types.rs#L303-L313 To better understand this difference and how it avoids a cycle, if you look at the trait stack before 63f6845e570305a92eaf855897768617366164d6, we end up with something like: * `{coroutine@process}::<'?0>: Send` * `{witness@process}::<'erased>: Send` **<-- THIS CHANGED** * `Pin<Box<{coroutine@process}::<'!1>>>: Send` * `{coroutine@process}::<'!1>: Send` * ... * `{coroutine@process}::<'erased>: Send` **<-- THIS CHANGED** * `{witness@process}::<'erased>: Send` **<-- THIS CHANGED** * coinductive cycle! :tada: ## So what's the fix? This hack replicates the behavior in opaque type inference to erase regions from the witness type, but instead erasing the regions during auto trait confirmation. This is kinda a hack, but is sound. It does not need to be replicated in the new trait solver, of course. --- I hope this explanation makes sense. We could beta backport this instead of the revert https://github.com/rust-lang/rust/pull/145193, but then I'd like to un-revert that on master in this PR along with landing this this hack. Thoughts? r? lcnr
2025-08-11Rollup merge of #144156 - compiler-errors:dtorck-upvars, r=lcnrStuart Cook-24/+50
Check coroutine upvars in dtorck constraint Fix rust-lang/rust#144155. This PR fixes an unsoundness where we were not considering coroutine upvars as drop-live if the coroutine interior types (witness types) had nothing which required drop. In the case that the coroutine does not have any interior types that need to be dropped, then we don't need to treat all of the upvars as use-live; instead, this PR uses the same logic as closures, and descends into the upvar types to collect anything that must be drop-live. The rest of this PR is reworking the comment to explain the behavior here. r? `@lcnr` or reassign 😸 --- Just some thoughts --- a proper fix for this whole situation would be to consider `TypingMode` in the `needs_drop` function, and just calling `coroutine_ty.needs_drop(tcx, typing_env)` in the dtorck constraint check. During MIR building, we should probably use a typing mode that stalls the local coroutines and considers them to be unconditionally drop, or perhaps just stall *all* coroutines in analysis mode. Then in borrowck mode, we can re-check `needs_drop` but descend into witness types properly. https://github.com/rust-lang/rust/pull/144158 implements this experimentally. This is a pretty involved fix, and conflicts with some in-flight changes (rust-lang/rust#144157) that I have around removing coroutine witnesses altogether. I'm happy to add a FIXME to rework this whole approach, but I don't want to block this quick fix since it's obviously more correct than the status-quo.
2025-08-10Ignore coroutine witness type region args in auto trait confirmationMichael Goulet-2/+15
2025-08-09rename `TraitRef::from_method` to `from_assoc`Deadbeef-1/+1
also add a note to `GenericArgs::truncate_to`
2025-08-08Check coroutine upvars and in dtorck constraintMichael Goulet-24/+50
2025-08-03Auto merge of #144677 - nnethercote:bound-const-handling, r=lcnrbors-4/+10
Improve bound const handling A few changes to make const handling more similar to type handling. r? `@compiler-errors` -errors
2025-08-01Auto merge of #144458 - compiler-errors:no-witness-mini, r=lcnrbors-36/+51
Remove the witness type from coroutine *args* (without actually removing the type) This does as much of rust-lang/rust#144157 as we can without having to break rust-lang/rust#143545 and/or introduce some better way of handling higher ranked assumptions. Namely, it: * Stalls coroutines based off of the *coroutine* type rather than the witness type. * Reworks the dtorck constraint hack to not rely on the witness type. * Removes the witness type from the args of the coroutine, eagerly creating the type for nested obligations when needed (auto/clone impls). I'll experiment with actually removing the witness type in a follow-up. r? lcnr
2025-08-01Auto merge of #144446 - nnethercote:opt-region-constraints, r=lcnrbors-21/+24
Optimize region constraints r? `@lcnr`
2025-07-31Remove the witness type from coroutine argsMichael Goulet-6/+12
2025-07-31Extract borrowck coroutine drop-liveness hackMichael Goulet-2/+5
2025-07-31Stall coroutines based off of ty::Coroutine, not ty::CoroutineWitnessMichael Goulet-28/+34
2025-07-31Overhaul `Constraint`.Nicholas Nethercote-21/+24
This commit changes it to store a `Region` instead of a `RegionVid` for the `Var` cases: - We avoid having to call `Region::new_var` to re-create `Region`s from `RegionVid`s in a few places, avoiding the interning process, giving a small perf win. (At the cost of the type allowing some invalid combinations of values.) - All the cases now store two `Region`s, so the commit also separates the `ConstraintKind` (a new type) from the `sub` and `sup` arguments in `Constraint`.
2025-07-31Make const bound handling more like types/regions.Nicholas Nethercote-4/+10
Currently there is `Ty` and `BoundTy`, and `Region` and `BoundRegion`, and `Const` and... `BoundVar`. An annoying inconsistency. This commit repurposes the existing `BoundConst`, which was barely used, so it's the partner to `Const`. Unlike `BoundTy`/`BoundRegion` it lacks a `kind` field but it's still nice to have because it makes the const code more similar to the ty/region code everywhere. The commit also removes `impl From<BoundVar> for BoundTy`, which has a single use and doesn't seem worth it. These changes fix the "FIXME: We really should have a separate `BoundConst` for consts".
2025-07-31Remove `ParamEnvAnd::into_parts`.Nicholas Nethercote-1/+1
The fields are public, so this doesn't need a method, normal deconstruction and/or field access is good enough.
2025-07-31Move `ImplHeader` out of `rustc_middle`.Nicholas Nethercote-6/+19
It's not used in `rustc_middle`, and `rustc_trait_selection` is a better place for it.
2025-07-28Rename trait_of_item -> trait_of_assocCameron Steffen-2/+2
2025-07-28use let chains in mir, resolve, targetKivooeo-28/+24