@@ -249,14 +249,23 @@ use crate::ops::ControlFlow;
249249#[ rustc_diagnostic_item = "PartialEq" ]
250250#[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
251251pub const trait PartialEq <Rhs : PointeeSized = Self >: PointeeSized {
252- /// Tests for `self` and `other` values to be equal, and is used by `==`.
252+ /// Equality operator `==`.
253+ ///
254+ /// Implementation of the "is equal to" operator `==`:
255+ /// tests whether its arguments are equal.
253256 #[ must_use]
254257 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
255258 #[ rustc_diagnostic_item = "cmp_partialeq_eq" ]
256259 fn eq( & self , other : & Rhs ) -> bool;
257260
258- /// Tests for `!=`. The default implementation is almost always sufficient,
259- /// and should not be overridden without very good reason.
261+ /// Inequality operator `!=`.
262+ ///
263+ /// Implementation of the "is not equal to" or "is different from" operator `!=`:
264+ /// tests whether its arguments are different.
265+ ///
266+ /// # Default implementation
267+ /// The default implementation of the inequality operator simply calls
268+ /// the implementation of the equality operator and negates the result.
260269 #[ inline]
261270 #[ must_use]
262271 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1857,19 +1866,31 @@ mod impls {
18571866 use crate :: ops:: ControlFlow :: { self, Break , Continue } ;
18581867 use crate :: panic:: const_assert;
18591868
1860- macro_rules! partial_eq_impl {
1869+ /// Implements `PartialEq` for primitive types.
1870+ ///
1871+ /// Primitive types have a compiler-defined primitive implementation of `==` and `!=`.
1872+ /// This implements the `PartialEq` trait is terms of those primitive implementations.
1873+ ///
1874+ /// NOTE: Calling this on a non-primitive type (such as `()`)
1875+ /// leads to infinitely recursive implementations.
1876+ macro_rules! impl_partial_eq_for_primitive {
18611877 ( $( $t: ty) * ) => ( $(
18621878 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
18631879 #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
18641880 impl const PartialEq for $t {
18651881 #[ inline]
18661882 fn eq( & self , other: & Self ) -> bool { * self == * other }
1883+ // Override the default to use the primitive implementation for `!=`.
18671884 #[ inline]
18681885 fn ne( & self , other: & Self ) -> bool { * self != * other }
18691886 }
18701887 ) * )
18711888 }
18721889
1890+ impl_partial_eq_for_primitive ! {
1891+ bool char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f64 f128
1892+ }
1893+
18731894 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
18741895 #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
18751896 impl const PartialEq for ( ) {
@@ -1883,10 +1904,6 @@ mod impls {
18831904 }
18841905 }
18851906
1886- partial_eq_impl ! {
1887- bool char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f64 f128
1888- }
1889-
18901907 macro_rules! eq_impl {
18911908 ( $( $t: ty) * ) => ( $(
18921909 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
0 commit comments