Skip to content

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.

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
Contributor

bors commented Jun 4, 2023

📌 Commit f549cac has been approved by HKalbasi

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jun 4, 2023

⌛ Testing commit f549cac with merge 2f1b7ce...

@bors
Copy link
Contributor

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
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

Development

Successfully merging this pull request may close these issues.

thread 'Worker' panicked at 'index out of bounds: the len is 0 but the index is 0', chalk-ir-0.89.0\src\fold\subst.rs:55:19

5 participants