1#![stable(feature = "rust1", since = "1.0.0")]
27
28mod bytewise;
29mod clamp;
30pub(crate) use bytewise::BytewiseEq;
31#[unstable(feature = "clamp_bounds", issue = "147781")]
32pub use clamp::ClampBounds;
33
34use self::Ordering::*;
35use crate::marker::{Destruct, PointeeSized};
36use crate::ops::ControlFlow;
37
38#[lang = "partial_eq"]
244#[stable(feature = "rust1", since = "1.0.0")]
245#[doc(alias = "==")]
246#[doc(alias = "!=")]
247#[diagnostic::on_unimplemented(
248 message = "can't compare `{Self}` with `{Rhs}`",
249 label = "no implementation for `{Self} == {Rhs}`"
250)]
251#[rustc_diagnostic_item = "PartialEq"]
252#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
253pub const trait PartialEq<Rhs: PointeeSized = Self>: PointeeSized {
254 #[must_use]
259 #[stable(feature = "rust1", since = "1.0.0")]
260 #[rustc_diagnostic_item = "cmp_partialeq_eq"]
261 fn eq(&self, other: &Rhs) -> bool;
262
263 #[inline]
275 #[must_use]
276 #[stable(feature = "rust1", since = "1.0.0")]
277 #[rustc_diagnostic_item = "cmp_partialeq_ne"]
278 fn ne(&self, other: &Rhs) -> bool {
279 !self.eq(other)
280 }
281}
282
283#[rustc_builtin_macro]
286#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
287#[allow_internal_unstable(core_intrinsics, structural_match)]
288pub macro PartialEq($item:item) {
289 }
291
292#[doc(alias = "==")]
349#[doc(alias = "!=")]
350#[stable(feature = "rust1", since = "1.0.0")]
351#[lang = "eq"]
352#[rustc_diagnostic_item = "Eq"]
353#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
354pub const trait Eq: [const] PartialEq<Self> + PointeeSized {
355 #[doc(hidden)]
360 #[coverage(off)]
361 #[inline]
362 #[stable(feature = "rust1", since = "1.0.0")]
363 #[rustc_diagnostic_item = "assert_receiver_is_total_eq"]
364 #[deprecated(since = "1.95.0", note = "implementation detail of `#[derive(Eq)]`")]
365 fn assert_receiver_is_total_eq(&self) {}
366
367 #[doc(hidden)]
370 #[coverage(off)]
371 #[unstable(feature = "derive_eq_internals", issue = "none")]
372 fn assert_fields_are_eq(&self) {}
373}
374
375#[rustc_builtin_macro]
378#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
379#[allow_internal_unstable(core_intrinsics, derive_eq_internals, structural_match)]
380#[allow_internal_unstable(coverage_attribute)]
381pub macro Eq($item:item) {
382 }
384
385#[doc(hidden)]
390#[allow(missing_debug_implementations)]
391#[unstable(
392 feature = "derive_eq_internals",
393 reason = "deriving hack, should not be public",
394 issue = "none"
395)]
396pub struct AssertParamIsEq<T: Eq + PointeeSized> {
397 _field: crate::marker::PhantomData<T>,
398}
399
400#[derive(#[automatically_derived]#[stable(feature = "rust1", since = "1.0.0")]
impl crate::marker::Copy for Ordering { }Copy, #[automatically_derived]#[stable(feature = "rust1", since = "1.0.0")]
impl crate::fmt::Debug for Ordering {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::write_str(f,
match self {
Ordering::Less => "Less",
Ordering::Equal => "Equal",
Ordering::Greater => "Greater",
})
}
}Debug, #[automatically_derived]#[stable(feature = "rust1", since = "1.0.0")]
impl crate::hash::Hash for Ordering {
#[inline]
fn hash<__H: crate::hash::Hasher>(&self, state: &mut __H) {
crate::hash::Hash::hash(&crate::intrinsics::discriminant_value(self),
state)
}
}Hash)]
414#[derive_const(#[automatically_derived]#[rustc_const_unstable(feature = "derive_const", issue = "143874")]#[doc(hidden)]#[stable(feature
= "rust1", since = "1.0.0")]
const unsafe impl crate::clone::TrivialClone for Ordering { }
#[automatically_derived]#[rustc_const_unstable(feature = "derive_const", issue = "143874")]#[stable(feature
= "rust1", since = "1.0.0")]
const impl crate::clone::Clone for Ordering {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]#[rustc_const_unstable(feature = "derive_const", issue = "143874")]#[stable(feature
= "rust1", since = "1.0.0")]
const impl crate::cmp::Eq for Ordering { }Eq, #[automatically_derived]#[rustc_const_unstable(feature = "derive_const", issue = "143874")]#[stable(feature
= "rust1", since = "1.0.0")]
const impl crate::cmp::PartialOrd for Ordering {
#[inline]
fn partial_cmp(&self, other: &Self)
-> crate::option::Option<crate::cmp::Ordering> {
crate::option::Option::Some(crate::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]#[rustc_const_unstable(feature = "derive_const", issue = "143874")]#[stable(feature
= "rust1", since = "1.0.0")]
const impl crate::cmp::Ord for Ordering {
#[inline]
fn cmp(&self, other: &Self) -> crate::cmp::Ordering {
crate::cmp::Ord::cmp(&crate::intrinsics::discriminant_value(self),
&crate::intrinsics::discriminant_value(other))
}
}Ord, #[automatically_derived]#[stable(feature = "rust1", since = "1.0.0")]
impl crate::marker::StructuralPartialEq for Ordering { }
#[automatically_derived]#[rustc_const_unstable(feature = "derive_const", issue = "143874")]#[stable(feature
= "rust1", since = "1.0.0")]
const impl crate::cmp::PartialEq for Ordering {
#[inline]
fn eq(&self, other: &Self) -> bool {
crate::intrinsics::discriminant_value(self) ==
crate::intrinsics::discriminant_value(other)
}
}PartialEq)]
415#[stable(feature = "rust1", since = "1.0.0")]
416#[lang = "Ordering"]
420#[repr(i8)]
421pub enum Ordering {
422 #[stable(feature = "rust1", since = "1.0.0")]
424 Less = -1,
425 #[stable(feature = "rust1", since = "1.0.0")]
427 Equal = 0,
428 #[stable(feature = "rust1", since = "1.0.0")]
430 Greater = 1,
431}
432
433impl Ordering {
434 #[inline]
435 const fn as_raw(self) -> i8 {
436 crate::intrinsics::discriminant_value(&self)
438 }
439
440 #[inline]
452 #[must_use]
453 #[rustc_const_stable(feature = "ordering_helpers", since = "1.53.0")]
454 #[stable(feature = "ordering_helpers", since = "1.53.0")]
455 pub const fn is_eq(self) -> bool {
456 self.as_raw() == 0
461 }
462
463 #[inline]
475 #[must_use]
476 #[rustc_const_stable(feature = "ordering_helpers", since = "1.53.0")]
477 #[stable(feature = "ordering_helpers", since = "1.53.0")]
478 pub const fn is_ne(self) -> bool {
479 self.as_raw() != 0
480 }
481
482 #[inline]
494 #[must_use]
495 #[rustc_const_stable(feature = "ordering_helpers", since = "1.53.0")]
496 #[stable(feature = "ordering_helpers", since = "1.53.0")]
497 pub const fn is_lt(self) -> bool {
498 self.as_raw() < 0
499 }
500
501 #[inline]
513 #[must_use]
514 #[rustc_const_stable(feature = "ordering_helpers", since = "1.53.0")]
515 #[stable(feature = "ordering_helpers", since = "1.53.0")]
516 pub const fn is_gt(self) -> bool {
517 self.as_raw() > 0
518 }
519
520 #[inline]
532 #[must_use]
533 #[rustc_const_stable(feature = "ordering_helpers", since = "1.53.0")]
534 #[stable(feature = "ordering_helpers", since = "1.53.0")]
535 pub const fn is_le(self) -> bool {
536 self.as_raw() <= 0
537 }
538
539 #[inline]
551 #[must_use]
552 #[rustc_const_stable(feature = "ordering_helpers", since = "1.53.0")]
553 #[stable(feature = "ordering_helpers", since = "1.53.0")]
554 pub const fn is_ge(self) -> bool {
555 self.as_raw() >= 0
556 }
557
558 #[inline]
588 #[must_use]
589 #[rustc_const_stable(feature = "const_ordering", since = "1.48.0")]
590 #[stable(feature = "rust1", since = "1.0.0")]
591 pub const fn reverse(self) -> Ordering {
592 match self {
593 Less => Greater,
594 Equal => Equal,
595 Greater => Less,
596 }
597 }
598
599 #[inline]
627 #[must_use]
628 #[rustc_const_stable(feature = "const_ordering", since = "1.48.0")]
629 #[stable(feature = "ordering_chaining", since = "1.17.0")]
630 pub const fn then(self, other: Ordering) -> Ordering {
631 match self {
632 Equal => other,
633 _ => self,
634 }
635 }
636
637 #[inline]
666 #[must_use]
667 #[stable(feature = "ordering_chaining", since = "1.17.0")]
668 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
669 pub const fn then_with<F>(self, f: F) -> Ordering
670 where
671 F: [const] FnOnce() -> Ordering + [const] Destruct,
672 {
673 match self {
674 Equal => f(),
675 _ => self,
676 }
677 }
678}
679
680#[derive(#[automatically_derived]#[stable(feature = "reverse_cmp_key", since =
"1.19.0")]
impl<T: crate::marker::Copy> crate::marker::Copy for Reverse<T> { }Copy, #[automatically_derived]#[stable(feature = "reverse_cmp_key", since =
"1.19.0")]
impl<T: crate::fmt::Debug> crate::fmt::Debug for Reverse<T> {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field1_finish(f, "Reverse",
&&self.0)
}
}Debug, #[automatically_derived]#[stable(feature = "reverse_cmp_key", since =
"1.19.0")]
impl<T: crate::hash::Hash> crate::hash::Hash for Reverse<T> {
#[inline]
fn hash<__H: crate::hash::Hasher>(&self, state: &mut __H) {
crate::hash::Hash::hash(&self.0, state)
}
}Hash)]
697#[derive_const(#[automatically_derived]#[stable(feature = "reverse_cmp_key", since =
"1.19.0")]
impl<T: crate::cmp::PartialEq> crate::marker::StructuralPartialEq for
Reverse<T> {
}
#[automatically_derived]#[rustc_const_unstable(feature = "derive_const", issue = "143874")]#[stable(feature
= "reverse_cmp_key", since = "1.19.0")]
const impl<T: [const] crate::cmp::PartialEq> crate::cmp::PartialEq for
Reverse<T> {
#[inline]
fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]#[rustc_const_unstable(feature = "derive_const", issue = "143874")]#[stable(feature
= "reverse_cmp_key", since = "1.19.0")]
const impl<T: [const] crate::cmp::Eq> crate::cmp::Eq for Reverse<T> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) { let _: crate::cmp::AssertParamIsEq<T>; }
}Eq, #[automatically_derived]#[rustc_const_unstable(feature = "derive_const", issue = "143874")]#[stable(feature
= "reverse_cmp_key", since = "1.19.0")]
const impl<T: [const] crate::default::Default> crate::default::Default for
Reverse<T> {
#[inline]
fn default() -> Self { Reverse(crate::default::Default::default()) }
}Default)]
698#[stable(feature = "reverse_cmp_key", since = "1.19.0")]
699#[repr(transparent)]
700pub struct Reverse<T>(#[stable(feature = "reverse_cmp_key", since = "1.19.0")] pub T);
701
702#[stable(feature = "reverse_cmp_key", since = "1.19.0")]
703#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
704const impl<T: [const] PartialOrd> PartialOrd for Reverse<T> {
705 #[inline]
706 fn partial_cmp(&self, other: &Reverse<T>) -> Option<Ordering> {
707 other.0.partial_cmp(&self.0)
708 }
709
710 #[inline]
711 fn lt(&self, other: &Self) -> bool {
712 other.0 < self.0
713 }
714 #[inline]
715 fn le(&self, other: &Self) -> bool {
716 other.0 <= self.0
717 }
718 #[inline]
719 fn gt(&self, other: &Self) -> bool {
720 other.0 > self.0
721 }
722 #[inline]
723 fn ge(&self, other: &Self) -> bool {
724 other.0 >= self.0
725 }
726}
727
728#[stable(feature = "reverse_cmp_key", since = "1.19.0")]
729#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
730const impl<T: [const] Ord> Ord for Reverse<T> {
731 #[inline]
732 fn cmp(&self, other: &Reverse<T>) -> Ordering {
733 other.0.cmp(&self.0)
734 }
735}
736
737#[stable(feature = "reverse_cmp_key", since = "1.19.0")]
738impl<T: Clone> Clone for Reverse<T> {
739 #[inline]
740 fn clone(&self) -> Reverse<T> {
741 Reverse(self.0.clone())
742 }
743
744 #[inline]
745 fn clone_from(&mut self, source: &Self) {
746 self.0.clone_from(&source.0)
747 }
748}
749
750#[derive(#[automatically_derived]impl<K: crate::fmt::Debug, V: crate::fmt::Debug>
crate::fmt::Debug for KeyAndValue<K, V> {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field2_finish(f,
"KeyAndValue key value", &self.key, &&self.value)
}
}Debug, #[automatically_derived]impl<K: crate::marker::Copy, V: crate::marker::Copy>
crate::marker::Copy for KeyAndValue<K, V> {
}Copy, #[automatically_derived]impl<K: crate::clone::Clone, V: crate::clone::Clone>
crate::clone::Clone for KeyAndValue<K, V> {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
KeyAndValue {
key: crate::clone::Clone::clone(&self.key),
value: crate::clone::Clone::clone(&self.value),
}
}
}Clone)]
754pub(crate) struct KeyAndValue<K, V> {
755 pub key: K,
756 pub value: V,
757}
758impl<K: PartialEq, V> PartialEq for KeyAndValue<K, V> {
759 #[inline]
760 fn eq(&self, other: &Self) -> bool {
761 self.key == other.key
762 }
763 #[inline]
764 fn ne(&self, other: &Self) -> bool {
765 self.key != other.key
766 }
767}
768impl<K: Eq, V> Eq for KeyAndValue<K, V> {}
769impl<K: PartialOrd, V> PartialOrd for KeyAndValue<K, V> {
770 #[inline]
771 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
772 PartialOrd::partial_cmp(&self.key, &other.key)
773 }
774 #[inline]
775 fn lt(&self, other: &Self) -> bool {
776 self.key < other.key
777 }
778 #[inline]
779 fn le(&self, other: &Self) -> bool {
780 self.key <= other.key
781 }
782 #[inline]
783 fn gt(&self, other: &Self) -> bool {
784 self.key > other.key
785 }
786 #[inline]
787 fn ge(&self, other: &Self) -> bool {
788 self.key >= other.key
789 }
790}
791impl<K: Ord, V> Ord for KeyAndValue<K, V> {
792 #[inline]
793 fn cmp(&self, other: &Self) -> Ordering {
794 Ord::cmp(&self.key, &other.key)
795 }
796}
797
798#[doc(alias = "<")]
1040#[doc(alias = ">")]
1041#[doc(alias = "<=")]
1042#[doc(alias = ">=")]
1043#[stable(feature = "rust1", since = "1.0.0")]
1044#[rustc_diagnostic_item = "Ord"]
1045#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1046pub const trait Ord: [const] Eq + [const] PartialOrd<Self> + PointeeSized {
1047 #[must_use]
1062 #[stable(feature = "rust1", since = "1.0.0")]
1063 #[rustc_diagnostic_item = "ord_cmp_method"]
1064 fn cmp(&self, other: &Self) -> Ordering;
1065
1066 #[stable(feature = "ord_max_min", since = "1.21.0")]
1095 #[inline]
1096 #[must_use]
1097 #[rustc_diagnostic_item = "cmp_ord_max"]
1098 fn max(self, other: Self) -> Self
1099 where
1100 Self: Sized + [const] Destruct,
1101 {
1102 if other < self { self } else { other }
1103 }
1104
1105 #[stable(feature = "ord_max_min", since = "1.21.0")]
1134 #[inline]
1135 #[must_use]
1136 #[rustc_diagnostic_item = "cmp_ord_min"]
1137 fn min(self, other: Self) -> Self
1138 where
1139 Self: Sized + [const] Destruct,
1140 {
1141 if other < self { other } else { self }
1142 }
1143
1144 #[must_use]
1161 #[inline]
1162 #[stable(feature = "clamp", since = "1.50.0")]
1163 fn clamp(self, min: Self, max: Self) -> Self
1164 where
1165 Self: Sized + [const] Destruct,
1166 {
1167 if !(min <= max) { crate::panicking::panic("assertion failed: min <= max") };assert!(min <= max);
1168 if self < min {
1169 min
1170 } else if self > max {
1171 max
1172 } else {
1173 self
1174 }
1175 }
1176
1177 #[must_use]
1196 #[inline]
1197 #[unstable(feature = "clamp_to", issue = "147781")]
1198 fn clamp_to<R>(self, range: R) -> Self
1199 where
1200 Self: Sized + [const] Destruct,
1201 R: [const] ClampBounds<Self>,
1202 {
1203 range.clamp(self)
1204 }
1205}
1206
1207#[rustc_builtin_macro]
1210#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
1211#[allow_internal_unstable(core_intrinsics)]
1212pub macro Ord($item:item) {
1213 }
1215
1216#[lang = "partial_ord"]
1447#[stable(feature = "rust1", since = "1.0.0")]
1448#[doc(alias = ">")]
1449#[doc(alias = "<")]
1450#[doc(alias = "<=")]
1451#[doc(alias = ">=")]
1452#[diagnostic::on_unimplemented(
1453 message = "can't compare `{Self}` with `{Rhs}`",
1454 label = "no implementation for `{Self} < {Rhs}` and `{Self} > {Rhs}`"
1455)]
1456#[rustc_diagnostic_item = "PartialOrd"]
1457#[allow(multiple_supertrait_upcastable)] #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1459pub const trait PartialOrd<Rhs: PointeeSized = Self>:
1460 [const] PartialEq<Rhs> + PointeeSized
1461{
1462 #[must_use]
1486 #[stable(feature = "rust1", since = "1.0.0")]
1487 #[rustc_diagnostic_item = "cmp_partialord_cmp"]
1488 fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>;
1489
1490 #[inline]
1500 #[must_use]
1501 #[stable(feature = "rust1", since = "1.0.0")]
1502 #[rustc_diagnostic_item = "cmp_partialord_lt"]
1503 fn lt(&self, other: &Rhs) -> bool {
1504 self.partial_cmp(other).is_some_and(Ordering::is_lt)
1505 }
1506
1507 #[inline]
1518 #[must_use]
1519 #[stable(feature = "rust1", since = "1.0.0")]
1520 #[rustc_diagnostic_item = "cmp_partialord_le"]
1521 fn le(&self, other: &Rhs) -> bool {
1522 self.partial_cmp(other).is_some_and(Ordering::is_le)
1523 }
1524
1525 #[inline]
1536 #[must_use]
1537 #[stable(feature = "rust1", since = "1.0.0")]
1538 #[rustc_diagnostic_item = "cmp_partialord_gt"]
1539 fn gt(&self, other: &Rhs) -> bool {
1540 self.partial_cmp(other).is_some_and(Ordering::is_gt)
1541 }
1542
1543 #[inline]
1554 #[must_use]
1555 #[stable(feature = "rust1", since = "1.0.0")]
1556 #[rustc_diagnostic_item = "cmp_partialord_ge"]
1557 fn ge(&self, other: &Rhs) -> bool {
1558 self.partial_cmp(other).is_some_and(Ordering::is_ge)
1559 }
1560
1561 #[inline]
1571 #[unstable(feature = "partial_ord_chaining_methods", issue = "none")]
1573 #[doc(hidden)]
1574 fn __chaining_less(&self, other: &Rhs) -> ControlFlow<bool> {
1575 default_chaining_impl(self, other, Ordering::is_lt)
1576 }
1577
1578 #[inline]
1580 #[unstable(feature = "partial_ord_chaining_methods", issue = "none")]
1581 #[doc(hidden)]
1582 fn __chaining_greater(&self, other: &Rhs) -> ControlFlow<bool> {
1583 default_chaining_impl(self, other, Ordering::is_gt)
1584 }
1585}
1586
1587#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1588const fn default_chaining_impl<T, U>(
1589 lhs: &T,
1590 rhs: &U,
1591 p: impl [const] FnOnce(Ordering) -> bool + [const] Destruct,
1592) -> ControlFlow<bool>
1593where
1594 T: [const] PartialOrd<U> + PointeeSized,
1595 U: PointeeSized,
1596{
1597 match <T as PartialOrd<U>>::partial_cmp(lhs, rhs) {
1601 Some(Equal) => ControlFlow::Continue(()),
1602 Some(c) => ControlFlow::Break(p(c)),
1603 None => ControlFlow::Break(false),
1604 }
1605}
1606
1607#[rustc_builtin_macro]
1610#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
1611#[allow_internal_unstable(core_intrinsics)]
1612pub macro PartialOrd($item:item) {
1613 }
1615
1616#[inline]
1649#[must_use]
1650#[stable(feature = "rust1", since = "1.0.0")]
1651#[rustc_diagnostic_item = "cmp_min"]
1652#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1653pub const fn min<T: [const] Ord + [const] Destruct>(v1: T, v2: T) -> T {
1654 v1.min(v2)
1655}
1656
1657#[inline]
1681#[must_use]
1682#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
1683#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1684pub const fn min_by<T: [const] Destruct, F: [const] FnOnce(&T, &T) -> Ordering>(
1685 v1: T,
1686 v2: T,
1687 compare: F,
1688) -> T {
1689 if compare(&v1, &v2).is_le() { v1 } else { v2 }
1690}
1691
1692#[inline]
1711#[must_use]
1712#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
1713#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1714pub const fn min_by_key<T, F, K>(v1: T, v2: T, mut f: F) -> T
1715where
1716 T: [const] Destruct,
1717 F: [const] FnMut(&T) -> K + [const] Destruct,
1718 K: [const] Ord + [const] Destruct,
1719{
1720 if f(&v2) < f(&v1) { v2 } else { v1 }
1721}
1722
1723#[inline]
1756#[must_use]
1757#[stable(feature = "rust1", since = "1.0.0")]
1758#[rustc_diagnostic_item = "cmp_max"]
1759#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1760pub const fn max<T: [const] Ord + [const] Destruct>(v1: T, v2: T) -> T {
1761 v1.max(v2)
1762}
1763
1764#[inline]
1788#[must_use]
1789#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
1790#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1791pub const fn max_by<T: [const] Destruct, F: [const] FnOnce(&T, &T) -> Ordering>(
1792 v1: T,
1793 v2: T,
1794 compare: F,
1795) -> T {
1796 if compare(&v1, &v2).is_gt() { v1 } else { v2 }
1797}
1798
1799#[inline]
1818#[must_use]
1819#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
1820#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1821pub const fn max_by_key<T, F, K>(v1: T, v2: T, mut f: F) -> T
1822where
1823 T: [const] Destruct,
1824 F: [const] FnMut(&T) -> K + [const] Destruct,
1825 K: [const] Ord + [const] Destruct,
1826{
1827 if f(&v2) < f(&v1) { v1 } else { v2 }
1828}
1829
1830#[inline]
1868#[must_use]
1869#[unstable(feature = "cmp_minmax", issue = "115939")]
1870#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1871pub const fn minmax<T>(v1: T, v2: T) -> [T; 2]
1872where
1873 T: [const] Ord,
1874{
1875 if v2 < v1 { [v2, v1] } else { [v1, v2] }
1876}
1877
1878#[inline]
1903#[must_use]
1904#[unstable(feature = "cmp_minmax", issue = "115939")]
1905#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1906pub const fn minmax_by<T, F>(v1: T, v2: T, compare: F) -> [T; 2]
1907where
1908 F: [const] FnOnce(&T, &T) -> Ordering,
1909{
1910 if compare(&v1, &v2).is_le() { [v1, v2] } else { [v2, v1] }
1911}
1912
1913#[inline]
1932#[must_use]
1933#[unstable(feature = "cmp_minmax", issue = "115939")]
1934#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1935pub const fn minmax_by_key<T, F, K>(v1: T, v2: T, mut f: F) -> [T; 2]
1936where
1937 F: [const] FnMut(&T) -> K + [const] Destruct,
1938 K: [const] Ord + [const] Destruct,
1939{
1940 if f(&v2) < f(&v1) { [v2, v1] } else { [v1, v2] }
1941}
1942
1943macro impl_for_tuples_up_to($mac:ident! { $($x:ident, $($y:ident,)*)? }) {
1945 $(impl_for_tuples_up_to! {
1946 $mac! { $($y,)* }
1947 })?
1948 $mac! { $($x, $($y,)*)? }
1949}
1950
1951macro impl_tuples($($mac:ident,)+) {
1953 $(impl_for_tuples_up_to! { $mac! { x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, } })+
1954}
1955
1956#[diagnostic::on_unimplemented(message = "`{Self}` is not a homogeneous tuple")]
1961#[unstable(feature = "cmp_splat_internals", issue = "160728")]
1962#[rustc_const_unstable(feature = "cmp_splat_internals", issue = "160728")]
1963const trait HomogeneousTuple<T>: crate::marker::Tuple {}
1964
1965macro impl_homogeneous_tuple($($x:ident,)*) {
1967 #[unstable(feature = "cmp_splat_internals", issue = "160728")]
1968 #[rustc_const_unstable(feature = "cmp_splat_internals", issue = "160728")]
1969 const impl<T> HomogeneousTuple<T> for ($(${ignore($x)}T,)*) { }
1970}
1971
1972#[unstable(feature = "cmp_splat_internals", issue = "160728")]
#[rustc_const_unstable(feature = "cmp_splat_internals", issue = "160728")]
const impl<T> HomogeneousTuple<T> for (T, T, T, T, T, T, T, T, T, T, T, T) { }impl_tuples! {
1973 impl_homogeneous_tuple,
1974}
1975
1976#[inline]
2019#[must_use]
2020#[unstable(feature = "cmp_splat", issue = "160728")]
2021#[rustc_const_unstable(feature = "cmp_splat", issue = "160728")]
2022#[expect(private_bounds, reason = "`SmallestArgs` is an internal implementation detail")]
2023#[cfg(not(test))] pub const fn smallest<T: [const] Ord + [const] Destruct>(
2025 v1: T,
2026 #[rustc_splat] args: impl [const] SmallestArgs<T>,
2027) -> T {
2028 SmallestArgs::smallest(v1, args)
2029}
2030
2031#[diagnostic::on_unimplemented(message = "`{Self}` is not a valid set of arguments for `smallest`")]
2033#[unstable(feature = "cmp_splat_internals", issue = "160728")]
2034#[rustc_const_unstable(feature = "cmp_splat_internals", issue = "160728")]
2035const trait SmallestArgs<T>: HomogeneousTuple<T> {
2036 fn smallest(v1: T, args: Self) -> T;
2038}
2039
2040macro impl_smallest_args($($x:ident,)*) {
2042 #[unstable(feature = "cmp_splat_internals", issue = "160728")]
2043 #[rustc_const_unstable(feature = "cmp_splat_internals", issue = "160728")]
2044 const impl<T> SmallestArgs<T> for ($(${ignore($x)}T,)*)
2045 where
2046 T: [const] Destruct + [const] Ord,
2047 {
2048 #[inline(always)] fn smallest(v1: T, ($($x,)*): Self) -> T {
2050 v1$(.min($x))*
2051 }
2052 }
2053}
2054
2055#[unstable(feature = "cmp_splat_internals", issue = "160728")]
#[rustc_const_unstable(feature = "cmp_splat_internals", issue = "160728")]
const impl<T> SmallestArgs<T> for (T, T, T, T, T, T, T, T, T, T, T, T) where
T: [const] Destruct + [const] Ord {
#[inline(always)]
fn smallest(v1: T,
(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11): Self) -> T {
v1.min(x0).min(x1).min(x2).min(x3).min(x4).min(x5).min(x6).min(x7).min(x8).min(x9).min(x10).min(x11)
}
}impl_tuples! {
2056 impl_smallest_args,
2057}
2058
2059#[inline]
2102#[must_use]
2103#[unstable(feature = "cmp_splat", issue = "160728")]
2104#[rustc_const_unstable(feature = "cmp_splat", issue = "160728")]
2105#[expect(private_bounds, reason = "`LargestArgs` is an internal implementation detail")]
2106#[cfg(not(test))] pub const fn largest<T: [const] Ord + [const] Destruct>(
2108 v1: T,
2109 #[rustc_splat] args: impl [const] LargestArgs<T>,
2110) -> T {
2111 LargestArgs::largest(v1, args)
2112}
2113
2114#[diagnostic::on_unimplemented(message = "`{Self}` is not a valid set of arguments for `largest`")]
2116#[unstable(feature = "cmp_splat_internals", issue = "160728")]
2117#[rustc_const_unstable(feature = "cmp_splat_internals", issue = "160728")]
2118const trait LargestArgs<T>: HomogeneousTuple<T> {
2119 fn largest(v1: T, args: Self) -> T;
2121}
2122
2123macro impl_largest_args($($x:ident,)*) {
2125 #[unstable(feature = "cmp_splat_internals", issue = "160728")]
2126 #[rustc_const_unstable(feature = "cmp_splat_internals", issue = "160728")]
2127 const impl<T> LargestArgs<T> for ($(${ignore($x)}T,)*)
2128 where
2129 T: [const] Destruct + [const] Ord,
2130 {
2131 #[inline(always)] fn largest(v1: T, ($($x,)*): Self) -> T {
2133 v1$(.max($x))*
2134 }
2135 }
2136}
2137
2138#[unstable(feature = "cmp_splat_internals", issue = "160728")]
#[rustc_const_unstable(feature = "cmp_splat_internals", issue = "160728")]
const impl<T> LargestArgs<T> for (T, T, T, T, T, T, T, T, T, T, T, T) where
T: [const] Destruct + [const] Ord {
#[inline(always)]
fn largest(v1: T,
(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11): Self) -> T {
v1.max(x0).max(x1).max(x2).max(x3).max(x4).max(x5).max(x6).max(x7).max(x8).max(x9).max(x10).max(x11)
}
}impl_tuples! {
2139 impl_largest_args,
2140}
2141
2142mod impls {
2144 use crate::cmp::Ordering::{self, Equal, Greater, Less};
2145 use crate::hint::unreachable_unchecked;
2146 use crate::marker::PointeeSized;
2147 use crate::ops::ControlFlow::{self, Break, Continue};
2148 use crate::panic::const_assert;
2149
2150 macro_rules! impl_partial_eq_for_primitive {
2158 ($($t:ty)*) => ($(
2159 #[stable(feature = "rust1", since = "1.0.0")]
2160 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2161 const impl PartialEq for $t {
2162 #[inline]
2163 fn eq(&self, other: &Self) -> bool { *self == *other }
2164 #[inline]
2166 fn ne(&self, other: &Self) -> bool { *self != *other }
2167 }
2168 )*)
2169 }
2170
2171 #[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for bool {
#[inline]
fn eq(&self, other: &Self) -> bool { *self == *other }
#[inline]
fn ne(&self, other: &Self) -> bool { *self != *other }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for char {
#[inline]
fn eq(&self, other: &Self) -> bool { *self == *other }
#[inline]
fn ne(&self, other: &Self) -> bool { *self != *other }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for usize {
#[inline]
fn eq(&self, other: &Self) -> bool { *self == *other }
#[inline]
fn ne(&self, other: &Self) -> bool { *self != *other }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for u8 {
#[inline]
fn eq(&self, other: &Self) -> bool { *self == *other }
#[inline]
fn ne(&self, other: &Self) -> bool { *self != *other }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for u16 {
#[inline]
fn eq(&self, other: &Self) -> bool { *self == *other }
#[inline]
fn ne(&self, other: &Self) -> bool { *self != *other }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for u32 {
#[inline]
fn eq(&self, other: &Self) -> bool { *self == *other }
#[inline]
fn ne(&self, other: &Self) -> bool { *self != *other }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for u64 {
#[inline]
fn eq(&self, other: &Self) -> bool { *self == *other }
#[inline]
fn ne(&self, other: &Self) -> bool { *self != *other }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for u128 {
#[inline]
fn eq(&self, other: &Self) -> bool { *self == *other }
#[inline]
fn ne(&self, other: &Self) -> bool { *self != *other }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for isize {
#[inline]
fn eq(&self, other: &Self) -> bool { *self == *other }
#[inline]
fn ne(&self, other: &Self) -> bool { *self != *other }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for i8 {
#[inline]
fn eq(&self, other: &Self) -> bool { *self == *other }
#[inline]
fn ne(&self, other: &Self) -> bool { *self != *other }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for i16 {
#[inline]
fn eq(&self, other: &Self) -> bool { *self == *other }
#[inline]
fn ne(&self, other: &Self) -> bool { *self != *other }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for i32 {
#[inline]
fn eq(&self, other: &Self) -> bool { *self == *other }
#[inline]
fn ne(&self, other: &Self) -> bool { *self != *other }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for i64 {
#[inline]
fn eq(&self, other: &Self) -> bool { *self == *other }
#[inline]
fn ne(&self, other: &Self) -> bool { *self != *other }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for i128 {
#[inline]
fn eq(&self, other: &Self) -> bool { *self == *other }
#[inline]
fn ne(&self, other: &Self) -> bool { *self != *other }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for f16 {
#[inline]
fn eq(&self, other: &Self) -> bool { *self == *other }
#[inline]
fn ne(&self, other: &Self) -> bool { *self != *other }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for f32 {
#[inline]
fn eq(&self, other: &Self) -> bool { *self == *other }
#[inline]
fn ne(&self, other: &Self) -> bool { *self != *other }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for f64 {
#[inline]
fn eq(&self, other: &Self) -> bool { *self == *other }
#[inline]
fn ne(&self, other: &Self) -> bool { *self != *other }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialEq for f128 {
#[inline]
fn eq(&self, other: &Self) -> bool { *self == *other }
#[inline]
fn ne(&self, other: &Self) -> bool { *self != *other }
}impl_partial_eq_for_primitive! {
2172 bool char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f64 f128
2173 }
2174
2175 #[stable(feature = "rust1", since = "1.0.0")]
2176 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2177 const impl PartialEq for () {
2178 #[inline]
2179 fn eq(&self, _other: &()) -> bool {
2180 true
2181 }
2182 #[inline]
2183 fn ne(&self, _other: &()) -> bool {
2184 false
2185 }
2186 }
2187
2188 macro_rules! eq_impl {
2189 ($($t:ty)*) => ($(
2190 #[stable(feature = "rust1", since = "1.0.0")]
2191 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2192 const impl Eq for $t {}
2193 )*)
2194 }
2195
2196 #[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Eq for () { }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Eq for bool { }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Eq for char { }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Eq for usize { }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Eq for u8 { }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Eq for u16 { }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Eq for u32 { }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Eq for u64 { }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Eq for u128 { }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Eq for isize { }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Eq for i8 { }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Eq for i16 { }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Eq for i32 { }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Eq for i64 { }
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Eq for i128 { }eq_impl! { () bool char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
2197
2198 #[rustfmt::skip]
2199 macro_rules! partial_ord_methods_primitive_impl {
2200 () => {
2201 #[inline(always)]
2202 fn lt(&self, other: &Self) -> bool { *self < *other }
2203 #[inline(always)]
2204 fn le(&self, other: &Self) -> bool { *self <= *other }
2205 #[inline(always)]
2206 fn gt(&self, other: &Self) -> bool { *self > *other }
2207 #[inline(always)]
2208 fn ge(&self, other: &Self) -> bool { *self >= *other }
2209
2210 #[inline]
2215 fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
2216 let (lhs, rhs) = (*self, *other);
2217 if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
2219 }
2220 #[inline]
2221 fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
2222 let (lhs, rhs) = (*self, *other);
2223 if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
2225 }
2226 };
2227 }
2228
2229 macro_rules! partial_ord_impl {
2230 ($($t:ty)*) => ($(
2231 #[stable(feature = "rust1", since = "1.0.0")]
2232 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2233 const impl PartialOrd for $t {
2234 #[inline]
2235 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
2236 match (*self <= *other, *self >= *other) {
2237 (false, false) => None,
2238 (false, true) => Some(Greater),
2239 (true, false) => Some(Less),
2240 (true, true) => Some(Equal),
2241 }
2242 }
2243
2244 partial_ord_methods_primitive_impl!();
2245 }
2246 )*)
2247 }
2248
2249 #[stable(feature = "rust1", since = "1.0.0")]
2250 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2251 const impl PartialOrd for () {
2252 #[inline]
2253 fn partial_cmp(&self, _: &()) -> Option<Ordering> {
2254 Some(Equal)
2255 }
2256 }
2257
2258 #[stable(feature = "rust1", since = "1.0.0")]
2259 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2260 const impl PartialOrd for bool {
2261 #[inline]
2262 fn partial_cmp(&self, other: &bool) -> Option<Ordering> {
2263 Some(self.cmp(other))
2264 }
2265
2266 #[inline(always)]
fn lt(&self, other: &Self) -> bool { *self < *other }
#[inline(always)]
fn le(&self, other: &Self) -> bool { *self <= *other }
#[inline(always)]
fn gt(&self, other: &Self) -> bool { *self > *other }
#[inline(always)]
fn ge(&self, other: &Self) -> bool { *self >= *other }
#[inline]
fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
}
#[inline]
fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
}partial_ord_methods_primitive_impl!();
2267 }
2268
2269 #[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for f16 {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
match (*self <= *other, *self >= *other) {
(false, false) => None,
(false, true) => Some(Greater),
(true, false) => Some(Less),
(true, true) => Some(Equal),
}
}
#[inline(always)]
fn lt(&self, other: &Self) -> bool { *self < *other }
#[inline(always)]
fn le(&self, other: &Self) -> bool { *self <= *other }
#[inline(always)]
fn gt(&self, other: &Self) -> bool { *self > *other }
#[inline(always)]
fn ge(&self, other: &Self) -> bool { *self >= *other }
#[inline]
fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
}
#[inline]
fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for f32 {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
match (*self <= *other, *self >= *other) {
(false, false) => None,
(false, true) => Some(Greater),
(true, false) => Some(Less),
(true, true) => Some(Equal),
}
}
#[inline(always)]
fn lt(&self, other: &Self) -> bool { *self < *other }
#[inline(always)]
fn le(&self, other: &Self) -> bool { *self <= *other }
#[inline(always)]
fn gt(&self, other: &Self) -> bool { *self > *other }
#[inline(always)]
fn ge(&self, other: &Self) -> bool { *self >= *other }
#[inline]
fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
}
#[inline]
fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for f64 {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
match (*self <= *other, *self >= *other) {
(false, false) => None,
(false, true) => Some(Greater),
(true, false) => Some(Less),
(true, true) => Some(Equal),
}
}
#[inline(always)]
fn lt(&self, other: &Self) -> bool { *self < *other }
#[inline(always)]
fn le(&self, other: &Self) -> bool { *self <= *other }
#[inline(always)]
fn gt(&self, other: &Self) -> bool { *self > *other }
#[inline(always)]
fn ge(&self, other: &Self) -> bool { *self >= *other }
#[inline]
fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
}
#[inline]
fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for f128 {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
match (*self <= *other, *self >= *other) {
(false, false) => None,
(false, true) => Some(Greater),
(true, false) => Some(Less),
(true, true) => Some(Equal),
}
}
#[inline(always)]
fn lt(&self, other: &Self) -> bool { *self < *other }
#[inline(always)]
fn le(&self, other: &Self) -> bool { *self <= *other }
#[inline(always)]
fn gt(&self, other: &Self) -> bool { *self > *other }
#[inline(always)]
fn ge(&self, other: &Self) -> bool { *self >= *other }
#[inline]
fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
}
#[inline]
fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
}
}partial_ord_impl! { f16 f32 f64 f128 }
2270
2271 macro_rules! min_max_impl {
2272 (char) => {
2273 #[inline]
2274 fn min(self, other: Self) -> Self {
2275 let c = u32::min(self as u32, other as u32);
2276 unsafe { char::from_u32_unchecked(c) }
2278 }
2279
2280 #[inline]
2281 fn max(self, other: Self) -> Self {
2282 let c = u32::max(self as u32, other as u32);
2283 unsafe { char::from_u32_unchecked(c) }
2285 }
2286 };
2287 ($t:ident) => {
2288 #[inline]
2289 fn min(self, other: Self) -> Self {
2290 crate::intrinsics::integer_min(self, other)
2291 }
2292
2293 #[inline]
2294 fn max(self, other: Self) -> Self {
2295 crate::intrinsics::integer_max(self, other)
2296 }
2297 };
2298 }
2299
2300 macro_rules! ord_impl {
2301 ($($t:ident)*) => ($(
2302 #[stable(feature = "rust1", since = "1.0.0")]
2303 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2304 const impl PartialOrd for $t {
2305 #[inline]
2306 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
2307 Some(crate::intrinsics::three_way_compare(*self, *other))
2308 }
2309
2310 partial_ord_methods_primitive_impl!();
2311 }
2312
2313 #[stable(feature = "rust1", since = "1.0.0")]
2314 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2315 const impl Ord for $t {
2316 #[inline]
2317 fn cmp(&self, other: &Self) -> Ordering {
2318 crate::intrinsics::three_way_compare(*self, *other)
2319 }
2320
2321 #[inline]
2322 #[track_caller]
2323 fn clamp(self, min: Self, max: Self) -> Self
2324 {
2325 const_assert!(
2326 min <= max,
2327 "min > max",
2328 "min > max. min = {min:?}, max = {max:?}",
2329 min: $t,
2330 max: $t,
2331 );
2332 if self < min {
2333 min
2334 } else if self > max {
2335 max
2336 } else {
2337 self
2338 }
2339 }
2340
2341 min_max_impl!($t);
2342 }
2343 )*)
2344 }
2345
2346 #[stable(feature = "rust1", since = "1.0.0")]
2347 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2348 const impl Ord for () {
2349 #[inline]
2350 fn cmp(&self, _other: &()) -> Ordering {
2351 Equal
2352 }
2353 }
2354
2355 #[stable(feature = "rust1", since = "1.0.0")]
2356 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2357 const impl Ord for bool {
2358 #[inline]
2359 fn cmp(&self, other: &bool) -> Ordering {
2360 match (*self as i8) - (*other as i8) {
2364 -1 => Less,
2365 0 => Equal,
2366 1 => Greater,
2367 _ => unsafe { unreachable_unchecked() },
2369 }
2370 }
2371
2372 #[inline]
2373 fn min(self, other: bool) -> bool {
2374 self & other
2375 }
2376
2377 #[inline]
2378 fn max(self, other: bool) -> bool {
2379 self | other
2380 }
2381
2382 #[inline]
2383 fn clamp(self, min: bool, max: bool) -> bool {
2384 if !(min <= max) { crate::panicking::panic("assertion failed: min <= max") };assert!(min <= max);
2385 self.max(min).min(max)
2386 }
2387 }
2388
2389 #[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for char {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(crate::intrinsics::three_way_compare(*self, *other))
}
#[inline(always)]
fn lt(&self, other: &Self) -> bool { *self < *other }
#[inline(always)]
fn le(&self, other: &Self) -> bool { *self <= *other }
#[inline(always)]
fn gt(&self, other: &Self) -> bool { *self > *other }
#[inline(always)]
fn ge(&self, other: &Self) -> bool { *self >= *other }
#[inline]
fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
}
#[inline]
fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Ord for char {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
crate::intrinsics::three_way_compare(*self, *other)
}
#[inline]
#[track_caller]
fn clamp(self, min: Self, max: Self) -> Self {
{
if !(min <= max) {
{
#[rustc_allow_const_fn_unstable(const_eval_select)]
#[inline(always)]
#[track_caller]
const fn do_panic(min: char, max: char) -> ! {
{
#[inline]
#[track_caller]
fn runtime(min: char, max: char) -> ! {
{
{
crate::panicking::panic_fmt(format_args!("min > max. min = {0:?}, max = {1:?}",
min, max));
}
}
}
#[inline]
#[track_caller]
const fn compiletime(min: char, max: char) -> ! {
let _ = min;
let _ = max;
{
{ crate::panicking::panic_fmt(format_args!("min > max")); }
}
}
const_eval_select((min, max), compiletime, runtime)
}
}
do_panic(min, max)
}
}
};
if self < min { min } else if self > max { max } else { self }
}
#[inline]
fn min(self, other: Self) -> Self {
let c = u32::min(self as u32, other as u32);
unsafe { char::from_u32_unchecked(c) }
}
#[inline]
fn max(self, other: Self) -> Self {
let c = u32::max(self as u32, other as u32);
unsafe { char::from_u32_unchecked(c) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for usize {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(crate::intrinsics::three_way_compare(*self, *other))
}
#[inline(always)]
fn lt(&self, other: &Self) -> bool { *self < *other }
#[inline(always)]
fn le(&self, other: &Self) -> bool { *self <= *other }
#[inline(always)]
fn gt(&self, other: &Self) -> bool { *self > *other }
#[inline(always)]
fn ge(&self, other: &Self) -> bool { *self >= *other }
#[inline]
fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
}
#[inline]
fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Ord for usize {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
crate::intrinsics::three_way_compare(*self, *other)
}
#[inline]
#[track_caller]
fn clamp(self, min: Self, max: Self) -> Self {
{
if !(min <= max) {
{
#[rustc_allow_const_fn_unstable(const_eval_select)]
#[inline(always)]
#[track_caller]
const fn do_panic(min: usize, max: usize) -> ! {
{
#[inline]
#[track_caller]
fn runtime(min: usize, max: usize) -> ! {
{
{
crate::panicking::panic_fmt(format_args!("min > max. min = {0:?}, max = {1:?}",
min, max));
}
}
}
#[inline]
#[track_caller]
const fn compiletime(min: usize, max: usize) -> ! {
let _ = min;
let _ = max;
{
{ crate::panicking::panic_fmt(format_args!("min > max")); }
}
}
const_eval_select((min, max), compiletime, runtime)
}
}
do_panic(min, max)
}
}
};
if self < min { min } else if self > max { max } else { self }
}
#[inline]
fn min(self, other: Self) -> Self {
crate::intrinsics::integer_min(self, other)
}
#[inline]
fn max(self, other: Self) -> Self {
crate::intrinsics::integer_max(self, other)
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for u8 {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(crate::intrinsics::three_way_compare(*self, *other))
}
#[inline(always)]
fn lt(&self, other: &Self) -> bool { *self < *other }
#[inline(always)]
fn le(&self, other: &Self) -> bool { *self <= *other }
#[inline(always)]
fn gt(&self, other: &Self) -> bool { *self > *other }
#[inline(always)]
fn ge(&self, other: &Self) -> bool { *self >= *other }
#[inline]
fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
}
#[inline]
fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Ord for u8 {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
crate::intrinsics::three_way_compare(*self, *other)
}
#[inline]
#[track_caller]
fn clamp(self, min: Self, max: Self) -> Self {
{
if !(min <= max) {
{
#[rustc_allow_const_fn_unstable(const_eval_select)]
#[inline(always)]
#[track_caller]
const fn do_panic(min: u8, max: u8) -> ! {
{
#[inline]
#[track_caller]
fn runtime(min: u8, max: u8) -> ! {
{
{
crate::panicking::panic_fmt(format_args!("min > max. min = {0:?}, max = {1:?}",
min, max));
}
}
}
#[inline]
#[track_caller]
const fn compiletime(min: u8, max: u8) -> ! {
let _ = min;
let _ = max;
{
{ crate::panicking::panic_fmt(format_args!("min > max")); }
}
}
const_eval_select((min, max), compiletime, runtime)
}
}
do_panic(min, max)
}
}
};
if self < min { min } else if self > max { max } else { self }
}
#[inline]
fn min(self, other: Self) -> Self {
crate::intrinsics::integer_min(self, other)
}
#[inline]
fn max(self, other: Self) -> Self {
crate::intrinsics::integer_max(self, other)
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for u16 {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(crate::intrinsics::three_way_compare(*self, *other))
}
#[inline(always)]
fn lt(&self, other: &Self) -> bool { *self < *other }
#[inline(always)]
fn le(&self, other: &Self) -> bool { *self <= *other }
#[inline(always)]
fn gt(&self, other: &Self) -> bool { *self > *other }
#[inline(always)]
fn ge(&self, other: &Self) -> bool { *self >= *other }
#[inline]
fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
}
#[inline]
fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Ord for u16 {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
crate::intrinsics::three_way_compare(*self, *other)
}
#[inline]
#[track_caller]
fn clamp(self, min: Self, max: Self) -> Self {
{
if !(min <= max) {
{
#[rustc_allow_const_fn_unstable(const_eval_select)]
#[inline(always)]
#[track_caller]
const fn do_panic(min: u16, max: u16) -> ! {
{
#[inline]
#[track_caller]
fn runtime(min: u16, max: u16) -> ! {
{
{
crate::panicking::panic_fmt(format_args!("min > max. min = {0:?}, max = {1:?}",
min, max));
}
}
}
#[inline]
#[track_caller]
const fn compiletime(min: u16, max: u16) -> ! {
let _ = min;
let _ = max;
{
{ crate::panicking::panic_fmt(format_args!("min > max")); }
}
}
const_eval_select((min, max), compiletime, runtime)
}
}
do_panic(min, max)
}
}
};
if self < min { min } else if self > max { max } else { self }
}
#[inline]
fn min(self, other: Self) -> Self {
crate::intrinsics::integer_min(self, other)
}
#[inline]
fn max(self, other: Self) -> Self {
crate::intrinsics::integer_max(self, other)
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for u32 {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(crate::intrinsics::three_way_compare(*self, *other))
}
#[inline(always)]
fn lt(&self, other: &Self) -> bool { *self < *other }
#[inline(always)]
fn le(&self, other: &Self) -> bool { *self <= *other }
#[inline(always)]
fn gt(&self, other: &Self) -> bool { *self > *other }
#[inline(always)]
fn ge(&self, other: &Self) -> bool { *self >= *other }
#[inline]
fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
}
#[inline]
fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Ord for u32 {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
crate::intrinsics::three_way_compare(*self, *other)
}
#[inline]
#[track_caller]
fn clamp(self, min: Self, max: Self) -> Self {
{
if !(min <= max) {
{
#[rustc_allow_const_fn_unstable(const_eval_select)]
#[inline(always)]
#[track_caller]
const fn do_panic(min: u32, max: u32) -> ! {
{
#[inline]
#[track_caller]
fn runtime(min: u32, max: u32) -> ! {
{
{
crate::panicking::panic_fmt(format_args!("min > max. min = {0:?}, max = {1:?}",
min, max));
}
}
}
#[inline]
#[track_caller]
const fn compiletime(min: u32, max: u32) -> ! {
let _ = min;
let _ = max;
{
{ crate::panicking::panic_fmt(format_args!("min > max")); }
}
}
const_eval_select((min, max), compiletime, runtime)
}
}
do_panic(min, max)
}
}
};
if self < min { min } else if self > max { max } else { self }
}
#[inline]
fn min(self, other: Self) -> Self {
crate::intrinsics::integer_min(self, other)
}
#[inline]
fn max(self, other: Self) -> Self {
crate::intrinsics::integer_max(self, other)
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for u64 {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(crate::intrinsics::three_way_compare(*self, *other))
}
#[inline(always)]
fn lt(&self, other: &Self) -> bool { *self < *other }
#[inline(always)]
fn le(&self, other: &Self) -> bool { *self <= *other }
#[inline(always)]
fn gt(&self, other: &Self) -> bool { *self > *other }
#[inline(always)]
fn ge(&self, other: &Self) -> bool { *self >= *other }
#[inline]
fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
}
#[inline]
fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Ord for u64 {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
crate::intrinsics::three_way_compare(*self, *other)
}
#[inline]
#[track_caller]
fn clamp(self, min: Self, max: Self) -> Self {
{
if !(min <= max) {
{
#[rustc_allow_const_fn_unstable(const_eval_select)]
#[inline(always)]
#[track_caller]
const fn do_panic(min: u64, max: u64) -> ! {
{
#[inline]
#[track_caller]
fn runtime(min: u64, max: u64) -> ! {
{
{
crate::panicking::panic_fmt(format_args!("min > max. min = {0:?}, max = {1:?}",
min, max));
}
}
}
#[inline]
#[track_caller]
const fn compiletime(min: u64, max: u64) -> ! {
let _ = min;
let _ = max;
{
{ crate::panicking::panic_fmt(format_args!("min > max")); }
}
}
const_eval_select((min, max), compiletime, runtime)
}
}
do_panic(min, max)
}
}
};
if self < min { min } else if self > max { max } else { self }
}
#[inline]
fn min(self, other: Self) -> Self {
crate::intrinsics::integer_min(self, other)
}
#[inline]
fn max(self, other: Self) -> Self {
crate::intrinsics::integer_max(self, other)
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for u128 {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(crate::intrinsics::three_way_compare(*self, *other))
}
#[inline(always)]
fn lt(&self, other: &Self) -> bool { *self < *other }
#[inline(always)]
fn le(&self, other: &Self) -> bool { *self <= *other }
#[inline(always)]
fn gt(&self, other: &Self) -> bool { *self > *other }
#[inline(always)]
fn ge(&self, other: &Self) -> bool { *self >= *other }
#[inline]
fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
}
#[inline]
fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Ord for u128 {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
crate::intrinsics::three_way_compare(*self, *other)
}
#[inline]
#[track_caller]
fn clamp(self, min: Self, max: Self) -> Self {
{
if !(min <= max) {
{
#[rustc_allow_const_fn_unstable(const_eval_select)]
#[inline(always)]
#[track_caller]
const fn do_panic(min: u128, max: u128) -> ! {
{
#[inline]
#[track_caller]
fn runtime(min: u128, max: u128) -> ! {
{
{
crate::panicking::panic_fmt(format_args!("min > max. min = {0:?}, max = {1:?}",
min, max));
}
}
}
#[inline]
#[track_caller]
const fn compiletime(min: u128, max: u128) -> ! {
let _ = min;
let _ = max;
{
{ crate::panicking::panic_fmt(format_args!("min > max")); }
}
}
const_eval_select((min, max), compiletime, runtime)
}
}
do_panic(min, max)
}
}
};
if self < min { min } else if self > max { max } else { self }
}
#[inline]
fn min(self, other: Self) -> Self {
crate::intrinsics::integer_min(self, other)
}
#[inline]
fn max(self, other: Self) -> Self {
crate::intrinsics::integer_max(self, other)
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for isize {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(crate::intrinsics::three_way_compare(*self, *other))
}
#[inline(always)]
fn lt(&self, other: &Self) -> bool { *self < *other }
#[inline(always)]
fn le(&self, other: &Self) -> bool { *self <= *other }
#[inline(always)]
fn gt(&self, other: &Self) -> bool { *self > *other }
#[inline(always)]
fn ge(&self, other: &Self) -> bool { *self >= *other }
#[inline]
fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
}
#[inline]
fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Ord for isize {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
crate::intrinsics::three_way_compare(*self, *other)
}
#[inline]
#[track_caller]
fn clamp(self, min: Self, max: Self) -> Self {
{
if !(min <= max) {
{
#[rustc_allow_const_fn_unstable(const_eval_select)]
#[inline(always)]
#[track_caller]
const fn do_panic(min: isize, max: isize) -> ! {
{
#[inline]
#[track_caller]
fn runtime(min: isize, max: isize) -> ! {
{
{
crate::panicking::panic_fmt(format_args!("min > max. min = {0:?}, max = {1:?}",
min, max));
}
}
}
#[inline]
#[track_caller]
const fn compiletime(min: isize, max: isize) -> ! {
let _ = min;
let _ = max;
{
{ crate::panicking::panic_fmt(format_args!("min > max")); }
}
}
const_eval_select((min, max), compiletime, runtime)
}
}
do_panic(min, max)
}
}
};
if self < min { min } else if self > max { max } else { self }
}
#[inline]
fn min(self, other: Self) -> Self {
crate::intrinsics::integer_min(self, other)
}
#[inline]
fn max(self, other: Self) -> Self {
crate::intrinsics::integer_max(self, other)
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for i8 {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(crate::intrinsics::three_way_compare(*self, *other))
}
#[inline(always)]
fn lt(&self, other: &Self) -> bool { *self < *other }
#[inline(always)]
fn le(&self, other: &Self) -> bool { *self <= *other }
#[inline(always)]
fn gt(&self, other: &Self) -> bool { *self > *other }
#[inline(always)]
fn ge(&self, other: &Self) -> bool { *self >= *other }
#[inline]
fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
}
#[inline]
fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Ord for i8 {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
crate::intrinsics::three_way_compare(*self, *other)
}
#[inline]
#[track_caller]
fn clamp(self, min: Self, max: Self) -> Self {
{
if !(min <= max) {
{
#[rustc_allow_const_fn_unstable(const_eval_select)]
#[inline(always)]
#[track_caller]
const fn do_panic(min: i8, max: i8) -> ! {
{
#[inline]
#[track_caller]
fn runtime(min: i8, max: i8) -> ! {
{
{
crate::panicking::panic_fmt(format_args!("min > max. min = {0:?}, max = {1:?}",
min, max));
}
}
}
#[inline]
#[track_caller]
const fn compiletime(min: i8, max: i8) -> ! {
let _ = min;
let _ = max;
{
{ crate::panicking::panic_fmt(format_args!("min > max")); }
}
}
const_eval_select((min, max), compiletime, runtime)
}
}
do_panic(min, max)
}
}
};
if self < min { min } else if self > max { max } else { self }
}
#[inline]
fn min(self, other: Self) -> Self {
crate::intrinsics::integer_min(self, other)
}
#[inline]
fn max(self, other: Self) -> Self {
crate::intrinsics::integer_max(self, other)
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for i16 {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(crate::intrinsics::three_way_compare(*self, *other))
}
#[inline(always)]
fn lt(&self, other: &Self) -> bool { *self < *other }
#[inline(always)]
fn le(&self, other: &Self) -> bool { *self <= *other }
#[inline(always)]
fn gt(&self, other: &Self) -> bool { *self > *other }
#[inline(always)]
fn ge(&self, other: &Self) -> bool { *self >= *other }
#[inline]
fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
}
#[inline]
fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Ord for i16 {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
crate::intrinsics::three_way_compare(*self, *other)
}
#[inline]
#[track_caller]
fn clamp(self, min: Self, max: Self) -> Self {
{
if !(min <= max) {
{
#[rustc_allow_const_fn_unstable(const_eval_select)]
#[inline(always)]
#[track_caller]
const fn do_panic(min: i16, max: i16) -> ! {
{
#[inline]
#[track_caller]
fn runtime(min: i16, max: i16) -> ! {
{
{
crate::panicking::panic_fmt(format_args!("min > max. min = {0:?}, max = {1:?}",
min, max));
}
}
}
#[inline]
#[track_caller]
const fn compiletime(min: i16, max: i16) -> ! {
let _ = min;
let _ = max;
{
{ crate::panicking::panic_fmt(format_args!("min > max")); }
}
}
const_eval_select((min, max), compiletime, runtime)
}
}
do_panic(min, max)
}
}
};
if self < min { min } else if self > max { max } else { self }
}
#[inline]
fn min(self, other: Self) -> Self {
crate::intrinsics::integer_min(self, other)
}
#[inline]
fn max(self, other: Self) -> Self {
crate::intrinsics::integer_max(self, other)
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for i32 {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(crate::intrinsics::three_way_compare(*self, *other))
}
#[inline(always)]
fn lt(&self, other: &Self) -> bool { *self < *other }
#[inline(always)]
fn le(&self, other: &Self) -> bool { *self <= *other }
#[inline(always)]
fn gt(&self, other: &Self) -> bool { *self > *other }
#[inline(always)]
fn ge(&self, other: &Self) -> bool { *self >= *other }
#[inline]
fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
}
#[inline]
fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Ord for i32 {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
crate::intrinsics::three_way_compare(*self, *other)
}
#[inline]
#[track_caller]
fn clamp(self, min: Self, max: Self) -> Self {
{
if !(min <= max) {
{
#[rustc_allow_const_fn_unstable(const_eval_select)]
#[inline(always)]
#[track_caller]
const fn do_panic(min: i32, max: i32) -> ! {
{
#[inline]
#[track_caller]
fn runtime(min: i32, max: i32) -> ! {
{
{
crate::panicking::panic_fmt(format_args!("min > max. min = {0:?}, max = {1:?}",
min, max));
}
}
}
#[inline]
#[track_caller]
const fn compiletime(min: i32, max: i32) -> ! {
let _ = min;
let _ = max;
{
{ crate::panicking::panic_fmt(format_args!("min > max")); }
}
}
const_eval_select((min, max), compiletime, runtime)
}
}
do_panic(min, max)
}
}
};
if self < min { min } else if self > max { max } else { self }
}
#[inline]
fn min(self, other: Self) -> Self {
crate::intrinsics::integer_min(self, other)
}
#[inline]
fn max(self, other: Self) -> Self {
crate::intrinsics::integer_max(self, other)
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for i64 {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(crate::intrinsics::three_way_compare(*self, *other))
}
#[inline(always)]
fn lt(&self, other: &Self) -> bool { *self < *other }
#[inline(always)]
fn le(&self, other: &Self) -> bool { *self <= *other }
#[inline(always)]
fn gt(&self, other: &Self) -> bool { *self > *other }
#[inline(always)]
fn ge(&self, other: &Self) -> bool { *self >= *other }
#[inline]
fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
}
#[inline]
fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Ord for i64 {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
crate::intrinsics::three_way_compare(*self, *other)
}
#[inline]
#[track_caller]
fn clamp(self, min: Self, max: Self) -> Self {
{
if !(min <= max) {
{
#[rustc_allow_const_fn_unstable(const_eval_select)]
#[inline(always)]
#[track_caller]
const fn do_panic(min: i64, max: i64) -> ! {
{
#[inline]
#[track_caller]
fn runtime(min: i64, max: i64) -> ! {
{
{
crate::panicking::panic_fmt(format_args!("min > max. min = {0:?}, max = {1:?}",
min, max));
}
}
}
#[inline]
#[track_caller]
const fn compiletime(min: i64, max: i64) -> ! {
let _ = min;
let _ = max;
{
{ crate::panicking::panic_fmt(format_args!("min > max")); }
}
}
const_eval_select((min, max), compiletime, runtime)
}
}
do_panic(min, max)
}
}
};
if self < min { min } else if self > max { max } else { self }
}
#[inline]
fn min(self, other: Self) -> Self {
crate::intrinsics::integer_min(self, other)
}
#[inline]
fn max(self, other: Self) -> Self {
crate::intrinsics::integer_max(self, other)
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl PartialOrd for i128 {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(crate::intrinsics::three_way_compare(*self, *other))
}
#[inline(always)]
fn lt(&self, other: &Self) -> bool { *self < *other }
#[inline(always)]
fn le(&self, other: &Self) -> bool { *self <= *other }
#[inline(always)]
fn gt(&self, other: &Self) -> bool { *self > *other }
#[inline(always)]
fn ge(&self, other: &Self) -> bool { *self >= *other }
#[inline]
fn __chaining_less(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs < rhs) }
}
#[inline]
fn __chaining_greater(&self, other: &Self) -> ControlFlow<bool> {
let (lhs, rhs) = (*self, *other);
if lhs == rhs { Continue(()) } else { Break(lhs > rhs) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const impl Ord for i128 {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
crate::intrinsics::three_way_compare(*self, *other)
}
#[inline]
#[track_caller]
fn clamp(self, min: Self, max: Self) -> Self {
{
if !(min <= max) {
{
#[rustc_allow_const_fn_unstable(const_eval_select)]
#[inline(always)]
#[track_caller]
const fn do_panic(min: i128, max: i128) -> ! {
{
#[inline]
#[track_caller]
fn runtime(min: i128, max: i128) -> ! {
{
{
crate::panicking::panic_fmt(format_args!("min > max. min = {0:?}, max = {1:?}",
min, max));
}
}
}
#[inline]
#[track_caller]
const fn compiletime(min: i128, max: i128) -> ! {
let _ = min;
let _ = max;
{
{ crate::panicking::panic_fmt(format_args!("min > max")); }
}
}
const_eval_select((min, max), compiletime, runtime)
}
}
do_panic(min, max)
}
}
};
if self < min { min } else if self > max { max } else { self }
}
#[inline]
fn min(self, other: Self) -> Self {
crate::intrinsics::integer_min(self, other)
}
#[inline]
fn max(self, other: Self) -> Self {
crate::intrinsics::integer_max(self, other)
}
}ord_impl! { char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
2390
2391 #[stable(feature = "never_type", since = "1.100.0")]
2392 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2393 const impl PartialEq for ! {
2394 #[inline]
2395 fn eq(&self, _: &!) -> bool {
2396 *self
2397 }
2398 }
2399
2400 #[stable(feature = "never_type", since = "1.100.0")]
2401 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2402 const impl Eq for ! {}
2403
2404 #[stable(feature = "never_type", since = "1.100.0")]
2405 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2406 const impl PartialOrd for ! {
2407 #[inline]
2408 fn partial_cmp(&self, _: &!) -> Option<Ordering> {
2409 *self
2410 }
2411 }
2412
2413 #[stable(feature = "never_type", since = "1.100.0")]
2414 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2415 const impl Ord for ! {
2416 #[inline]
2417 fn cmp(&self, _: &!) -> Ordering {
2418 *self
2419 }
2420 }
2421
2422 #[stable(feature = "rust1", since = "1.0.0")]
2425 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2426 const impl<A: PointeeSized, B: PointeeSized> PartialEq<&B> for &A
2427 where
2428 A: [const] PartialEq<B>,
2429 {
2430 #[inline]
2431 fn eq(&self, other: &&B) -> bool {
2432 PartialEq::eq(*self, *other)
2433 }
2434 #[inline]
2435 fn ne(&self, other: &&B) -> bool {
2436 PartialEq::ne(*self, *other)
2437 }
2438 }
2439 #[stable(feature = "rust1", since = "1.0.0")]
2440 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2441 const impl<A: PointeeSized, B: PointeeSized> PartialOrd<&B> for &A
2442 where
2443 A: [const] PartialOrd<B>,
2444 {
2445 #[inline]
2446 fn partial_cmp(&self, other: &&B) -> Option<Ordering> {
2447 PartialOrd::partial_cmp(*self, *other)
2448 }
2449 #[inline]
2450 fn lt(&self, other: &&B) -> bool {
2451 PartialOrd::lt(*self, *other)
2452 }
2453 #[inline]
2454 fn le(&self, other: &&B) -> bool {
2455 PartialOrd::le(*self, *other)
2456 }
2457 #[inline]
2458 fn gt(&self, other: &&B) -> bool {
2459 PartialOrd::gt(*self, *other)
2460 }
2461 #[inline]
2462 fn ge(&self, other: &&B) -> bool {
2463 PartialOrd::ge(*self, *other)
2464 }
2465 #[inline]
2466 fn __chaining_less(&self, other: &&B) -> ControlFlow<bool> {
2467 PartialOrd::__chaining_less(*self, *other)
2468 }
2469 #[inline]
2470 fn __chaining_greater(&self, other: &&B) -> ControlFlow<bool> {
2471 PartialOrd::__chaining_greater(*self, *other)
2472 }
2473 }
2474 #[stable(feature = "rust1", since = "1.0.0")]
2475 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2476 const impl<A: PointeeSized> Ord for &A
2477 where
2478 A: [const] Ord,
2479 {
2480 #[inline]
2481 fn cmp(&self, other: &Self) -> Ordering {
2482 Ord::cmp(*self, *other)
2483 }
2484 }
2485 #[stable(feature = "rust1", since = "1.0.0")]
2486 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2487 const impl<A: PointeeSized> Eq for &A where A: [const] Eq {}
2488
2489 #[stable(feature = "rust1", since = "1.0.0")]
2492 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2493 const impl<A: PointeeSized, B: PointeeSized> PartialEq<&mut B> for &mut A
2494 where
2495 A: [const] PartialEq<B>,
2496 {
2497 #[inline]
2498 fn eq(&self, other: &&mut B) -> bool {
2499 PartialEq::eq(*self, *other)
2500 }
2501 #[inline]
2502 fn ne(&self, other: &&mut B) -> bool {
2503 PartialEq::ne(*self, *other)
2504 }
2505 }
2506 #[stable(feature = "rust1", since = "1.0.0")]
2507 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2508 const impl<A: PointeeSized, B: PointeeSized> PartialOrd<&mut B> for &mut A
2509 where
2510 A: [const] PartialOrd<B>,
2511 {
2512 #[inline]
2513 fn partial_cmp(&self, other: &&mut B) -> Option<Ordering> {
2514 PartialOrd::partial_cmp(*self, *other)
2515 }
2516 #[inline]
2517 fn lt(&self, other: &&mut B) -> bool {
2518 PartialOrd::lt(*self, *other)
2519 }
2520 #[inline]
2521 fn le(&self, other: &&mut B) -> bool {
2522 PartialOrd::le(*self, *other)
2523 }
2524 #[inline]
2525 fn gt(&self, other: &&mut B) -> bool {
2526 PartialOrd::gt(*self, *other)
2527 }
2528 #[inline]
2529 fn ge(&self, other: &&mut B) -> bool {
2530 PartialOrd::ge(*self, *other)
2531 }
2532 #[inline]
2533 fn __chaining_less(&self, other: &&mut B) -> ControlFlow<bool> {
2534 PartialOrd::__chaining_less(*self, *other)
2535 }
2536 #[inline]
2537 fn __chaining_greater(&self, other: &&mut B) -> ControlFlow<bool> {
2538 PartialOrd::__chaining_greater(*self, *other)
2539 }
2540 }
2541 #[stable(feature = "rust1", since = "1.0.0")]
2542 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2543 const impl<A: PointeeSized> Ord for &mut A
2544 where
2545 A: [const] Ord,
2546 {
2547 #[inline]
2548 fn cmp(&self, other: &Self) -> Ordering {
2549 Ord::cmp(*self, *other)
2550 }
2551 }
2552 #[stable(feature = "rust1", since = "1.0.0")]
2553 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2554 const impl<A: PointeeSized> Eq for &mut A where A: [const] Eq {}
2555
2556 #[stable(feature = "rust1", since = "1.0.0")]
2557 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2558 const impl<A: PointeeSized, B: PointeeSized> PartialEq<&mut B> for &A
2559 where
2560 A: [const] PartialEq<B>,
2561 {
2562 #[inline]
2563 fn eq(&self, other: &&mut B) -> bool {
2564 PartialEq::eq(*self, *other)
2565 }
2566 #[inline]
2567 fn ne(&self, other: &&mut B) -> bool {
2568 PartialEq::ne(*self, *other)
2569 }
2570 }
2571
2572 #[stable(feature = "rust1", since = "1.0.0")]
2573 #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2574 const impl<A: PointeeSized, B: PointeeSized> PartialEq<&B> for &mut A
2575 where
2576 A: [const] PartialEq<B>,
2577 {
2578 #[inline]
2579 fn eq(&self, other: &&B) -> bool {
2580 PartialEq::eq(*self, *other)
2581 }
2582 #[inline]
2583 fn ne(&self, other: &&B) -> bool {
2584 PartialEq::ne(*self, *other)
2585 }
2586 }
2587}