about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
AgeCommit message (Collapse)AuthorLines
2023-03-23Note type mismatch on ConstArgHasTypeMichael Goulet-2/+12
2023-03-23Return nested obligations from canonical response var unificationMichael Goulet-25/+38
2023-03-23Don't split up TreatProjections and TreatParams anymoreMichael Goulet-19/+9
2023-03-23Rollup merge of #109472 - MU001999:patch-3, r=eholkMatthias Krüger-7/+25
Add parentheses properly for method calls Fixes #109436
2023-03-23Auto merge of #109517 - matthiaskrgr:rollup-m3orqzd, r=matthiaskrgrbors-61/+121
Rollup of 7 pull requests Successful merges: - #108541 (Suppress `opaque_hidden_inferred_bound` for nested RPITs) - #109137 (resolve: Querify most cstore access methods (subset 2)) - #109380 (add `known-bug` test for unsoundness issue) - #109462 (Make alias-eq have a relation direction (and rename it to alias-relate)) - #109475 (Simpler checked shifts in MIR building) - #109504 (Stabilize `arc_into_inner` and `rc_into_inner`.) - #109506 (make param bound vars visibly bound vars with -Zverbose) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-03-23Rollup merge of #109462 - compiler-errors:alias-relate, r=BoxyUwU,lcnrMatthias Krüger-61/+121
Make alias-eq have a relation direction (and rename it to alias-relate) Emitting an "alias-eq" is too strict in some situations, since we don't always want strict equality between a projection and rigid ty. Adds a relation direction. * I could probably just reuse this [`RelationDir`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_infer/infer/combine/enum.RelationDir.html) -- happy to uplift that struct into middle and use that instead, but I didn't feel compelled to... 🤷 * Some of the matching in `compute_alias_relate_goal` is a bit verbose -- I guess I could simplify it by using [`At::relate`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_infer/infer/at/struct.At.html#method.relate) and mapping the relation-dir to a variance. * Alternatively, I coulld simplify things by making more helper functions on `EvalCtxt` (e.g. `EvalCtxt::relate_with_direction(T, T)` that also does the nested goal registration). No preference. r? ```@lcnr``` cc ```@BoxyUwU``` though boxy can claim it if she wants NOTE: first commit is all the changes, the second is just renaming stuff
2023-03-23Auto merge of #109503 - matthiaskrgr:rollup-cnp7kdd, r=matthiaskrgrbors-49/+123
Rollup of 9 pull requests Successful merges: - #108954 (rustdoc: handle generics better when matching notable traits) - #109203 (refactor/feat: refactor identifier parsing a bit) - #109213 (Eagerly intern and check CrateNum/StableCrateId collisions) - #109358 (rustc: Remove unused `Session` argument from some attribute functions) - #109359 (Update stdarch) - #109378 (Remove Ty::is_region_ptr) - #109423 (Use region-erased self type during IAT selection) - #109447 (new solver cleanup + implement coherence) - #109501 (make link clickable) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-03-23Remove AliasRelationDirection::SupertypeMichael Goulet-67/+69
2023-03-23Rename AliasEq -> AliasRelateMichael Goulet-23/+27
2023-03-23Include relation direction in AliasEq predicateMichael Goulet-26/+80
2023-03-23Use span_look_ahead instead of next_pointMu42-6/+3
2023-03-22Rollup merge of #109447 - lcnr:coherence, r=compiler-errorsMatthias Krüger-49/+123
new solver cleanup + implement coherence the cleanup: - change `Certainty::unify_and` to consider ambig + overflow to be ambig - rename `trait_candidate_should_be_dropped_in_favor_of` to `candidate_should_be_dropped_in_favor_of` - remove outdated fixme For coherence I mostly just add an ambiguous candidate if the current trait ref is unknowable. I am doing the same for reservation impl where I also just add an ambiguous candidate.
2023-03-22Implement non-const Destruct trait in new solverMichael Goulet-0/+28
2023-03-22reviewlcnr-2/+1
2023-03-22stop special-casing `'static` in evaluatelcnr-78/+86
2023-03-22`HirId` to `LocalDefId` cleanuplcnr-5/+4
2023-03-22Fixes #109436: add parentheses properlyMu42-7/+28
2023-03-22Auto merge of #109119 - lcnr:trait-system-cleanup, r=compiler-errorsbors-222/+89
a general type system cleanup removes the helper functions `traits::fully_solve_X` as they add more complexity then they are worth. It's confusing which of these helpers should be used in which context. changes the way we deal with overflow to always add depth in `evaluate_predicates_recursively`. It may make sense to actually fully transition to not have `recursion_depth` on obligations but that's probably a bit too much for this PR. also removes some other small - and imo unnecessary - helpers. r? types
2023-03-21Rollup merge of #109446 - spastorino:new-rpitit-17, r=compiler-errorsMatthias Krüger-0/+1
Do not suggest bounds restrictions for synthesized RPITITs Before this PR we were getting ... ``` warning: the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes --> tests/ui/async-await/in-trait/missing-send-bound.rs:5:12 | 5 | #![feature(async_fn_in_trait)] | ^^^^^^^^^^^^^^^^^ | = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information = note: `#[warn(incomplete_features)]` on by default error: future cannot be sent between threads safely --> tests/ui/async-await/in-trait/missing-send-bound.rs:17:20 | 17 | assert_is_send(test::<T>()); | ^^^^^^^^^^^ future returned by `test` is not `Send` | = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `impl Future<Output = ()>` note: future is not `Send` as it awaits another future which is not `Send` --> tests/ui/async-await/in-trait/missing-send-bound.rs:13:5 | 13 | T::bar().await; | ^^^^^^^^ await occurs here on type `impl Future<Output = ()>`, which is not `Send` note: required by a bound in `assert_is_send` --> tests/ui/async-await/in-trait/missing-send-bound.rs:21:27 | 21 | fn assert_is_send(_: impl Send) {} | ^^^^ required by this bound in `assert_is_send` help: consider further restricting the associated type | 16 | fn test2<T: Foo>() where impl Future<Output = ()>: Send { | ++++++++++++++++++++++++++++++++++++ error: aborting due to previous error; 1 warning emitted ``` and we want this output ... ``` warning: the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/missing-send-bound.rs:5:12 | LL | #![feature(async_fn_in_trait)] | ^^^^^^^^^^^^^^^^^ | = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information = note: `#[warn(incomplete_features)]` on by default error: future cannot be sent between threads safely --> $DIR/missing-send-bound.rs:17:20 | LL | assert_is_send(test::<T>()); | ^^^^^^^^^^^ future returned by `test` is not `Send` | = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `impl Future<Output = ()>` note: future is not `Send` as it awaits another future which is not `Send` --> $DIR/missing-send-bound.rs:13:5 | LL | T::bar().await; | ^^^^^^^^ await occurs here on type `impl Future<Output = ()>`, which is not `Send` note: required by a bound in `assert_is_send` --> $DIR/missing-send-bound.rs:21:27 | LL | fn assert_is_send(_: impl Send) {} | ^^^^ required by this bound in `assert_is_send` error: aborting due to previous error; 1 warning emitted ``` r? `@compiler-errors`
2023-03-21Rollup merge of #109441 - oli-obk:fn_trait_new_solver, r=compiler-errorsMatthias Krüger-26/+32
Only implement Fn* traits for extern "Rust" safe function pointers and items Since calling the function via an `Fn` trait will assume `extern "Rust"` ABI and not do any safety checks, only safe `extern "Rust"` function can implement the `Fn` traits. This syncs the logic between the old solver and the new solver. r? `@compiler-errors`
2023-03-21Rollup merge of #109336 - compiler-errors:constrain-to-ct-err, r=BoxyUwUMatthias Krüger-1/+5
Constrain const vars to error if const types are mismatched When equating two consts of different types, if either are const variables, constrain them to the correct const error kind. This helps us avoid "successfully" matching a const against an impl signature but leaving unconstrained const vars, which will lead to incremental ICEs when we call const-eval queries during const projection. Fixes #109296 The second commit in the stack fixes a regression in the first commit where we end up mentioning `[const error]` in an impl overlap error message. I think the error message changes for the better, but I could implement alternative strategies to avoid this without delaying the overlap error message... r? `@BoxyUwU`
2023-03-21Do not suggest bounds restrictions for synthesized RPITITsSantiago Pastorino-0/+1
2023-03-21disable global caching during coherencelcnr-1/+2
2023-03-21enable `intercrate` in the solver `InferCtxt`lcnr-6/+18
2023-03-21new solver cleanup + coherencelcnr-42/+103
2023-03-21Rollup merge of #108896 - BoxyUwU:new_solver_add_goal_fn, r=lcnrnils-443/+531
new solver: make all goal evaluation able to be automatically rerun It is generally wrong to call `evaluate_goal` multiple times or `evaluate_goal` and `evaluate_all` for the same `QueryResult` without correctly handling rerunning the goals when inference makes progress. Not doing so will result in the assertion in `evaluate_goal` firing because rerunning the goal will lead to a more accurate `QueryResult`. Currently there are lots of places that get this wrong and generally it is complex and error prone to handle correctly everywhere. This PR introduces a way to add goals to the `EvalCtxt` and then run all the added goals in a loop so that `evaluate_goal`/`evaluate_all` is not necessary to call manually. There are a few complications for making everything work "right": 1. the `normalizes-to` hack that replaces the rhs with an unconstrained infer var requires special casing in the new `try_evaluate_added_goals` function similar to how `evaluate_goal`'s assertion special cases that hack. 2. `assemble_candidates_after_normalizing_self_ty`'s normalization step needs to be reran for each candidate otherwise the found candidates will potentially get a more accurate `QueryResult` when rerunning the projection/trait goal which can effect the `QueryResult` of the projection/trait goal. This is implemented via `EvalCtxt::probe`'s closure's `EvalCtxt` inheriting the added goals of the `EvalCtxt` that `probe` is called on, allowing us to add goals in a probe, and then enter a nested probe for each candidate and evaluate added goals which include the normalization step's goals. I made `make_canonical_response` evaluate added goals so that it will be hard to mess up the impl of the solver by forgetting to evaluate added goals. Right now the only way to mess this up would be to call `response_no_constraints` (which from the name is obviously weird). The visibility of `evaluate_goal` means that it can be called from various `compute_x_goal` or candidate assembly functions, this is generally wrong and we should never call `evaluate_goal` manually, instead we should be calling `add_goal`/`add_goals`. This is solved by moving `evaluate_goal` `evaluate_canonical_goal` and `compute_goal` into `eval_ctxt`'s module and making them private so they cannot be called from elsewhere, forcing people to call `add_goal/s` and `evaluate_added_goals_and_make_canonical_resposne`/`try_evaluate_added_goals` --- Other changes: - removed the `&& false` that was introduced to the assertion in `evaluate_goal` in #108839 - remove a `!self.did_overflow()` requirement in `search_graph.is_empty()` which causes goals that overflow to ICE - made `EvalCtxt::eq` take `&mut self` and add all the nested goals via `add_goals` instead of returning them as 99% of call sites just immediately called `EvalCtxt::add_goals` manually. r? `````@lcnr`````
2023-03-21Also check function items' signatures for Fn* trait compatibilityOli Scherer-5/+14
2023-03-21Deduplicate fn trait compatibility checksOli Scherer-28/+8
2023-03-21Only implement Fn* traits for extern "Rust" safe function pointers.Oli Scherer-1/+18
2023-03-21evaluate: improve and fix recursion depth handlinglcnr-52/+19
2023-03-21remove some trait solver helperslcnr-170/+70
they add more complexity then they are worth. It's confusing which of these helpers should be used in which context.
2023-03-20Enforce non-lifetime-binders in supertrait preds are not object safeMichael Goulet-1/+20
2023-03-19Delay overlap errors if errors are involvedMichael Goulet-1/+5
2023-03-17Fast path that skips over unchanged obligations in process_obligationsThe 8472-0/+23
- only borrow the refcell once per loop - avoid complex matches to reduce branch paths in the hot loop - use a by-ref fast path that avoids mutations at the expense of having false negatives
2023-03-17move `compute_goal` and `evaluate_x` methods to inner moduleBoxy-272/+272
2023-03-17fix bad assertionBoxy-13/+4
2023-03-17replace chain with two `add_goal`Boxy-16/+11
2023-03-17fix let else unformattingBoxy-5/+9
2023-03-17UNACEPTABLEBoxy-9/+9
2023-03-17add commentsBoxy-0/+5
Co-authored-by: lcnr <rust@lcnr.de>
2023-03-17add assertBoxy-2/+9
2023-03-17review nitsBoxy-14/+18
2023-03-17Rollup merge of #109198 - compiler-errors:new-rpitit-default-body, r=spastorinoMatthias Krüger-9/+13
Install projection from RPITIT to default trait method opaque correctly 1. For new lowering strategy `-Zlower-impl-trait-in-trait-to-assoc-ty`, install the correct default trait method projection predicates (RPITIT -> opaque). This makes default trait body tests pass! 2. Fix two WF-checking bugs -- first, we want to make sure that we're always looking for an opaque type in `check_return_position_impl_trait_in_trait_bounds`. That's because the RPITIT projections are normalized to opaques during wfcheck. Second, fix RPITIT's param-envs by not adding the projection predicates that we install on trait methods to make default RPITITs work -- I left a comment why. 3. Also, just a small drive-by for `rustc_on_unimplemented`. Not sure if it affects any tests, but can't hurt. r? ````@spastorino,```` based off of #109140
2023-03-17Rollup merge of #108958 - clubby789:unbox-the-hir, r=compiler-errorsMatthias Krüger-3/+0
Remove box expressions from HIR After #108516, `#[rustc_box]` is used at HIR->THIR lowering and this is no longer emitted, so it can be removed. This is based on top of #108471 to help with conflicts, so 43490488ccacd1a822e9c621f5ed6fca99959a0b is the only relevant commit (sorry for all the duplicated pings!) ````@rustbot```` label +S-blocked
2023-03-16replace usage of `evaluate_goal` with a new `add_goal`Boxy-254/+336
2023-03-16Rollup merge of #109171 - oli-obk:normalization_cleanup, r=compiler-errorsMatthias Krüger-77/+48
Some cleanups in our normalization logic Changed a match to be exhaustive and deduplicated some code. r? ```@compiler-errors``` this pulls out the uncontroversial part of https://github.com/rust-lang/rust/pull/108860
2023-03-16Rollup merge of #109166 - lcnr:define_opaque_types-explicit, r=oli-obkMatthias Krüger-80/+95
make `define_opaque_types` fully explicit based on the idea of #108389. Moved `define_opaque_types` into the actual operations, e.g. `eq`, instead of `infcx.at` because normalization doesn't use `define_opaque_types` and even creates it's own `At` with a different `define_opaque_types` internally. Somewhat surprisingly, coherence actually relies on `DefineOpaqueTypes::Yes` for soundness which was revealed because I've incorrectly used `DefineOpaqueTypes::No` in `equate_impl_headers`. It feels concerning that even though this is the case, we still sometimes use `DefineOpaqueTypes::No` in coherence. I did not look into this as part of this PR as it is purely changing the structure of the code without changing behavior in any way. r? ```@oli-obk```
2023-03-16Fix on_unimplemented_note for RPITITsMichael Goulet-7/+11
2023-03-15Rename impl_trait_in_trait_parent to impl_trait_in_trait_parent_fnSantiago Pastorino-2/+2
2023-03-15Revert "Auto merge of #107376 - aliemjay:remove-givens, r=lcnr"Rémy Rakic-7/+7
This reverts commit e84e5ff04a647ce28540300244a26ba120642eea, reversing changes made to 1716932743a7b3705cbf0c34db0c4e070ed1930d.