The code is fine. b refers to a lifetime-extended object that is the result of the expression a++, which is a different object from a. (Binding a temporary object to a reference extends the lifetime of the object to that of the reference.) You can use and modify both objects.