Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions library/core/src/bstr/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,35 @@ use crate::slice::SliceIndex;
use crate::{hash, ops, range};

#[unstable(feature = "bstr", issue = "134915")]
impl Ord for ByteStr {
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Ord for ByteStr {
#[inline]
fn cmp(&self, other: &ByteStr) -> Ordering {
Ord::cmp(&self.0, &other.0)
}
}

#[unstable(feature = "bstr", issue = "134915")]
impl PartialOrd for ByteStr {
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for ByteStr {
#[inline]
fn partial_cmp(&self, other: &ByteStr) -> Option<Ordering> {
PartialOrd::partial_cmp(&self.0, &other.0)
}
}

#[unstable(feature = "bstr", issue = "134915")]
impl PartialEq<ByteStr> for ByteStr {
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq<ByteStr> for ByteStr {
#[inline]
fn eq(&self, other: &ByteStr) -> bool {
self.0 == other.0
}
}

#[unstable(feature = "bstr", issue = "134915")]
impl Eq for ByteStr {}
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Eq for ByteStr {}

#[unstable(feature = "bstr", issue = "134915")]
impl hash::Hash for ByteStr {
Expand Down
9 changes: 6 additions & 3 deletions library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ use crate::{fmt, ops, range, slice, str};
/// ```
///
/// [str]: prim@str "str"
#[derive(PartialEq, Eq, Hash)]
#[derive(Hash)]
#[derive_const(PartialEq, Eq)]
#[stable(feature = "core_c_str", since = "1.64.0")]
#[rustc_diagnostic_item = "cstr_type"]
#[rustc_has_incoherent_inherent_impls]
Expand Down Expand Up @@ -684,15 +685,17 @@ impl PartialEq<&Self> for CStr {
// because `c_char` is `i8` (not `u8`) on some platforms.
// That is why this is implemented manually and not derived.
#[stable(feature = "rust1", since = "1.0.0")]
impl PartialOrd for CStr {
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for CStr {
#[inline]
fn partial_cmp(&self, other: &CStr) -> Option<Ordering> {
self.to_bytes().partial_cmp(other.to_bytes())
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl Ord for CStr {
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Ord for CStr {
#[inline]
fn cmp(&self, other: &CStr) -> Ordering {
self.to_bytes().cmp(other.to_bytes())
Expand Down
16 changes: 10 additions & 6 deletions library/core/src/panic/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ pub struct Location<'a> {
}

#[stable(feature = "panic_hooks", since = "1.10.0")]
impl PartialEq for Location<'_> {
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for Location<'_> {
fn eq(&self, other: &Self) -> bool {
// Compare col / line first as they're cheaper to compare and more likely to differ,
// while not impacting the result.
Expand All @@ -56,20 +57,23 @@ impl PartialEq for Location<'_> {
}

#[stable(feature = "panic_hooks", since = "1.10.0")]
impl Eq for Location<'_> {}
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Eq for Location<'_> {}

#[stable(feature = "panic_hooks", since = "1.10.0")]
impl Ord for Location<'_> {
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Ord for Location<'_> {
fn cmp(&self, other: &Self) -> Ordering {
self.file()
.cmp(other.file())
.then_with(|| self.line.cmp(&other.line))
.then_with(|| self.col.cmp(&other.col))
.then_with(const || self.line.cmp(&other.line))
.then_with(const || self.col.cmp(&other.col))
}
}

#[stable(feature = "panic_hooks", since = "1.10.0")]
impl PartialOrd for Location<'_> {
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for Location<'_> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
Expand Down
6 changes: 4 additions & 2 deletions library/core/src/str/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use crate::{ops, range};
/// culturally-accepted standards requires locale-specific data that is outside the scope of
/// the `str` type.
#[stable(feature = "rust1", since = "1.0.0")]
impl Ord for str {
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Ord for str {
#[inline]
fn cmp(&self, other: &str) -> Ordering {
self.as_bytes().cmp(other.as_bytes())
Expand Down Expand Up @@ -43,7 +44,8 @@ const impl Eq for str {}
/// culturally-accepted standards requires locale-specific data that is outside the scope of
/// the `str` type.
#[stable(feature = "rust1", since = "1.0.0")]
impl PartialOrd for str {
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for str {
#[inline]
fn partial_cmp(&self, other: &str) -> Option<Ordering> {
Some(self.cmp(other))
Expand Down
Loading