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
Conversation
2eb0881
to
585965a
Compare
- use `DefWithBodyId::as_generic_def_id()` - add comments on `InferenceResult` invariant - move local helper function to bottom to comply with style guide
585965a
to
a3789ea
Compare
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@bors r+ |
☀️ Test successful - checks-actions |
…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.
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 inCapturedItemWithoutTy::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.