Add some AsRef implementations for smart pointers by MatthijsKok · Pull Request #139318 · rust-lang/rust (original) (raw)

I am not confident than any of these can be added without widespread breakage. For example, the new Box impls break pretty reasonable-looking code like the following:

error[E0283]: type annotations needed --> src/main.rs:3:22 | 3 | println!("{}", b.as_ref()); | ^^^^^^ | = note: multiple impls satisfying Box<str>: AsRef<_> found in the following crates: alloc, std: - impl AsRef for Box; - impl AsRef for Box; - impl AsRef<[u8]> for Box<str, A> where A: Allocator; - impl<T, A> AsRef for Box<T, A> where A: Allocator, T: ?Sized; help: try using a fully qualified path to specify the expected types | 3 - println!("{}", b.as_ref()); 3 + println!("{}", <Box as AsRef>::as_ref(&b)); |

If you'd like to see a crater run, I would recommend starting with just 1 single new impl, whichever of these is your favorite. Please send a separate PR for each impl that we should crater, and we can keep this PR as-is to keep track of all the impls we'd ideally like to add.