-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Querify whether a type implements StructuralEq
and PartialStructuralEq
#72177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -778,6 +778,27 @@ impl<'tcx> ty::TyS<'tcx> { | |
} | ||
} | ||
|
||
/// Returns `true` if this type implements both `PartialStructuralEq` and `StructuralEq`. | ||
/// | ||
/// These marker traits are implemented along with `PartialEq` and `Eq` when implementations | ||
/// for those traits are derived. They indicate that two values of this type are equal if all | ||
/// of their fields are equal. A quirk of the marker traits is that their implementation is | ||
/// never conditional on generic parameter bounds. For that reason, this helper function does | ||
/// not take a `ParamEnv`. | ||
/// | ||
/// This function is "shallow" because it may return `true` for a type whose fields are not | ||
/// `StructuralEq`. You will need to use a type visitor if you want to know whether a call to | ||
/// `PartialEq::eq` will proceed structurally for a given type. | ||
#[inline] | ||
pub fn is_structural_eq_shallow(&'tcx self, tcx: TyCtxt<'tcx>) -> bool { | ||
// Fast path for some builtin types | ||
if self.is_primitive() || self.is_str() { | ||
|
||
return true; | ||
} | ||
|
||
tcx.is_structural_eq_raw(self) | ||
} | ||
|
||
pub fn same_type(a: Ty<'tcx>, b: Ty<'tcx>) -> bool { | ||
match (&a.kind, &b.kind) { | ||
(&Adt(did_a, substs_a), &Adt(did_b, substs_b)) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.