]> git.lizzy.rs Git - rust.git/commit
std: Add AsRef/AsMut impls to Box/Rc/Arc
authorAlex Crichton <alex@alexcrichton.com>
Thu, 17 Sep 2015 06:17:39 +0000 (23:17 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 2 Oct 2015 15:57:48 +0000 (08:57 -0700)
commitdb76ac73309332927d04e4f8bf5d235dc6f32360
tree5af4d5f7ad60c9c8926c16966f9e4b9ae4b0d3df
parentd9d9ca1a025a944c552c027129cec984ffeeb41c
std: Add AsRef/AsMut impls to Box/Rc/Arc

These common traits were left off originally by accident from these smart
pointers, and a past attempt (#26008) to add them was later reverted (#26160)
due to unexpected breakge (#26096) occurring. The specific breakage in worry is
the meaning of this return value changed:

    let a: Box<Option<T>> = ...;
    a.as_ref()

Currently this returns `Option<&T>` but after this change it will return
`&Option<T>` because the `AsRef::as_ref` method shares the same name as
`Option::as_ref`. A [crater report][crater] of this change, however, has shown
that the fallout of this change is quite minimal. These trait implementations
are "the right impls to add" to these smart pointers and would enable various
generalizations such as those in #27197.

[crater]: https://gist.github.com/anonymous/0ba4c3512b07641c0f99

This commit is a breaking change for the above reasons mentioned, and the
mitigation strategies look like any of:

    Option::as_ref(&a)
    a.as_ref().as_ref()
    (*a).as_ref()
src/liballoc/arc.rs
src/liballoc/boxed.rs
src/liballoc/rc.rs