You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Presently the mutable getters on RefMut require that the self parameter has the same lifetime as the inner reference. So for a type like this Message, we generate getters as shown below:
Note how the getters require &'a mut self, when self also contains a &'a mut Message{A,B}.
This lifetime restriction prevents converting a MessageRefMut into a reference that outlives the RefMut itself, e.g.
// Does not compilefnget_x(message:&mutMessage) -> &mutString{
message.to_mut().x_mut()}
This pattern may be useful sometimes, and is possible with an ordinary mutable reference, i.e. if we had just &'a mut Message{A,B} we could get a &'a mut to one of its fields.
To fix the issue I propose we generate additional moving getters on RefMut that take self by value:
Presently the mutable getters on
RefMut
require that theself
parameter has the same lifetime as the inner reference. So for a type like thisMessage
, we generate getters as shown below:Note how the getters require
&'a mut self
, whenself
also contains a&'a mut Message{A,B}
.This lifetime restriction prevents converting a
MessageRefMut
into a reference that outlives theRefMut
itself, e.g.This pattern may be useful sometimes, and is possible with an ordinary mutable reference, i.e. if we had just
&'a mut Message{A,B}
we could get a&'a mut
to one of its fields.To fix the issue I propose we generate additional moving getters on
RefMut
that takeself
by value:This is a similar pattern to
hash_map::OccupiedEntry::into_mut
.NB: this issue doesn't affect
Ref
because it uses immutable references:message.to_ref().x()
is fine.The text was updated successfully, but these errors were encountered: