-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Avoid writing a temporary closure kind #34986
Conversation
We used to write a temporary closure kind into the inference table, but this could lead to obligations being incorrectled resolved before inference had completed. This result could then be cached, leading to further trouble. This patch avoids writing any closure kind until the computation is complete. Fixes rust-lang#34349.
I would prefer passing the "during_closure_kind_inference" flag to MC (through EUV) rather than a on-infcx flag. Are you sure the value of the closure kind is not needed for upvar inference to work correctly? Using EUV/MC in this context feels super-dubious, but it is what we have now. |
I started this way, but mainly stopped because it seemed like it was affecting a lot of code. The flag has to be passed through both the MC and EUV. But I can do it that way if you prefer; I agree it's mildly cleaner (and hence the reason I started that way).
I didn't go back digging through the code, so I don't have citations, but indeed it's how it was designed to work. IIRC we translate a reference to an upvar |
We used to put the flag on the `InferCtxt`.
@arielb1 moved flag. |
@@ -259,7 +263,7 @@ impl<'a, 'gcx, 'tcx> AdjustBorrowKind<'a, 'gcx, 'tcx> { | |||
}) | |||
} | |||
|
|||
fn adjust_upvar_borrow_kind_for_consume(&self, | |||
fn adjust_upvar_borrow_kind_for_consume(&mut self, | |||
cmt: mc::cmt<'tcx>, | |||
mode: euv::ConsumeMode) | |||
{ |
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.
The code below is, like, super-dubious. Why is the guarantor supposed to be a deref of anything when we are moving out of a closure?
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.
cc #30046
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.
The code below is, like, super-dubious. Why is the guarantor supposed to be a deref of anything when we are moving out of a closure?
I'll have to re-read it, but I imagine because we are hard-coding the closure upvar kind to Fn
.
The code at OTOH, beta probably wants this fix, so @bors r+ and leave the cleanup to another commit. |
📌 Commit 63eb4d9 has been approved by |
Avoid writing a temporary closure kind We used to write a temporary closure kind into the inference table, but this could lead to obligations being incorrectled resolved before inference had completed. This result could then be cached, leading to further trouble. This patch avoids writing any closure kind until the computation is complete. Fixes #34349. r? @arielb1 -- what do you think?
Backport rust-lang#34986 to beta
We used to write a temporary closure kind into the inference table, but
this could lead to obligations being incorrectled resolved before
inference had completed. This result could then be cached, leading to
further trouble. This patch avoids writing any closure kind until the
computation is complete.
Fixes #34349.
r? @arielb1 -- what do you think?