-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Remove cross-borrowing #112
Conversation
Another alternative would be to disallow coercion to |
+1. Let's get rid of this special case. |
+1 to removing coercion to |
I've always thought that implicit coercion to |
@sfackler Without this, post-DST with |
+1 Cross borrowing to |
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
This was discussed two weeks ago and we decided to merge. |
Summary
Remove the coercion from
Box<T>
to&T
/&mut T
from the language.Motivation
Currently, the coercion between
Box<T>
to&mut T
can 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&T
or&mut T
.Detailed design
The coercion between
Box<T>
and&T
/&mut T
should be removed.Note that methods that take
&self
/&mut self
can 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 T
may 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.