rust-lang/rfcs — pull request #112 by pcwalton (2014-06-09 22:11:53+00:00)
Title: RFC: Remove cross-borrowing

- Start Date: 2014-06-09
- RFC PR #: (leave this empty)
- Rust Issue #: #10504

# Summary

Remove the coercion from `Box` to `&T`/`&mut T` from the language.

# Motivation

Currently, the coercion between `Box` 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` and `&T`/`&mut T` should be removed.

Note that methods that take `&self`/`&mut self` can still be called on values of type `Box` 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` 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.