about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/traits
AgeCommit message (Collapse)AuthorLines
2023-08-09Rollup merge of #114548 - fee1-dead-contrib:migrate-to-trans, r=davidtwcoMatthias Krüger-33/+17
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-07Structurally normalize weak and inherent tooMichael Goulet-1/+3
2023-08-07Migrate a trait selection error to use diagnostic translationDeadbeef-33/+17
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-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-73/+141
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
2023-08-03Don't be incompleteMichael Goulet-92/+128
2023-08-03Fix upcasting with normalization in old solver, add a testMichael Goulet-2/+12
2023-08-03short-circuit when proj def ids differMichael Goulet-5/+6
2023-08-03Rework upcastingMichael Goulet-59/+80
2023-08-04enable suggest convert to slice for binary operationyukang-3/+5
2023-08-03Fix wrong span for trait selection failure error reportingyukang-0/+8
2023-08-03builtin impl confirmation wuhulcnr-23/+17
2023-08-02Remove constness from `TraitPredicate`Deadbeef-93/+45
2023-08-02Rollup merge of #114079 - compiler-errors:closure-upvars, r=oli-obkNilstrieb-5/+6
Use `upvar_tys` in more places, make it return a list Just a cleanup that fell out of a PR that I was gonna write, but that PR kinda got stuck.
2023-08-02Auto merge of #114358 - matthiaskrgr:rollup-d810m9e, r=matthiaskrgrbors-4/+13
Rollup of 6 pull requests Successful merges: - #114178 (Account for macros when suggesting a new let binding) - #114199 (Don't unsize coerce infer vars in select in new solver) - #114301 (Don't check unnecessarily that impl trait is RPIT) - #114314 (Tweaks to `adt_sized_constraint`) - #114322 (Fix invalid slice coercion suggestion reported in turbofish) - #114340 ([rustc_attr][nit] Replace `filter` + `is_some` with `map_or`.) r? `@ghost` `@rustbot` modify labels: rollup
2023-08-02Rollup merge of #114322 - Urgau:fix-issue-110063, r=compiler-errorsMatthias Krüger-3/+12
Fix invalid slice coercion suggestion reported in turbofish This PR fixes the invalid slice coercion suggestion reported in turbofish and inferred generics by not emitting them. Fixes https://github.com/rust-lang/rust/issues/110063
2023-08-02Auto merge of #114170 - lcnr:add-commmentz, r=compiler-errorsbors-10/+0
add `dropck_outlives` comments
2023-08-01Use upvar_tys in more places, make it a listMichael Goulet-5/+6
2023-08-01Convert adt_sized_constraint to early-binder, use listMichael Goulet-1/+1
2023-08-01Rename `maybe_suggest_convert_to_slice` fn name to consistent namingUrgau-3/+3
2023-08-01Fix invalid slice coercion suggestion reported in turbofishUrgau-0/+9
2023-07-30inline format!() args up to and including rustc_codegen_llvmMatthias Krüger-153/+128
2023-07-29Auto merge of #111916 - fee1-dead-contrib:noop-method-call-warn, ↵bors-2/+1
r=compiler-errors make `noop_method_call` warn by default r? `@compiler-errors`
2023-07-28Lower generic const items to HIRLeón Orell Valerian Liehr-0/+2
2023-07-28dropck_outlives commentslcnr-10/+0
2023-07-28Auto merge of #113312 - Ddystopia:auto-trait-fun, r=lcnrbors-14/+77
discard default auto trait impls if explicit ones exist (rebase of #85048) Rebase of #85048
2023-07-28Auto merge of #114134 - fee1-dead-contrib:rm-constness-from-param-env, r=oli-obkbors-107/+25
Remove `constness` from `ParamEnv` This should be replaced by keyword generics/effects. cc #110395 r? `@oli-obk`
2023-07-27Remove `constness` from `ParamEnv`Deadbeef-107/+25
2023-07-26Don't treat negative trait predicates as always knowableMichael Goulet-1/+1
2023-07-25Make everything builtin!Michael Goulet-64/+63
2023-07-25Restore tuple unsizing feature gateMichael Goulet-11/+20
2023-07-24Improve diagnostic for const ctors in array repeat expressionsclubby789-9/+20
2023-07-24Auto merge of #114024 - matthiaskrgr:rollup-uhdbq64, r=matthiaskrgrbors-7/+3
Rollup of 8 pull requests Successful merges: - #113969 (add dynamic for smir) - #113985 (Use erased self type when autoderefing for trait error suggestion) - #113987 (Comment stuff in the new solver) - #113992 (arm-none fixups) - #113993 (Optimize format usage) - #113994 (Optimize format usage) - #114006 (Update sparc-unknown-none-elf platform README) - #114021 (Add missing documentation for `Session::time`) r? `@ghost` `@rustbot` modify labels: rollup
2023-07-24Rollup merge of #113985 - compiler-errors:issue-113951, r=estebankMatthias Krüger-7/+3
Use erased self type when autoderefing for trait error suggestion Let's not try to pass something from `skip_binder` into autoderef. Fixes #113951
2023-07-24Auto merge of #113956 - fmease:rustdoc-fix-x-crate-rpitits, ↵bors-3/+6
r=GuillaumeGomez,compiler-errors rustdoc: handle cross-crate RPITITs correctly Filter out the internal associated types synthesized during the desugaring of RPITITs, they really shouldn't show up in the docs. This also fixes #113929 since we're no longer invoking `is_impossible_associated_item` (renamed from `is_impossible_method`) which cannot handle them (leading to an ICE). I don't think it makes sense to try to make `is_impossible_associated_item` handle this exotic kind of associated type (CC original author `@compiler-errors).` @ T-rustdoc reviewers, currently I'm throwing out ITIT assoc tys before cleaning assoc tys at each usage-site. I'm thinking about making `clean_middle_assoc_item` return an `Option<_>` instead and doing the check inside of it to prevent any call sites from forgetting the check for ITITs. Since I wasn't sure if you would like that approach, I didn't go through with it. Let me know what you think. <details><summary>Explanation on why <code>is_impossible_associated_item(itit_assoc_ty)</code> leads to an ICE</summary> Given the following code: ```rs pub trait Trait { fn def<T>() -> impl Default {} } impl Trait for () {} ``` The generated associated type looks something like (simplified): ```rs type {opaque#0}<T>: Default = impl Default; // the name is actually `kw::Empty` but this is the `def_path_str` repr ``` The query `is_impossible_associated_item` goes through all predicates of the associated item – in this case `<T as Sized>` – to check if they contain any generic parameters from the (generic) associated type itself. For predicates that don't contain any *own* generics, it does further processing, part of which is instantiating the predicate with the generic arguments of the impl block (which is only correct if they truly don't contain any own generics since they wouldn't get instantiated this way leading to an ICE). It checks if `parent_def_id(T) == assoc_ty_def_id` to get to know if `T` is owned by the assoc ty. Unfortunately this doesn't work for ITIT assoc tys. In this case, the parent of `T` is `Trait::def` (!) which is the associated function (I'm pretty sure this is very intentional) which is of course not equal to the assoc ty `Trait::{opaque#0}`. </details> `@rustbot` label A-cross-crate-reexports
2023-07-23Use erased self type when autoderefing for trait error suggestionMichael Goulet-7/+3
2023-07-23fixDeadbeef-2/+1
2023-07-23fix clippy::useless_formatMatthias Krüger-1/+1
2023-07-23fix couple of clippy findings:Matthias Krüger-7/+2
filter_map_identity iter_kv_map needless_question_mark redundant_at_rest_pattern filter_next derivable_impls