-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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] Change destination accessor to return references #30761
Conversation
☔ The latest upstream changes (presumably #30757) made this pull request unmergeable. Please resolve the merge conflicts. |
@@ -425,7 +425,7 @@ pub trait MutVisitor<'tcx> { | |||
} | |||
|
|||
Terminator::Call { ref mut func, ref mut args, ref mut kind } => { | |||
if let Some(ref mut destination) = kind.destination() { |
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.
indeed, this was definitely a bug.
r+ but I suspect this conflicted with @michaelwoerister's macroization of the visitor |
Previously it was returning a value, mostly for the two reasons: * Cloning Lvalue is very cheap most of the time (i.e. when Lvalue is not a Projection); * There’s users who want &mut lvalue and there’s users who want &lvalue. Returning a value allows to make either one easier when pattern matching (i.e. Some(ref dest) or Some(ref mut dest)). However, I’m now convinced this is an invalid approach. Namely the users which want a mutable reference may modify the Lvalue in-place, but the changes won’t be reflected in the final MIR, since the Lvalue modified is merely a clone. Instead, we have two accessors `destination` and `destination_mut` which return a reference to the destination in desired mode.
37f4ff0
to
2f86c16
Compare
Before #30757 this actually caused a bug in the |
@bors r+ |
📌 Commit 2f86c16 has been approved by |
…elwoerister Previously it was returning a clone, mostly for the two reasons: * Cloning Lvalue is very cheap most of the time (i.e. when Lvalue is not a Projection); * There’s users who want &mut lvalue and there’s users who want &lvalue. Returning a value allows to make either one easier when pattern matching (i.e. Some(ref dest) or Some(ref mut dest)). However, I’m now convinced this is an invalid approach. Namely the users which want a mutable reference may modify the Lvalue in-place, but the changes won’t be reflected in the final MIR, since the Lvalue modified is merely a clone. Instead, we have two accessors `destination` and `destination_mut` which return a reference to the destination in desired mode. r? @nikomatsakis
Previously it was returning a clone, mostly for the two reasons: * Cloning Lvalue is very cheap most of the time (i.e. when Lvalue is not a Projection); * There’s users who want &mut lvalue and there’s users who want &lvalue. Returning a value allows to make either one easier when pattern matching (i.e. Some(ref dest) or Some(ref mut dest)). However, I’m now convinced this is an invalid approach. Namely the users which want a mutable reference may modify the Lvalue in-place, but the changes won’t be reflected in the final MIR, since the Lvalue modified is merely a clone. Instead, we have two accessors `destination` and `destination_mut` which return a reference to the destination in desired mode. r? @nikomatsakis
@bors: retry force |
…elwoerister Previously it was returning a clone, mostly for the two reasons: * Cloning Lvalue is very cheap most of the time (i.e. when Lvalue is not a Projection); * There’s users who want &mut lvalue and there’s users who want &lvalue. Returning a value allows to make either one easier when pattern matching (i.e. Some(ref dest) or Some(ref mut dest)). However, I’m now convinced this is an invalid approach. Namely the users which want a mutable reference may modify the Lvalue in-place, but the changes won’t be reflected in the final MIR, since the Lvalue modified is merely a clone. Instead, we have two accessors `destination` and `destination_mut` which return a reference to the destination in desired mode. r? @nikomatsakis
Previously it was returning a clone, mostly for the two reasons:
to make either one easier when pattern matching (i.e. Some(ref dest) or Some(ref mut dest)).
However, I’m now convinced this is an invalid approach. Namely the users which want a mutable
reference may modify the Lvalue in-place, but the changes won’t be reflected in the final MIR,
since the Lvalue modified is merely a clone.
Instead, we have two accessors
destination
anddestination_mut
which return a reference to thedestination in desired mode.
r? @nikomatsakis