Skip to content

Commit 3317391

Browse files
committed
Implement AsRef<ByteStr> for [u8]
This impl was omitted from #135073 due to inference failures. Add it separately to judge its impact.
1 parent c211076 commit 3317391

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

library/alloc/src/str.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ macro_rules! specialize_for_lengths {
9090
$num => {
9191
for s in iter {
9292
copy_slice_and_advance!(target, sep_bytes);
93-
let content_bytes = s.borrow().as_ref();
93+
let content_bytes: &[_] = s.borrow().as_ref();
9494
copy_slice_and_advance!(target, content_bytes);
9595
}
9696
},
@@ -99,7 +99,7 @@ macro_rules! specialize_for_lengths {
9999
// arbitrary non-zero size fallback
100100
for s in iter {
101101
copy_slice_and_advance!(target, sep_bytes);
102-
let content_bytes = s.borrow().as_ref();
102+
let content_bytes: &[_] = s.borrow().as_ref();
103103
copy_slice_and_advance!(target, content_bytes);
104104
}
105105
}

library/core/src/bstr/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,13 @@ impl AsRef<ByteStr> for ByteStr {
201201
}
202202
}
203203

204-
// `impl AsRef<ByteStr> for [u8]` omitted to avoid widespread inference failures
204+
#[unstable(feature = "bstr", issue = "134915")]
205+
impl AsRef<ByteStr> for [u8] {
206+
#[inline]
207+
fn as_ref(&self) -> &ByteStr {
208+
ByteStr::new(self)
209+
}
210+
}
205211

206212
#[unstable(feature = "bstr", issue = "134915")]
207213
impl AsRef<ByteStr> for str {

src/tools/clippy/tests/ui/useful_asref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trait Trait {
77
fn as_ptr(&self);
88
}
99

10-
impl<'a> Trait for &'a [u8] {
10+
impl<'a> Trait for &'a [u32] {
1111
fn as_ptr(&self) {
1212
self.as_ref().as_ptr();
1313
}

0 commit comments

Comments
 (0)