about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
AgeCommit message (Collapse)AuthorLines
2023-02-13Make visiting traits generic over the InternerAlan Egerton-8/+8
2023-02-13Workaround issue #107747Alan Egerton-1/+4
Only required until fix #107803 is merged into stage0 compiler, expected when beta 1.69.0 is released on 2023-03-09, then this commit can be reverted.
2023-02-13Alias folding/visiting traits instead of re-exportAlan Egerton-19/+18
2023-02-13Reduce direct `mk_ty` usage.Nicholas Nethercote-5/+5
We use more specific `mk_*` functions in most places, might as well use them as much as possible.
2023-02-13Pre-intern some commonly used type variables.Nicholas Nethercote-1/+1
This requires some rearrangement of plumbing, such as adding `mk_fresh_{,int_,float_}ty` and removing `mk_ty_infer`.
2023-02-12rename query and use `NoSolution`Boxy-4/+5
2023-02-11make `relate`'s const ty assertion use semantic equalityBoxy-2/+21
2023-02-11Auto merge of #107919 - Dylan-DPC:rollup-fkl9swa, r=Dylan-DPCbors-7/+35
Rollup of 9 pull requests Successful merges: - #105019 (Add parentheses properly for borrowing suggestion) - #106001 (Stop at the first `NULL` argument when iterating `argv`) - #107098 (Suggest function call on pattern type mismatch) - #107490 (rustdoc: remove inconsistently-present sidebar tooltips) - #107855 (Add a couple random projection tests for new solver) - #107857 (Add ui test for implementation on projection) - #107878 (Clarify `new_size` for realloc means bytes) - #107888 (revert #107074, add regression test) - #107900 (Zero the `REPARSE_MOUNTPOINT_DATA_BUFFER` header) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-02-11Rollup merge of #105019 - chenyukang:yukang/fix-104961-borrow, r=cjgillotDylan DPC-7/+35
Add parentheses properly for borrowing suggestion Fixes #104961
2023-02-10implement `compute_alias_eq_goal`Boxy-3/+113
2023-02-10emit `AliasEq` when relating type and const aliasesBoxy-0/+15
2023-02-10add `AliasEq` to `PredicateKind`Boxy-0/+34
2023-02-10Rollup merge of #107863 - compiler-errors:new-solver-multiple-candidates, ↵Matthias Krüger-3/+5
r=jackh726 Allow multiple candidates with same response in new solver Treat >1 candidates as *not* ambiguous if they return the same response.
2023-02-10Rollup merge of #107831 - nnethercote:query-refactoring, r=oli-obkMatthias Krüger-4/+3
Query refactoring Just some cleanups I found when learning about the query system. Best reviewed one commit at a time. r? `@oli-obk`
2023-02-10Multiple candidates with same response is not ambiguousMichael Goulet-3/+5
2023-02-09Rollup merge of #107815 - compiler-errors:new-solver-no-auto-if-impl, r=lcnrDylan DPC-0/+14
Disqualify `auto trait` built-in impl in new solver if explicit `impl` exists
2023-02-09Disqualify auto-trait builtin impl in new solver if impl existsMichael Goulet-0/+14
2023-02-09Move winnowing to assemblyMichael Goulet-140/+81
2023-02-09Implement a dummy drop-in-favor-of for the new solverMichael Goulet-19/+33
2023-02-09Use elaborated item bounds for alias typesMichael Goulet-4/+1
2023-02-09Fix subst issue with object_ty_for_traitMichael Goulet-5/+3
2023-02-09Avoid some `tls::with` calls.Nicholas Nethercote-4/+3
These are in places where a `tcx` is easily obtained.
2023-02-08Rollup merge of #107799 - lcnr:update-provisional-result, r=oli-obkMichael Goulet-5/+8
correctly update goals in the cache we may want to actually write the response for our goal into the provisional or global cache instead of simply using the result from the last iteration '^^ r? ```@rust-lang/initiative-trait-system-refactor```
2023-02-09fix #104961, Add parentheses properly for borrowing suggestionyukang-7/+35
2023-02-08correctly update goals in the cachelcnr-5/+8
2023-02-08Rollup merge of #107780 - compiler-errors:instantiate-binder, r=lcnrMatthias Krüger-34/+34
Rename `replace_bound_vars_with_*` to `instantiate_binder_with_*` Mentioning "binder" rather than "bound vars", imo, makes it clearer that we're doing something to the binder as a whole. Also, "instantiate" is the verb that I'm always reaching for when I'm looking for these functions, and the name that we use in the new solver anyways. r? types
2023-02-08Rollup merge of #107769 - compiler-errors:pointer-like, r=eholkMatthias Krüger-8/+8
Rename `PointerSized` to `PointerLike` The old name was unnecessarily vague. This PR renames a nightly language feature that I added, so I don't think it needs any additional approval, though anyone can feel free to speak up if you dislike the rename. It's still unsatisfying that we don't the user which of {size, alignment} is wrong, but this trait really is just a stepping stone for a more generalized mechanism to create `dyn*`, just meant for nightly testing, so I don't think it really deserves additional diagnostic machinery for now. Fixes #107696, cc ``@RalfJung`` r? ``@eholk``
2023-02-07Replacing bound vars is actually instantiating a binderMichael Goulet-34/+34
2023-02-07Rename PointerSized to PointerLikeMichael Goulet-8/+8
2023-02-07Rollup merge of #107555 - edward-shen:edward-shen/dup-trait-suggestion, ↵Matthias Krüger-0/+2
r=compiler-errors Modify existing bounds if they exist Fixes #107335. This implementation is kinda gross but I don't really see a better way to do it. This primarily does two things: Modifies `suggest_constraining_type_param` to accept a new parameter that indicates a span to be replaced instead of added, if presented, and limit the additive suggestions to either suggest a new bound on an existing bound (see newly added unit test) or add the generics argument if a generics argument wasn't found. The former change is required to retain the capability to add an entirely new bounds if it was entirely omitted. r? ``@compiler-errors``
2023-02-06Rollup merge of #106477 - ↵Matthias Krüger-1/+3
Nathan-Fenner:nathanf/refined-error-span-trait-impl, r=compiler-errors Refine error spans for "The trait bound `T: Trait` is not satisfied" when passing literal structs/tuples This PR adds a new heuristic which refines the error span reported for "`T: Trait` is not satisfied" errors, by "drilling down" into individual fields of structs/enums/tuples to point to the "problematic" value. Here's a self-contained example of the difference in error span: ```rs struct Burrito<Filling> { filling: Filling, } impl <Filling: Delicious> Delicious for Burrito<Filling> {} fn eat_delicious_food<Food: Delicious>(food: Food) {} fn will_type_error() { eat_delicious_food(Burrito { filling: Kale }); // ^~~~~~~~~~~~~~~~~~~~~~~~~ (before) The trait bound `Kale: Delicious` is not satisfied // ^~~~ (after) The trait bound `Kale: Delicious` is not satisfied } ``` (kale is fine, this is just a silly food-based example) Before this PR, the error span is identified as the entire argument to the generic function `eat_delicious_food`. However, since only `Kale` is the "problematic" part, we can point at it specifically. In particular, the primary error message itself mentions the missing `Kale: Delicious` trait bound, so it's much clearer if this part is called out explicitly. --- The _existing_ heuristic tries to label the right function argument in `point_at_arg_if_possible`. It goes something like this: - Look at the broken base trait `Food: Delicious` and find which generics it mentions (in this case, only `Food`) - Look at the parameter type definitions and find which of them mention `Filling` (in this case, only `food`) - If there is exactly one relevant parameter, label the corresponding argument with the error span, instead of the entire call This PR extends this heuristic by further refining the resulting expression span in the new `point_at_specific_expr_if_possible` function. For each `impl` in the (broken) chain, we apply the following strategy: The strategy to determine this span involves connecting information about our generic `impl` with information about our (struct) type and the (struct) literal expression: - Find the `impl` (`impl <Filling: Delicious> Delicious for Burrito<Filling>`) that links our obligation (`Kale: Delicious`) with the parent obligation (`Burrito<Kale>: Delicious`) - Find the "original" predicate constraint in the impl (`Filling: Delicious`) which produced our obligation. - Find all of the generics that are mentioned in the predicate (`Filling`). - Examine the `Self` type in the `impl`, and see which of its type argument(s) mention any of those generics. - Examing the definition for the `Self` type, and identify (for each of its variants) if there's a unique field which uses those generic arguments. - If there is a unique field mentioning the "blameable" arguments, use that field for the error span. Before we do any of this logic, we recursively call `point_at_specific_expr_if_possible` on the parent obligation. Hence we refine the `expr` "outwards-in" and bail at the first kind of expression/impl we don't recognize. This function returns a `Result<&Expr, &Expr>` - either way, it returns the `Expr` whose span should be reported as an error. If it is `Ok`, then it means it refined successfull. If it is `Err`, then it may be only a partial success - but it cannot be refined even further. --- I added a new test file which exercises this new behavior. A few existing tests were affected, since their error spans are now different. In one case, this leads to a different code suggestion for the autofix - although the new suggestion isn't _wrong_, it is different from what used to be. This change doesn't create any new errors or remove any existing ones, it just adjusts the spans where they're presented. --- Some considerations: right now, this check occurs in addition to some similar logic in `adjust_fulfillment_error_for_expr_obligation` function, which tidies up various kinds of error spans (not just trait-fulfillment error). It's possible that this new code would be better integrated into that function (or another one) - but I haven't looked into this yet. Although this code only occurs when there's a type error, it's definitely not as efficient as possible. In particular, there are definitely some cases where it degrades to quadratic performance (e.g. for a trait `impl` with 100+ generic parameters or 100 levels deep nesting of generic types). I'm not sure if these are realistic enough to worry about optimizing yet. There's also still a lot of repetition in some of the logic, where the behavior for different types (namely, `struct` vs `enum` variant) is _similar_ but not the same. --- I think the biggest win here is better targeting for tuples; in particular, if you're using tuples + traits to express variadic-like functions, the compiler can't tell you which part of a tuple has the wrong type, since the span will cover the entire argument. This change allows the individual field in the tuple to be highlighted, as in this example: ``` // NEW LL | want(Wrapper { value: (3, q) }); | ---- ^ the trait `T3` is not implemented for `Q` // OLD LL | want(Wrapper { value: (3, q) }); | ---- ^~~~~~~~~~~~~~~~~~~~~~~~~ the trait `T3` is not implemented for `Q` ``` Especially with large tuples, the existing error spans are not very effective at quickly narrowing down the source of the problem.
2023-02-06Modify existing bounds if they existEdward Shen-0/+2
2023-02-03intern external constraintsMichael Goulet-21/+17
2023-02-03Rollup merge of #107427 - detrumi:builtin-impl-candidates, r=compiler-errorsDylan DPC-0/+25
Add candidates for DiscriminantKind builtin Part of #107379
2023-02-03Autotrait bounds on dyn-safe trait methodsDavid Tolnay-10/+50
2023-02-03Use new helper inside probeWilco Kusee-6/+2
2023-02-01Improve pretty-printing of `HirIdValidator` errorsArpad Borsos-1/+1
This now uses `node_to_string` for both missing and seen Ids, which includes the snippet of code for which the Id was allocated. Also removes the duplicated printing of `HirId`, as `node_to_string` includes that already. Similarly, changes all other users of `node_to_string` that do so, and changes the output of `node_to_string`, which is now "$hirid ($what `$span` in $path)".
2023-02-01Simplify discriminant_kind goal using new helper functionWilco Kusee-14/+7
2023-02-01Add candidates for DiscriminantKind builtinWilco Kusee-0/+36
2023-01-31Rollup merge of #107486 - compiler-errors:bound-ty-keep-name, r=oli-obkGuillaume Gomez-2/+2
Track bound types like bound regions When we instantiate bound types into placeholder types, we throw away the names for some reason. These names are particularly useful for error reporting once we have `for<T>` binders. r? types
2023-01-31Rollup merge of #107467 - WaffleLapkin:uneq, r=oli-obkGuillaume Gomez-14/+17
Improve enum checks Some light refactoring.
2023-01-31Rollup merge of #107348 - lcnr:project-solve-new, r=compiler-errorsGuillaume Gomez-45/+86
small refactor to new projection code extract `eq_term_and_make_canonical_response` into a helper function which also is another guarantee that the expected term does not influence candidate selection for projections. also change `evaluate_all(vec![single_goal])` to use `evaluate_goal`. the second commit now also adds a `debug_assert!` to `evaluate_goal`.
2023-01-31Auto merge of #106399 - estebank:type-err-span-label, r=nagisabors-3/+9
Modify primary span label for E0308 Looking at the reactions to https://hachyderm.io/`@ekuber/109622160673605438,` a lot of people seem to have trouble understanding the current output, where the primary span label on type errors talks about the specific types that diverged, but these can be deeply nested type parameters. Because of that we could see "expected i32, found u32" in the label while the note said "expected Vec<i32>, found Vec<u32>". This understandably confuses people. I believe that once people learn to read these errors it starts to make more sense, but this PR changes the output to be more in line with what people might expect, without sacrificing terseness. Fix #68220.
2023-01-31Rollup merge of #107479 - compiler-errors:probe-can-call-ocx, r=BoxyUwUYuki Okushi-1/+1
Use `ObligationCtxt::new_in_snapshot` in `satisfied_from_param_env` We can evaluate nested `ConstEvaluatable` obligations in an evaluation probe, which will ICE if we use `ObligationCtxt::new`. Fixes #107474 Fixes #106666 r? `@BoxyUwU` but feel free to reassign cc `@JulianKnodt` who i think added this assertion code Not sure if the rustdoc test is needed, but can't hurt. They're the same root cause, though.
2023-01-30Track bound types like bound regionsMichael Goulet-2/+2
2023-01-30Tweak E0271 wordingEsteban Küber-2/+6
2023-01-30Modify primary span label for E0308Esteban Küber-1/+3
The previous output was unintuitive to users.
2023-01-30nitsMichael Goulet-16/+16
2023-01-30Trait upcasting support in new solverMichael Goulet-59/+107
2023-01-30Implement unsizing in the new trait solverMichael Goulet-0/+192