Skip to content

fix: handle lifetime variables in projection normalization #13223

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

Merged
merged 1 commit into from
Sep 12, 2022

Conversation

lowr
Copy link
Contributor

@lowr lowr commented Sep 12, 2022

Fixes #12674

The problem is that we've been skipping the binders of normalized projections assuming they should be empty, but the assumption is unfortunately wrong. We may get back lifetime variables and should handle them before returning them as normalized projections. For those who are curious why we get those even though we treat all lifetimes as 'static, this comment in chalk may be interesting.

I thought using InferenceTable would be cleaner than the other ways as it already has the methods for canonicalization, normalizing projection, and resolving variables, so moved goal building and trait solving logic to a new HirDatabase query. I made it transparent query as the query itself doesn't do much work but the eventual call to HirDatabase::trait_solve_query() does.

@Veykril
Copy link
Member

Veykril commented Sep 12, 2022

Thanks!
@bors r+

@bors
Copy link
Contributor

bors commented Sep 12, 2022

📌 Commit efb5616 has been approved by Veykril

It is now in the queue for this repository.

@flodiebold
Copy link
Member

@bors r+

thanks!

@bors
Copy link
Contributor

bors commented Sep 12, 2022

⌛ Testing commit efb5616 with merge 4070b58...

bors added a commit that referenced this pull request Sep 12, 2022
fix: handle lifetime variables in projection normalization

Fixes #12674

The problem is that we've been skipping the binders of normalized projections assuming they should be empty, but the assumption is unfortunately wrong. We may get back lifetime variables and should handle them before returning them as normalized projections. For those who are curious why we get those even though we treat all lifetimes as 'static, [this comment in chalk](https://github.com/rust-lang/chalk/blob/d875af0ff196dd6430b5f5fd87a640fa5ab59d1e/chalk-solve/src/infer/unify.rs#L888-L908) may be interesting.

I thought using `InferenceTable` would be cleaner than the other ways as it already has the methods for canonicalization, normalizing projection, and resolving variables, so moved goal building and trait solving logic to a new `HirDatabase` query. I made it transparent query as the query itself doesn't do much work but the eventual call to `HirDatabase::trait_solve_query()` does.
@bors
Copy link
Contributor

bors commented Sep 12, 2022

💡 This pull request was already approved, no need to approve it again.

  • This pull request is currently being tested. If there's no response from the continuous integration service, you may use retry to trigger a build again.

@bors
Copy link
Contributor

bors commented Sep 12, 2022

📌 Commit efb5616 has been approved by flodiebold

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Sep 12, 2022

⌛ Testing commit efb5616 with merge b1a4ba3...

@bors
Copy link
Contributor

bors commented Sep 12, 2022

☀️ Test successful - checks-actions
Approved by: flodiebold
Pushing b1a4ba3 to master...

@bors bors merged commit b1a4ba3 into rust-lang:master Sep 12, 2022
bors added a commit that referenced this pull request Sep 13, 2022
fixup: remove unnecessary `Option`

Fixup for #13223, two things:

- `normalize_projection_query()` (and consequently `HirDatabase::normalize_projection()`) never returns `None` (well, it used to when I first wrote it...), so just return `Ty` instead of `Option<Ty>`
- When chalk cannot normalize projection uniquely, `normalize_trait_assoc_type()` used to return `None` before #13223, but not anymore because of the first point. I restored the behavior so its callers work as before.
bors added a commit that referenced this pull request Dec 25, 2022
…r=lowr

fix: handle lifetime variables in `CallableSig` query

Fixes #13838

The problem is similar to #13223: we've been skipping non-empty binders, letting lifetime bound variables escape.

I ended up refactoring `hir_ty::callable_sig_from_fnonce()`. Like #13223, I chose to make use of `InferenceTable` which is capable of handling variables (I feel we should always use it when we solve trait-related stuff instead of manually building obligations/queries).

I couldn't make up a test that crashes without this patch (since the function I'm fixing is only used *outside* `hir-ty`, simple `hir-ty` test wouldn't cause crash), but at least I tested with my local build and made sure it doesn't crash with the code in the original issue. I'd appreciate any help to find a regression test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

panic: textDocument/inlayHint: index out of bounds: the len is 0 but the index is 0
4 participants