diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 4644e37f809c1..6286d9fa52bbd 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -2043,6 +2043,13 @@ impl AsRef for Box { } } +#[stable(feature = "smart_ptr_as_ref_str", since = "CURRENT_RUSTC_VERSION")] +impl AsRef<[u8]> for Box { + fn as_ref(&self) -> &[u8] { + (&**self).as_ref() + } +} + #[stable(since = "1.5.0", feature = "smart_ptr_as_ref")] impl AsMut for Box { fn as_mut(&mut self) -> &mut T { diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 619d9f258e342..b33b8e11c2977 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -3655,6 +3655,13 @@ impl AsRef for Rc { } } +#[stable(feature = "smart_ptr_as_ref_str", since = "CURRENT_RUSTC_VERSION")] +impl AsRef<[u8]> for Rc { + fn as_ref(&self) -> &[u8] { + (&**self).as_ref() + } +} + #[stable(feature = "pin", since = "1.33.0")] impl Unpin for Rc {} diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index aa25ff5293c71..f3254cd4f97f8 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -1701,6 +1701,22 @@ impl AsRef for String { } } +#[stable(feature = "smart_ptr_as_ref_str", since = "CURRENT_RUSTC_VERSION")] +impl AsRef for Box { + #[inline] + fn as_ref(&self) -> &OsStr { + (&**self).as_ref() + } +} + +#[stable(feature = "smart_ptr_as_ref_str", since = "CURRENT_RUSTC_VERSION")] +impl AsRef for Rc { + #[inline] + fn as_ref(&self) -> &OsStr { + (&**self).as_ref() + } +} + impl FromInner for OsString { #[inline] fn from_inner(buf: Buf) -> OsString { diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 980213be7ea90..f22a44c6e736a 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -3358,6 +3358,22 @@ impl AsRef for PathBuf { } } +#[stable(feature = "smart_ptr_as_ref_str", since = "CURRENT_RUSTC_VERSION")] +impl AsRef for Box { + #[inline] + fn as_ref(&self) -> &Path { + Path::new(self) + } +} + +#[stable(feature = "smart_ptr_as_ref_str", since = "CURRENT_RUSTC_VERSION")] +impl AsRef for Rc { + #[inline] + fn as_ref(&self) -> &Path { + Path::new(self) + } +} + #[stable(feature = "path_into_iter", since = "1.6.0")] impl<'a> IntoIterator for &'a PathBuf { type Item = &'a OsStr;