-
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
MIR-borrowck: immutable unique closure upvars can be mutated #46236
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
This isn't quite working yet and I'm not quite sure why. I think I've followed the instructions left on the issue correctly. |
src/librustc/mir/mod.rs
Outdated
@@ -544,8 +544,8 @@ impl<'tcx> LocalDecl<'tcx> { | |||
pub struct UpvarDecl { | |||
pub debug_name: Name, | |||
|
|||
/// If true, the capture is behind a reference. | |||
pub by_ref: bool | |||
/// If None then the capture is by-value. |
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.
nit: rename it to pub capture_mode: Option<BorrowKind>
?
src/librustc_mir/borrow_check.rs
Outdated
|
||
if let Some(field) = field_projection { | ||
let decl = &self.mir.upvar_decls[field.index()]; | ||
if let Some(borrow_kind) = decl.by_ref { |
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.
nit: if let Some(BorrowKind::Unique) = decl.by_ref {
I think you also need to change |
src/librustc_mir/borrow_check.rs
Outdated
}; | ||
|
||
if let Lvalue::Static(_) = lvalue { | ||
self.report_assignment_to_static(context, (lvalue, span)); | ||
} | ||
|
||
if let Some(mpi) = self.move_path_for_lvalue(lvalue) { |
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.
You still need the move_path_closest_to
change here. Also, for assignments you want to move_path_closest_to
the original lvalue, not the result of is_mutable
, in order to allow
fn main() {
let x: (u32, u32);
x.0 = 0;
x.1 = 1;
}
BTW, if you're already at this, you could also fix #46160 by marking the closure argument (argument |
☔ The latest upstream changes (presumably #46041) made this pull request unmergeable. Please resolve the merge conflicts. |
Pushed a compiling version of the last changes and rebased ontop of the current master. Wasn't sure what to use for the new parameter to |
@bors r+ |
📌 Commit c6b1ba5 has been approved by |
MIR-borrowck: immutable unique closure upvars can be mutated Fixes #46023 and #46160 (see [this comment](#46236 (comment))).
☀️ Test successful - status-appveyor, status-travis |
This should have been merged like this, |
Hmm. Maybe, but I'm not sure. I guess it depends on how you view the (On the other hand, maybe it's nice to have all the upvar information collected in one place...) ( <grumpy> I still think we should just drop the notion of declaring local variables as |
Fixes #46023 and #46160 (see this comment).