Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DerefMut needs to be able to be triggered by implicit coercion to &mut Trait #13305

Closed
lilyball opened this issue Apr 4, 2014 · 4 comments
Closed

Comments

@lilyball
Copy link
Contributor

lilyball commented Apr 4, 2014

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: &mut Trait = *&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().

@eddyb
Copy link
Member

eddyb commented Apr 4, 2014

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 Trait after DST is:

let val: &mut Trait = &mut **refcell.borrow_mut();

@nikomatsakis
Copy link
Contributor

cc me

@nikomatsakis
Copy link
Contributor

I think this is basically a dup of #6308 (DST)

@alexcrichton
Copy link
Member

Due to the removal of implicit coercions between Box<T> and &T and friends, I believe this is closed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants