]> git.lizzy.rs Git - rust.git/commit
Change destination accessor to return references
authorSimonas Kazlauskas <git@kazlauskas.me>
Thu, 7 Jan 2016 13:08:02 +0000 (15:08 +0200)
committerSimonas Kazlauskas <git@kazlauskas.me>
Fri, 8 Jan 2016 12:40:32 +0000 (14:40 +0200)
commit2f86c1605c3a82d0c82c36f1dc84441237a9f5c1
tree6dc0722392fa53ac91df50f3b83bfb05e5327419
parent64a8ffeffaae2fe72994fb0832ae525346b8a3c0
Change destination accessor to return references

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.
src/librustc/mir/repr.rs
src/librustc_mir/transform/erase_regions.rs
src/librustc_trans/trans/mir/block.rs