Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: consider outer binders when folding captured items' type #14971

Merged
merged 3 commits into from Jun 4, 2023

Conversation

lowr
Copy link
Contributor

@lowr lowr commented Jun 4, 2023

Fixes #14966

Basically, the crash is caused by us producing a broken type and passing it to chalk: &dyn for<type> [for<> Implemented(^1.0: A<^0.0>)] (notice the innermost bound var ^0.0 has no corresponding binder). It's created in CapturedItemWithoutTy::with_ty(), which didn't consider outer binders when folding types to replace placeholders with bound variables.

The fix is one-liner, but I've also refactored the surrounding code a little.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 4, 2023
@lowr lowr force-pushed the fix/captured-item-ty-outer-binder branch from 2eb0881 to 585965a Compare June 4, 2023 10:20
lowr added 2 commits June 4, 2023 19:38
- use `DefWithBodyId::as_generic_def_id()`
- add comments on `InferenceResult` invariant
- move local helper function to bottom to comply with style guide
@lowr lowr force-pushed the fix/captured-item-ty-outer-binder branch from 585965a to a3789ea Compare June 4, 2023 10:44
@lowr
Copy link
Contributor Author

lowr commented Jun 4, 2023

Split into two commits since it was getting obscure what the fix is.

@@ -575,6 +579,8 @@ impl<'a> InferenceContext<'a> {
// used this function for another workaround, mention it here. If you really need this function and believe that
// there is no problem in it being `pub(crate)`, remove this comment.
pub(crate) fn resolve_all(self) -> InferenceResult {
// NOTE: `InferenceResult::closure_info` is `resolve_completely()`'d during
// `InferenceContext::infer_closures()` (in `HirPlace::ty()` specifically).
let InferenceContext { mut table, mut result, .. } = self;
Copy link
Member

@Veykril Veykril Jun 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given your comment, it might help to destructure result here so that when a new field is added it will error here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, I'll do that!

so that whenever new fields are added we don't forget to handle them.
@HKalbasi
Copy link
Member

HKalbasi commented Jun 4, 2023

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 4, 2023

📌 Commit f549cac has been approved by HKalbasi

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Jun 4, 2023

⌛ Testing commit f549cac with merge 2f1b7ce...

@bors
Copy link
Collaborator

bors commented Jun 4, 2023

☀️ Test successful - checks-actions
Approved by: HKalbasi
Pushing 2f1b7ce to master...

@bors bors merged commit 2f1b7ce into rust-lang:master Jun 4, 2023
10 checks passed
Kmeakin pushed a commit to Kmeakin/rust-analyzer that referenced this pull request Jun 5, 2023
…r, r=HKalbasi

fix: consider outer binders when folding captured items' type

Fixes rust-lang#14966

Basically, the crash is caused by us producing a broken type and passing it to chalk: `&dyn for<type> [for<> Implemented(^1.0: A<^0.0>)]` (notice the innermost bound var `^0.0` has no corresponding binder). It's created in `CapturedItemWithoutTy::with_ty()`, which didn't consider outer binders when folding types to replace placeholders with bound variables.

The fix is one-liner, but I've also refactored the surrounding code a little.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
5 participants