Uh oh!
There was an error while loading. Please reload this page.
RFC: Remove cross-borrowing - #112
Conversation
nrc
commented
Jun 9, 2014
Another alternative would be to disallow coercion to |
emberian
commented
Jun 9, 2014
+1. Let's get rid of this special case. |
lilyball
commented
Jun 9, 2014
+1 to removing coercion to |
sfackler
commented
Jun 9, 2014
I've always thought that implicit coercion to |
lilyball
commented
Jun 9, 2014
@sfackler Without this, post-DST with |
huonw
commented
Jun 10, 2014
+1 Cross borrowing to |
bstrie
commented
Jun 10, 2014
I'm all for removing special cases, but I do hope that eventually we reimplement it in a general way for user-defined smart pointers. Writing APIs that take references is our best means of avoiding combinatorial function explosion, but I've never seen anything but grumpiness and incredulity about the |
Accepted RFC #32: Remove cross-borrowing
alexcrichton
commented
Jun 25, 2014
This was discussed two weeks ago and we decided to merge. |
Summary
Remove the coercion from
Box<T>to&T/&mut Tfrom the language.Motivation
Currently, the coercion between
Box<T>to&mut Tcan be a hazard because it can lead to surprising mutation where it was not expected. Furthermore, it is inconsistent with user-defined smart pointers because user-defined smart pointers cannot implicitly coerceto&Tor&mut T.Detailed design
The coercion between
Box<T>and&T/&mut Tshould be removed.Note that methods that take
&self/&mut selfcan still be called on values of typeBox<T>without any special referencing or dereferencing. That is because the semantics of auto-deref and auto-ref conspire to make it work: the types unify after one autoderef followed by one autoref.Drawbacks
Borrowing from
Box<T>to&T/&mut Tmay be convenient.Alternatives
An alternative is to apply the method autoderef/autoref rules to all coercions in the language. This makes the mutability hazard more prevalent, however.
The impact of not doing this is that the coercion will remain.
Unresolved questions
None.