Skip to content

Commit 75a8d0d

Browse files
committed
Remove more impls that may cause inference failures
1 parent 9ccc52b commit 75a8d0d

File tree

2 files changed

+18
-51
lines changed

2 files changed

+18
-51
lines changed

library/alloc/src/bstr.rs

+12-27
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use core::borrow::{Borrow, BorrowMut};
77
#[unstable(feature = "bstr", issue = "134915")]
88
pub use core::bstr::ByteStr;
9-
use core::bstr::{impl_partial_eq, impl_partial_eq_ord, impl_partial_eq_ord_n};
9+
use core::bstr::{impl_partial_eq, impl_partial_eq_n, impl_partial_eq_ord};
1010
use core::cmp::Ordering;
1111
use core::ops::{
1212
Deref, DerefMut, DerefPure, Index, IndexMut, Range, RangeFrom, RangeFull, RangeInclusive,
@@ -165,21 +165,8 @@ impl Borrow<ByteStr> for ByteString {
165165
}
166166
}
167167

168-
#[unstable(feature = "bstr", issue = "134915")]
169-
impl Borrow<ByteStr> for Vec<u8> {
170-
#[inline]
171-
fn borrow(&self) -> &ByteStr {
172-
ByteStr::from_bytes(self.as_slice())
173-
}
174-
}
175-
176-
#[unstable(feature = "bstr", issue = "134915")]
177-
impl Borrow<ByteStr> for String {
178-
#[inline]
179-
fn borrow(&self) -> &ByteStr {
180-
ByteStr::from_bytes(self.as_bytes())
181-
}
182-
}
168+
// `impl Borrow<ByteStr> for Vec<u8>` omitted to avoid inference failures
169+
// `impl Borrow<ByteStr> for String` omitted to avoid inference failures
183170

184171
#[unstable(feature = "bstr", issue = "134915")]
185172
impl BorrowMut<[u8]> for ByteString {
@@ -197,13 +184,7 @@ impl BorrowMut<ByteStr> for ByteString {
197184
}
198185
}
199186

200-
#[unstable(feature = "bstr", issue = "134915")]
201-
impl BorrowMut<ByteStr> for Vec<u8> {
202-
#[inline]
203-
fn borrow_mut(&mut self) -> &mut ByteStr {
204-
ByteStr::from_bytes_mut(self.as_mut_slice())
205-
}
206-
}
187+
// `impl BorrowMut<ByteStr> for Vec<u8>` omitted to avoid inference failures
207188

208189
#[unstable(feature = "bstr", issue = "134915")]
209190
impl Default for ByteString {
@@ -563,20 +544,24 @@ macro_rules! impl_partial_eq_ord_cow {
563544
};
564545
}
565546

566-
impl_partial_eq_ord!(ByteString, Vec<u8>);
547+
// PartialOrd with `Vec<u8>` omitted to avoid inference failures
548+
impl_partial_eq!(ByteString, Vec<u8>);
567549
// PartialOrd with `[u8]` omitted to avoid inference failures
568550
impl_partial_eq!(ByteString, [u8]);
569551
// PartialOrd with `&[u8]` omitted to avoid inference failures
570552
impl_partial_eq!(ByteString, &[u8]);
571-
impl_partial_eq_ord!(ByteString, String);
553+
// PartialOrd with `String` omitted to avoid inference failures
554+
impl_partial_eq!(ByteString, String);
572555
// PartialOrd with `str` omitted to avoid inference failures
573556
impl_partial_eq!(ByteString, str);
574557
// PartialOrd with `&str` omitted to avoid inference failures
575558
impl_partial_eq!(ByteString, &str);
576559
impl_partial_eq_ord!(ByteString, ByteStr);
577560
impl_partial_eq_ord!(ByteString, &ByteStr);
578-
impl_partial_eq_ord_n!(ByteString, [u8; N]);
579-
impl_partial_eq_ord_n!(ByteString, &[u8; N]);
561+
// PartialOrd with `[u8; N]` omitted to avoid inference failures
562+
impl_partial_eq_n!(ByteString, [u8; N]);
563+
// PartialOrd with `&[u8; N]` omitted to avoid inference failures
564+
impl_partial_eq_n!(ByteString, &[u8; N]);
580565
impl_partial_eq_ord_cow!(ByteString, Cow<'_, ByteStr>);
581566
impl_partial_eq_ord_cow!(ByteString, Cow<'_, str>);
582567
impl_partial_eq_ord_cow!(ByteString, Cow<'_, [u8]>);

library/core/src/bstr.rs

+6-24
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ pub use impl_partial_eq_ord;
498498
#[doc(hidden)]
499499
#[macro_export]
500500
#[unstable(feature = "bstr_internals", issue = "none")]
501-
macro_rules! impl_partial_eq_ord_n {
501+
macro_rules! impl_partial_eq_n {
502502
($lhs:ty, $rhs:ty) => {
503503
#[allow(unused_lifetimes)]
504504
#[unstable(feature = "bstr", issue = "134915")]
@@ -519,32 +519,12 @@ macro_rules! impl_partial_eq_ord_n {
519519
PartialEq::eq(this, other.as_bytes())
520520
}
521521
}
522-
523-
#[allow(unused_lifetimes)]
524-
#[unstable(feature = "bstr", issue = "134915")]
525-
impl<const N: usize> PartialOrd<$rhs> for $lhs {
526-
#[inline]
527-
fn partial_cmp(&self, other: &$rhs) -> Option<Ordering> {
528-
let other: &[u8] = other.as_ref();
529-
PartialOrd::partial_cmp(self.as_bytes(), other)
530-
}
531-
}
532-
533-
#[allow(unused_lifetimes)]
534-
#[unstable(feature = "bstr", issue = "134915")]
535-
impl<const N: usize> PartialOrd<$lhs> for $rhs {
536-
#[inline]
537-
fn partial_cmp(&self, other: &$lhs) -> Option<Ordering> {
538-
let this: &[u8] = self.as_ref();
539-
PartialOrd::partial_cmp(this, other.as_bytes())
540-
}
541-
}
542522
};
543523
}
544524

545525
#[doc(hidden)]
546526
#[unstable(feature = "bstr_internals", issue = "none")]
547-
pub use impl_partial_eq_ord_n;
527+
pub use impl_partial_eq_n;
548528

549529
// PartialOrd with `[u8]` omitted to avoid inference failures
550530
impl_partial_eq!(ByteStr, [u8]);
@@ -554,8 +534,10 @@ impl_partial_eq!(ByteStr, &[u8]);
554534
impl_partial_eq!(ByteStr, str);
555535
// PartialOrd with `&str` omitted to avoid inference failures
556536
impl_partial_eq!(ByteStr, &str);
557-
impl_partial_eq_ord_n!(ByteStr, [u8; N]);
558-
impl_partial_eq_ord_n!(ByteStr, &[u8; N]);
537+
// PartialOrd with `[u8; N]` omitted to avoid inference failures
538+
impl_partial_eq_n!(ByteStr, [u8; N]);
539+
// PartialOrd with `[u8; N]` omitted to avoid inference failures
540+
impl_partial_eq_n!(ByteStr, &[u8; N]);
559541

560542
#[unstable(feature = "bstr", issue = "134915")]
561543
impl Ord for ByteStr {

0 commit comments

Comments
 (0)