summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
AgeCommit message (Collapse)AuthorLines
2023-09-09 unconstrained region vars: do not ICE ICE babylcnr-9/+5
2023-08-30Revert "Suggest using `Arc` on `!Send`/`!Sync` types"David Tolnay-6/+0
This reverts commit 9de1a472b68ed85f396b2e2cc79c3ef17584d6e1. (cherry picked from commit 823bacb6e3b04c0c9eecb53cc04d4ef96e45d20a)
2023-08-18instantiate response: no unnecessary new universelcnr-1/+1
this previously was a off-by-one error.
2023-08-18Auto merge of #114611 - nnethercote:type-system-chess, r=compiler-errorsbors-9/+4
Speed up compilation of `type-system-chess` [`type-system-chess`](https://github.com/rust-lang/rustc-perf/pull/1680) is an unusual program that implements a compile-time chess position solver in the trait system(!) This PR is about making it compile faster. r? `@ghost`
2023-08-15Rollup merge of #114819 - estebank:issue-78124, r=compiler-errorsMatthias Krüger-1/+1
Point at return type when it influences non-first `match` arm When encountering code like ```rust fn foo() -> i32 { match 0 { 1 => return 0, 2 => "", _ => 1, } } ``` Point at the return type and not at the prior arm, as that arm has type `!` which isn't influencing the arm corresponding to arm `2`. Fix #78124.
2023-08-15Rollup merge of #114831 - ↵Guillaume Gomez-7/+15
compiler-errors:next-solver-projection-subst-compat, r=lcnr Check projection args before substitution in new solver Don't ICE when an impl has the wrong kind of GAT arguments r? lcnr
2023-08-15Rollup merge of #114829 - ↵Guillaume Gomez-54/+92
compiler-errors:next-solver-only-unsize-to-dyn-once, r=lcnr Separate `consider_unsize_to_dyn_candidate` from other unsize candidates Move the unsize candidate assembly *just for* `T -> dyn Trait` out of `assemble_candidates_via_self_ty` so that we only consider it once, instead of for every normalization step of the self ty. This makes sure that we don't assemble several candidates that are equal modulo normalization when we really don't care about normalizing the self type of an `T: Unsize<dyn Trait>` goal anyways. Fixes rust-lang/trait-system-refactor-initiative#57 r? lcnr
2023-08-15Rollup merge of #114828 - compiler-errors:next-solver-probe-upcasting, r=lcnrGuillaume Gomez-10/+12
Probe when assembling upcast candidates so they don't step on eachother's toes in new solver Lack of a probe causes one candidate to disqualify the other due to inference side-effects. r? lcnr
2023-08-15Rollup merge of #114827 - compiler-errors:next-solver-dyn-safe-candidates, ↵Guillaume Gomez-0/+5
r=lcnr Only consider object candidates for object-safe dyn types in new solver We apparently allow this per RFC2027 :skull: r? lcnr
2023-08-15more nitsMichael Goulet-17/+49
2023-08-15Reuse the selection context, compute failing obligations first in ambig modeMichael Goulet-88/+78
2023-08-15nitsMichael Goulet-3/+3
Co-authored-by: lcnr <rust@lcnr.de>
2023-08-15Implement lint against coinductive impl overlapMichael Goulet-6/+75
2023-08-15more span infoMichael Goulet-7/+9
2023-08-15Check projection arguments before substitutionMichael Goulet-7/+15
2023-08-15Separate consider_unsize_to_dyn_candidate from other unsize candidatesMichael Goulet-54/+92
2023-08-15Probe when assembling upcast candidates so they don't step on eachother's toesMichael Goulet-10/+12
2023-08-15Only consider object candidates for object-safe dyn typesMichael Goulet-0/+5
2023-08-14Point at return type when it influences non-first `match` armEsteban Küber-1/+1
When encountering code like ```rust fn foo() -> i32 { match 0 { 1 => return 0, 2 => "", _ => 1, } } ``` Point at the return type and not at the prior arm, as that arm has type `!` which isn't influencing the arm corresponding to arm `2`. Fix #78124.
2023-08-14Remove constness from `ImplSource::Param`Deadbeef-5/+4
2023-08-13Auto merge of #114457 - lcnr:trait_ref_is_knowable-normalize, r=compiler-errorsbors-119/+167
normalize in `trait_ref_is_knowable` in new solver fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/51 Alternatively we could avoid normalizing the self type and do this at the end of the `assemble_candidates_via_self_ty` stack by splitting candidates into: - applicable without normalizing self type - applicable for aliases, even if they can be normalized - applicable for stuff which cannot get normalized further I don't think this would have any significant benefits and it also seems non-trivial to avoid normalizing only the self type in `trait_ref_is_knowable`. r? `@compiler-errors`
2023-08-12lower `evaluate_goal` stability check to `warn`lcnr-36/+56
2023-08-12normalize in `trait_ref_is_knowable` in new solverlcnr-83/+111
2023-08-11remove builtin impl for float and int inferlcnr-9/+4
2023-08-10Rollup merge of #114712 - compiler-errors:comment-nits, r=lcnrMichael Goulet-1/+1
Fix a couple of bad comments A couple of nits I saw. Sorry, this really should be folded into some other PR of mine, but I will literally forget if I don't put these up now.
2023-08-10Comment nitsMichael Goulet-1/+1
2023-08-10make the provisional cache slightly less brokenlcnr-40/+57
2023-08-09Suggest using `Arc` on `!Send`/`!Sync` typesEsteban Kuber-0/+6
2023-08-09Rollup merge of #114548 - fee1-dead-contrib:migrate-to-trans, r=davidtwcoMatthias Krüger-34/+52
Migrate a trait selection error to use diagnostic translation
2023-08-08Auto merge of #114545 - fee1-dead-contrib:lower-impl-effect, r=oli-obkbors-21/+0
correctly lower `impl const` to bind to host effect param r? `@oli-obk`
2023-08-08Only dedup obligation after new ones have been added.Nicholas Nethercote-4/+4
2023-08-08Size the `deduped` set appropriately.Nicholas Nethercote-1/+1
Avoids lots of resizing as the set fills up.
2023-08-08Simplify the boolean logic in a closure.Nicholas Nethercote-6/+1
And rename a closure argument.
2023-08-08Rollup merge of #114594 - compiler-errors:new-solver-resolve-aliases, r=lcnrMatthias Krüger-1/+3
Structurally normalize weak and inherent in new solver It seems pretty obvious to me that we should be normalizing weak and inherent aliases too, since they can always be normalized. This PR still leaves open the question of what to do with opaques, though 💀 **Also**, we need to structurally resolve the target of a coercion, for the UI test to work. r? `@lcnr`
2023-08-08Rollup merge of #114566 - fmease:type-alias-laziness-is-crate-specific, ↵Matthias Krüger-1/+1
r=oli-obk Store the laziness of type aliases in their `DefKind` Previously, we would treat paths referring to type aliases as *lazy* type aliases if the current crate had lazy type aliases enabled independently of whether the crate which the alias was defined in had the feature enabled or not. With this PR, the laziness of a type alias depends on the crate it is defined in. This generally makes more sense to me especially if / once lazy type aliases become the default in a new edition and we need to think about *edition interoperability*: Consider the hypothetical case where the dependency crate has an older edition (and thus eager type aliases), it exports a type alias with bounds & a where-clause (which are void but technically valid), the dependent crate has the latest edition (and thus lazy type aliases) and it uses that type alias. Arguably, the bounds should *not* be checked since at any time, the dependency crate should be allowed to change the bounds at will with a *non*-major version bump & without negatively affecting downstream crates. As for the reverse case (dependency: lazy type aliases, dependent: eager type aliases), I guess it rules out anything from slight confusion to mild annoyance from upstream crate authors that would be caused by the compiler ignoring the bounds of their type aliases in downstream crates with older editions. --- This fixes #114468 since before, my assumption that the type alias associated with a given weak projection was lazy (and therefore had its variances computed) did not necessarily hold in cross-crate scenarios (which [I kinda had a hunch about](https://github.com/rust-lang/rust/pull/114253#discussion_r1278608099)) as outlined above. Now it does hold. `@rustbot` label F-lazy_type_alias r? `@oli-obk`
2023-08-07Structurally normalize weak and inherent tooMichael Goulet-1/+3
2023-08-07Rollup merge of #114196 - compiler-errors:bubble-pls, r=lcnrMatthias Krüger-23/+24
Bubble up nested goals from equation in `predicates_for_object_candidate` This used to be needed for https://github.com/rust-lang/rust/pull/114036#discussion_r1273987510, but since it's no longer, I'm opening this as a separate PR. This also fixes one ICEing UI test: (`tests/ui/unboxed-closures/issue-53448.rs`) r? `@lcnr`
2023-08-07Store the laziness of type aliases in the DefKindLeón Orell Valerian Liehr-1/+1
2023-08-07Migrate a trait selection error to use diagnostic translationDeadbeef-34/+52
2023-08-07Rollup merge of #114549 - chenyukang:yukang-review-resolve-part, r=petrochenkovMatthias Krüger-14/+12
Style fix and refactor on resolve diagnostics - coding style - refactor api of `span_look_ahead`
2023-08-06refactor on span_look_aheadyukang-14/+12
2023-08-06lower impl const to bind to host effect paramDeadbeef-21/+0
2023-08-05Also report when goals go from ok to errorMichael Goulet-2/+8
2023-08-04Rollup merge of #114490 - kernelmethod:error-reporting-typos, r=compiler-errorsMichael Goulet-1/+1
Fix a typo in the error reporting for sealed traits. Fixes a typo in error reporting: "implelement" -> "implement"
2023-08-04Rollup merge of #114287 - lcnr:overflow, r=compiler-errorsMichael Goulet-531/+447
update overflow handling in the new trait solver implements https://hackmd.io/QY0dfEOgSNWwU4oiGnVRLw?view. I want to clean up this doc and add it to the rustc-dev-guide, but I think this PR is ready for merge as is, even without the dev-guide entry. r? `@compiler-errors`
2023-08-05Fix a typo in the error reporting for sealed traits.kernelmethod-1/+1
2023-08-04Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31Matthias Krüger-1/+1
Improve spans for indexing expressions fixes #114388 Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location. This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR. r? compiler-errors
2023-08-04Rollup merge of #113945 - chenyukang:yukang-fix-113447-slice-2, r=cjgillotMatthias Krüger-3/+13
Fix wrong span for trait selection failure error reporting Fixes #113447
2023-08-04Improve spans for indexing expressionsNilstrieb-1/+1
Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location. This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR.
2023-08-04Auto merge of #114036 - compiler-errors:upcast-to-fewer-assocs, r=lcnrbors-110/+234
Rework upcasting confirmation to support upcasting to fewer projections in target bounds This PR implements a modified trait upcasting algorithm that is resilient to changes in the number of associated types in the bounds of the source and target trait objects. It does this by equating each bound of the target trait ref individually against the bounds of the source trait ref, rather than doing them all together by constructing a new trait object. #### The new way we do trait upcasting confirmation 1. Equate the target trait object's principal trait ref with one of the supertraits of the source trait object's principal. https://github.com/rust-lang/rust/blob/fdcab310b2a57a4e9cc0b2629abd27afda49cd80/compiler/rustc_trait_selection/src/traits/select/mod.rs#L2509-L2525 2. Make sure that every auto trait in the *target* trait object is present in the source trait ref's bounds. https://github.com/rust-lang/rust/blob/fdcab310b2a57a4e9cc0b2629abd27afda49cd80/compiler/rustc_trait_selection/src/traits/select/mod.rs#L2559-L2562 3. For each projection in the *target* trait object, make sure there is exactly one projection that equates with it in the source trait ref's bound. If there is more than one, bail with ambiguity. https://github.com/rust-lang/rust/blob/fdcab310b2a57a4e9cc0b2629abd27afda49cd80/compiler/rustc_trait_selection/src/traits/select/mod.rs#L2526-L2557 * Since there may be more than one that applies, we probe first to check that there is exactly one, then we equate it outside of a probe once we know that it's unique. 4. Make sure the lifetime of the source trait object outlives the lifetime of the target. <details> <summary>Meanwhile, this is how we used to do upcasting:</summary> 1. For each supertrait of the source trait object, take that supertrait, append the source object's projection bounds, and the *target* trait object's auto trait bounds, and make this into a new object type: https://github.com/rust-lang/rust/blob/d12c6e947ceacf3b22c154caf9532b390d8dc88a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs#L915-L929 2. Then equate it with the target trait object: https://github.com/rust-lang/rust/blob/d12c6e947ceacf3b22c154caf9532b390d8dc88a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs#L936 This will be a type mismatch if the target trait object has fewer projection bounds, since we compare the bounds structurally in relate: https://github.com/rust-lang/rust/blob/d12c6e947ceacf3b22c154caf9532b390d8dc88a/compiler/rustc_middle/src/ty/relate.rs#L696-L698 </details> Fixes #114035 Also fixes #114113, because I added a normalize call in the old solver. r? types