-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Access individual fields of tuples, closures and generators on drop. #49822
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
// Closures and generators also have disjoint fields, but they are only | ||
// directly accessed in the body of the closure/generator. | ||
ty::TyClosure(def, substs) | ||
| ty::TyGenerator(def, substs, ..) |
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.
Generators are a bit funny -- I'm not sure if upvar_tys
is correct for that case?
Maybe @Zoxc can comment how to get the list of fields for a generator type, else I'll dig in later.
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.
I think this is correct here. upvar_tys
gives you just the upvars for a generator. Pre-transform generators have an additional u32
state field, but it's only used when constructing a generator and it is never accessed.
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.
This looks good (modulo generators), though I keep having this nagging feeling we can refactor this another way. But this seems like it is extending the existing fix, which is fine.
src/librustc_mir/borrow_check/mod.rs
Outdated
@@ -740,6 +740,30 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { | |||
self.visit_terminator_drop(loc, term, flow_state, &place, field_ty, span); | |||
} | |||
} | |||
// Same as above, but for tuples. | |||
ty::TyTuple(tys) => { |
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.
Hmm, maybe we can extract a helper function here? If feels a bit silly to have basically the same code repeated so many times.
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.
Done. I preferred a closure to avoid having to pass all of the captured variables as arguments.
6023d6c
to
dab4884
Compare
Ping from triage! Could @nikomatsakis (or someone else from @rust-lang/compiler) review this? |
@bors r+ |
📌 Commit dab4884 has been approved by |
⌛ Testing commit dab488406f5f948e6f61e793f0f498233a781cfc with merge 6e9d3f14539a96ebcfcb7ee4312592b490318750... |
💔 Test failed - status-appveyor |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
dab4884
to
902bc0f
Compare
@bors r+ |
📌 Commit 902bc0f has been approved by |
@bors p=6 |
Access individual fields of tuples, closures and generators on drop. Fixes #48623, by extending the change in #47917 to closures. Also does this for tuples and generators for consistency. Enums are unchanged because there is now way to borrow `*enum.field` without borrowing `enum.field` at the moment, so any error would be reported when the enum goes out of scope. Unions aren't changed because unions they don't automatically drop their fields. r? @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
Fixes #48623, by extending the change in #47917 to closures. Also does this for tuples and generators for consistency.
Enums are unchanged because there is no way to borrow
*enum.field
without borrowingenum.field
at the moment, so any error would be reported when the enum goes out of scope. Unions aren't changed because unions they don't automatically drop their fields.r? @nikomatsakis