diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index 0664f2c3cf2..999776fd904 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -90,7 +90,7 @@ macro_rules! specialize_for_lengths { $num => { for s in iter { copy_slice_and_advance!(target, sep_bytes); - let content_bytes = s.borrow().as_ref(); + let content_bytes: &[_] = s.borrow().as_ref(); copy_slice_and_advance!(target, content_bytes); } }, @@ -99,7 +99,7 @@ macro_rules! specialize_for_lengths { // arbitrary non-zero size fallback for s in iter { copy_slice_and_advance!(target, sep_bytes); - let content_bytes = s.borrow().as_ref(); + let content_bytes: &[_] = s.borrow().as_ref(); copy_slice_and_advance!(target, content_bytes); } } diff --git a/library/core/src/bstr/mod.rs b/library/core/src/bstr/mod.rs index c8d0c701ba8..9c292f2b7c4 100644 --- a/library/core/src/bstr/mod.rs +++ b/library/core/src/bstr/mod.rs @@ -201,7 +201,13 @@ impl AsRef for ByteStr { } } -// `impl AsRef for [u8]` omitted to avoid widespread inference failures +#[unstable(feature = "bstr", issue = "134915")] +impl AsRef for [u8] { + #[inline] + fn as_ref(&self) -> &ByteStr { + ByteStr::new(self) + } +} #[unstable(feature = "bstr", issue = "134915")] impl AsRef for str { diff --git a/src/tools/clippy/tests/ui/useful_asref.rs b/src/tools/clippy/tests/ui/useful_asref.rs index a37c2785bde..fa548e4cd7b 100644 --- a/src/tools/clippy/tests/ui/useful_asref.rs +++ b/src/tools/clippy/tests/ui/useful_asref.rs @@ -7,7 +7,7 @@ trait Trait { fn as_ptr(&self); } -impl<'a> Trait for &'a [u8] { +impl<'a> Trait for &'a [u32] { fn as_ptr(&self) { self.as_ref().as_ptr(); }