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
Today in IRC, dpc had a problem where he was trying to turn a RefCell<~Trait> into a &mut Trait and couldn't figure it out. The eventual solution that I came up with was
let val:&mutTrait = *&mut*refcell.borrow_mut()
(slightly modified; in his case the expression was being passed to a function that takes &mut Trait).
This was complicated to figure out and looks very confusing to anyone who doesn't understand that &mut *foo is required to trigger DerefMut, which is required to make the resulting ~Trait value (from *&mut *foo) be coercable to &mut Trait.
This should have been able to be written merely as *refcell.borrow_mut().
The text was updated successfully, but these errors were encountered:
Ah, our dear ~T -> &T/&mut T coercions. I hope they won't be part of a post-DST world, as manual reborrows should then work on all types.
The only sane way I know to get a &mut Traitafter DST is:
Today in IRC, dpc had a problem where he was trying to turn a
RefCell<~Trait>
into a&mut Trait
and couldn't figure it out. The eventual solution that I came up with was(slightly modified; in his case the expression was being passed to a function that takes
&mut Trait
).This was complicated to figure out and looks very confusing to anyone who doesn't understand that
&mut *foo
is required to triggerDerefMut
, which is required to make the resulting~Trait
value (from*&mut *foo
) be coercable to&mut Trait
.This should have been able to be written merely as
*refcell.borrow_mut()
.The text was updated successfully, but these errors were encountered: