mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 04:08:40 +00:00
update and clarify StructuralPartialEq docs
This commit is contained in:
parent
7e4077d06f
commit
41857a3d42
@ -190,24 +190,19 @@ pub trait Unsize<T: ?Sized> {
|
|||||||
|
|
||||||
/// Required trait for constants used in pattern matches.
|
/// Required trait for constants used in pattern matches.
|
||||||
///
|
///
|
||||||
/// Any type that derives `PartialEq` automatically implements this trait,
|
/// Constants are only allowed as patterns if (a) their type implements
|
||||||
/// *regardless* of whether its type-parameters implement `PartialEq`.
|
/// `PartialEq`, and (b) interpreting the value of the constant as a pattern
|
||||||
|
/// is equialent to calling `PartialEq`. This ensures that constants used as
|
||||||
|
/// patterns cannot expose implementation details in an unexpected way or
|
||||||
|
/// cause semver hazards.
|
||||||
///
|
///
|
||||||
/// If a `const` item contains some type that does not implement this trait,
|
/// This trait ensures point (b).
|
||||||
/// then that type either (1.) does not implement `PartialEq` (which means the
|
/// Any type that derives `PartialEq` automatically implements this trait.
|
||||||
/// constant will not provide that comparison method, which code generation
|
|
||||||
/// assumes is available), or (2.) it implements *its own* version of
|
|
||||||
/// `PartialEq` (which we assume does not conform to a structural-equality
|
|
||||||
/// comparison).
|
|
||||||
///
|
///
|
||||||
/// In either of the two scenarios above, we reject usage of such a constant in
|
/// Implementing this trait (which is unstable) is a way for type authors to explicitly allow
|
||||||
/// a pattern match.
|
/// comparing const values of this type; that operation will recursively compare all fields
|
||||||
///
|
/// (including private fields), even if that behavior differs from `PartialEq`. This can make it
|
||||||
/// See also the [structural match RFC][RFC1445], and [issue 63438] which
|
/// semver-breaking to add further private fields to a type.
|
||||||
/// motivated migrating from an attribute-based design to this trait.
|
|
||||||
///
|
|
||||||
/// [RFC1445]: https://github.com/rust-lang/rfcs/blob/master/text/1445-restrict-constants-in-patterns.md
|
|
||||||
/// [issue 63438]: https://github.com/rust-lang/rust/issues/63438
|
|
||||||
#[unstable(feature = "structural_match", issue = "31434")]
|
#[unstable(feature = "structural_match", issue = "31434")]
|
||||||
#[diagnostic::on_unimplemented(message = "the type `{Self}` does not `#[derive(PartialEq)]`")]
|
#[diagnostic::on_unimplemented(message = "the type `{Self}` does not `#[derive(PartialEq)]`")]
|
||||||
#[lang = "structural_peq"]
|
#[lang = "structural_peq"]
|
||||||
|
Loading…
Reference in New Issue
Block a user