@@ -190,24 +190,19 @@ pub trait Unsize<T: ?Sized> {
190
190
191
191
/// Required trait for constants used in pattern matches.
192
192
///
193
- /// Any type that derives `PartialEq` automatically implements this trait,
194
- /// *regardless* of whether its type-parameters implement `PartialEq`.
195
- ///
196
- /// If a `const` item contains some type that does not implement this trait,
197
- /// then that type either (1.) does not implement `PartialEq` (which means the
198
- /// constant will not provide that comparison method, which code generation
199
- /// assumes is available), or (2.) it implements *its own* version of
200
- /// `PartialEq` (which we assume does not conform to a structural-equality
201
- /// comparison).
202
- ///
203
- /// In either of the two scenarios above, we reject usage of such a constant in
204
- /// a pattern match.
205
- ///
206
- /// See also the [structural match RFC][RFC1445], and [issue 63438] which
207
- /// motivated migrating from an attribute-based design to this trait.
208
- ///
209
- /// [RFC1445]: https://github.com/rust-lang/rfcs/blob/master/text/1445-restrict-constants-in-patterns.md
210
- /// [issue 63438]: https://github.com/rust-lang/rust/issues/63438
193
+ /// Constants are only allowed as patterns if (a) their type implements
194
+ /// `PartialEq`, and (b) interpreting the value of the constant as a pattern
195
+ /// is equialent to calling `PartialEq`. This ensures that constants used as
196
+ /// patterns cannot expose implementation details in an unexpected way or
197
+ /// cause semver hazards.
198
+ ///
199
+ /// This trait ensures point (b).
200
+ /// Any type that derives `PartialEq` automatically implements this trait.
201
+ ///
202
+ /// Implementing this trait (which is unstable) is a way for type authors to explicitly allow
203
+ /// comparing const values of this type; that operation will recursively compare all fields
204
+ /// (including private fields), even if that behavior differs from `PartialEq`. This can make it
205
+ /// semver-breaking to add further private fields to a type.
211
206
#[ unstable( feature = "structural_match" , issue = "31434" ) ]
212
207
#[ diagnostic:: on_unimplemented( message = "the type `{Self}` does not `#[derive(PartialEq)]`" ) ]
213
208
#[ lang = "structural_peq" ]
0 commit comments