Proto-RFC: Expanded functional record update

I made some prototype for the alternative FRU desugaring (https://github.com/petrochenkov/rust/tree/fru).

As you can see the breakage is pretty significant (see the second commit).
In addition there are cases where the current semantics is actually desirable.

  • FRU from borrowed contexts, you can’t move the whole value, but can copy individual Copy fields.
  • Situations when some fields are simply copied, but others are somehow copied-and-transformed (see e.g. fold.rs in my patch). This cannot be done if the whole old value is moved out at the start.
  • Emulating Copy for types that can be Copy but don’t implement it for semantic reasons (e.g. iterators).

So the alternative semantics for FRU has to use some syntax distinct from the current one, and the current semantics needs to be kept.

If RFC 2061 is accepted and individual fields in Drop structs become consumable, then the only remaining major issue with the current semantics would be field privacy.

3 Likes