summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/traits
AgeCommit message (Collapse)AuthorLines
2025-07-17trait_sel: `MetaSized` always holds temporarilyDavid Wood-0/+7
As a temporary measure while a proper fix for `tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs` is implemented, make `MetaSized` obligations always hold. In effect, temporarily reverting the `sized_hierarchy` feature. This is a small change that can be backported. (cherry picked from commit 8d64937dc25eb2b01596a3581ec2660d8e81b9b2)
2025-06-22Rollup merge of #142458 - oli-obk:dyn-incompat, r=compiler-errorsGuillaume Gomez-1/+1
Merge unboxed trait object error suggestion into regular dyn incompat error Another hir-walker removed from the well-formed queries. This error was always a duplicate of another, but it was able to provide more information because it could invoke `is_dyn_compatible` without worrying about cycle errors. That's also the reason we can't put the error directly into hir_ty_lowering when lowering a `dyn Trait` within an associated item signature. So instead I packed it into the error handling of wf obligation checking.
2025-06-18Rollup merge of #142619 - klensy:or_fun_call, r=nnethercoteJakub Beránek-1/+1
apply clippy::or_fun_call Applies https://rust-lang.github.io/rust-clippy/master/index.html?groups=nursery#or_fun_call to reduce needless allocs.
2025-06-17apply clippy::or_fun_callklensy-1/+1
2025-06-16trait_sel: skip `nominal_obligations` for `Sized`David Wood-0/+8
`nominal_obligations` calls `predicates_of` on a `Sized` obligation, effectively elaborating the trait and making the well-formedness checking machinery do a bunch of extra work checking a `MetaSized` obligation is well-formed, but given that both `Sized` and `MetaSized` are built-ins, if `Sized` is otherwise well-formed, so `MetaSized` will be.
2025-06-16trait_sel: skip elaboration of sizedness supertraitDavid Wood-6/+69
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: extend fast path with sized hierarchyDavid Wood-7/+11
Extend the fast path for `Sized` traits to include constness and `MetaSized`.
2025-06-16trait_sel: `MetaSized` bounds in dispatchable checkDavid Wood-8/+15
Given the necessary additions of bounds to these traits and their impls in the standard library, it is necessary to add `MetaSized` bounds to the obligation which is proven as part of checking for dyn dispatchability.
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-14Rollup merge of #141811 - mejrs:bye_locals, r=compiler-errorsMatthias Krüger-2/+2
Unimplement unsized_locals Implements https://github.com/rust-lang/compiler-team/issues/630 Tracking issue here: https://github.com/rust-lang/rust/issues/111942 Note that this just removes the feature, not the implementation, and does not touch `unsized_fn_params`. This is because it is required to support `Box<dyn FnOnce()>: FnOnce()`. There may be more that should be removed (possibly in follow up prs) - the `forget_unsized` function and `forget` intrinsic. - the `unsized_locals` test directory; I've just fixed up the tests for now - various codegen support for unsized values and allocas cc ``@JakobDegen`` ``@oli-obk`` ``@Noratrieb`` ``@programmerjake`` ``@bjorn3`` ``@rustbot`` label F-unsized_locals Fixes rust-lang/rust#79409
2025-06-13Rollup merge of #142441 - compiler-errors:lazier-binder-value-folding, r=lcnrJubilee-151/+6
Delay replacing escaping bound vars in `FindParamInClause` By uplifting the `BoundVarReplacer`, which is used by (e.g.) normalization to replace escaping bound vars that are encountered when folding binders, we can use a similar strategy to delay the instantiation of a binder's contents in the `FindParamInClause` used by the new trait solver. This should alleviate the recently added requirement that `Binder<T>: TypeVisitable` only if `T: TypeFoldable`, which was previously required b/c we were calling `enter_forall` so that we could structurally normalize aliases that we found within the predicates of a param-env clause. r? lcnr
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-13TypeVisiting binders no longer requires TypeFolding its interiorMichael Goulet-2/+2
2025-06-13Uplift BoundVarReplacerMichael Goulet-146/+1
2025-06-13Don't use BTreeMap for mapped_constsMichael Goulet-6/+6
2025-06-13Merge unboxed trait object error suggestion into regular dyn incompat errorOli Scherer-1/+1
2025-06-13Unimplement unsized_localsmejrs-2/+2
2025-06-12Rollup merge of #142040 - jswrenn:transmute-ty-region-generic, r=compiler-errorsMatthias Krüger-97/+46
transmutability: shift abstraction boundary 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. r? `@compiler-errors`
2025-06-11Auto merge of #141763 - lcnr:fixme-gamer, r=BoxyUwUbors-1/+1
`FIXME(-Znext-solver)` triage r? `@BoxyUwU`
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-07Rollup merge of #142126 - compiler-errors:normalize-uv-via-relate, r=BoxyUwUGuillaume Gomez-4/+1
Treat normalizing consts like normalizing types in deeply normalize ...so that we don't end up putting a top-level normalizes-to goal in the fulfillment context, which ICEs. This basically just models the normalize-const code off of the normalize-ty code above it, which uses an alias-relate goal instead. Fixes rust-lang/rust#140571 r? lcnr
2025-06-07Unify normalization of terms in deeply normalizeMichael Goulet-4/+1
2025-06-05Replace some `Option<Span>` with `Span` and use DUMMY_SP instead of NoneOli Scherer-34/+40
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-06-03`FIXME(-Znext-solver)` triagelcnr-1/+1
Co-authored-by: Michael Goulet <michael@errs.io>
2025-05-27Rename unpack to kindMichael Goulet-3/+3
2025-05-26Auto merge of #141605 - jieyouxu:rollup-3gjqh5l, r=jieyouxubors-25/+12
Rollup of 10 pull requests Successful merges: - rust-lang/rust#140898 (minor improvements on running miri) - rust-lang/rust#141392 (Avoid obligation construction dance with query region constraints) - rust-lang/rust#141431 (Emit dummy open drop for unsafe binder) - rust-lang/rust#141433 (Properly analyze captures from unsafe binders) - rust-lang/rust#141439 (Deduplicate dyn compatibility violations due to coercion) - rust-lang/rust#141449 (further deduplicate ast visitor code) - rust-lang/rust#141513 (interpret: add allocation parameters to `AllocBytes`) - rust-lang/rust#141516 (speed up charsearcher for ascii chars) - rust-lang/rust#141526 (add a dedicated section for compiler environment variables in the unstable book) - rust-lang/rust#141550 (Fix `unused_braces` lint suggestion when encountering attributes) r? `@ghost` `@rustbot` modify labels: rollup
2025-05-26RenameMichael Goulet-8/+8
2025-05-26Don't retry in pred_known_to_hold_modulo_regions in new solver, since new ↵Michael Goulet-1/+1
solver is more complete Just a totally unrelated nitpick I'm folding into the PR, since it's code I'd like for us to prune when the new solver lands.
2025-05-26Avoid obligation construction dance with query region constraintsMichael Goulet-23/+10
2025-05-23Auto merge of #140553 - BoxyUwU:defer_type_system_ctfe, r=compiler-errorsbors-53/+86
Defer evaluating type system constants when they use infers or params Split out of #137972, the parts necessary for associated const equality and min generic const args to make progress and have correct semantics around when CTFE is invoked. According to a [previous perf run](https://perf.rust-lang.org/compare.html?start=93257e2d20809d82d1bc0fcc1942480d1a66d7cd&end=01b4cbf0f47c3f782330db88fa5ba199bba1f8a2&stat=instructions:u) of adding the new `const_arg_kind` query we should expect minor regressions here. I think this is acceptable as we should be able to remove this query relatively soon once mgca is more complete as we'll then be able to implement GCE in terms of mgca and rip out `GCEConst` at which point it's trivial to determine what kind of anon const we're dealing with (either it has generics and is a repeat expr hack, or it doesnt and is a normal anon const). This should only affect unstable code as we handle repeat exprs specially and those are the only kinds of type system consts that are allowed to make use of generic parameters. Fixes #133066 Fixes #133199 Fixes #136894 Fixes #137813 r? compiler-errors
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 #141390 - compiler-errors:poly-select-new-solver, r=lcnrMatthias Krüger-3/+5
Don't allow `poly_select` in new solver I added a `poly_select` call in #140519, but this causes an ICE since the new solver doesn't properly handle the "instantiate binder -> recanonicalize" step in the proof tree visitor. While we could fix the select visitor to look at the next step in proof tree, it's not really necessary. Instead, let's enforce that all callees call the non-higher-ranked `select` function in the new solver. Fixes https://github.com/rust-lang/rust/issues/141322 r? lcnr
2025-05-22Rollup merge of #141362 - BoxyUwU:correct_error_term_kind, r=lcnrMatthias Krüger-4/+25
Normalize aliases to correct kind of error term Fixes #140642 When normalizing an alias to an error in the old solver, normalize to the same term kind as the alias being normalized instead of always to a type error. r? lcnr
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-22Add test/comment about const patterns with unused paramsBoxy-0/+6
2025-05-22Review CommentsBoxy-69/+69
2025-05-22Don't allow poly_select in new solverMichael Goulet-3/+5
2025-05-22Return correct error term kind on projection errorsBoxy-4/+25
2025-05-21Rollup merge of #141363 - BoxyUwU:doc_lta_norm_binders, r=lcnrMatthias Krüger-4/+13
Document why we allow escaping bound vars in LTA norm r? lcnr followup from the const normalization PR. I think I now understand why free alias norm is funny about binders
2025-05-21Don't evaluate constants depending on infers or paramsBoxy-42/+64
2025-05-21Introduce `tcx.anon_const_kind` queryBoxy-2/+7
2025-05-21Document why we allow escaping bound vars in LTA normBoxy-4/+13
2025-05-21Auto merge of #141345 - matthiaskrgr:rollup-vux7gok, r=matthiaskrgrbors-3/+15
Rollup of 7 pull requests Successful merges: - #141267 (only resolve top-level guard patterns' guards once) - #141280 (Use Docker cache from the current repository) - #141296 (Async drop fix for 'broken mir, place has deref as later projection') - #141328 (When AsyncDrop impl is empty, sync drop generated in elaborator) - #141332 (Do not eagerly fold consts in `normalize_param_env_or_error` if new solver) - #141333 (Use `DeepRejectCtxt` in `assemble_inherent_candidates_from_param`) - #141334 (eagerly check nested obligations when coercing fndefs) r? `@ghost` `@rustbot` modify labels: rollup
2025-05-21Rollup merge of #141334 - lcnr:coerce-nested-obligations, r=compiler-errorsMatthias Krüger-0/+14
eagerly check nested obligations when coercing fndefs fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/212 r? `@compiler-errors`
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-21eagerly check nested obligations when coercing fndefslcnr-0/+14
2025-05-21Do not eagerly fold consts in normalize_param_env_or_error if new solverMichael Goulet-3/+1