diff options
| author | bors <bors@rust-lang.org> | 2024-01-26 00:17:00 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-01-26 00:17:00 +0000 |
| commit | dd2559e08e1530806740931037d6bb83ef956161 (patch) | |
| tree | 1c6e468a3101e3eb9b47e15e68d8ac3c62c5f139 /compiler/rustc_middle/src/ty | |
| parent | 0c1fb2a1e65a57073dc62dd502319a00cf753371 (diff) | |
| parent | 0df7810734d396d1a3082eee674d542c81c269d2 (diff) | |
| download | rust-dd2559e08e1530806740931037d6bb83ef956161.tar.gz rust-dd2559e08e1530806740931037d6bb83ef956161.zip | |
Auto merge of #116167 - RalfJung:structural-eq, r=lcnr
remove StructuralEq trait The documentation given for the trait is outdated: *all* function pointers implement `PartialEq` and `Eq` these days. So the `StructuralEq` trait doesn't really seem to have any reason to exist any more. One side-effect of this PR is that we allow matching on some consts that do not implement `Eq`. However, we already allowed matching on floats and consts containing floats, so this is not new, it is just allowed in more cases now. IMO it makes no sense at all to allow float matching but also sometimes require an `Eq` instance. If we want to require `Eq` we should adjust https://github.com/rust-lang/rust/pull/115893 to check for `Eq`, and rule out float matching for good. Fixes https://github.com/rust-lang/rust/issues/115881
Diffstat (limited to 'compiler/rustc_middle/src/ty')
| -rw-r--r-- | compiler/rustc_middle/src/ty/util.rs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 1f81678d6a5..8cc8abbe718 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -1249,19 +1249,18 @@ impl<'tcx> Ty<'tcx> { /// Primitive types (`u32`, `str`) have structural equality by definition. For composite data /// types, equality for the type as a whole is structural when it is the same as equality /// between all components (fields, array elements, etc.) of that type. For ADTs, structural - /// equality is indicated by an implementation of `PartialStructuralEq` and `StructuralEq` for - /// that type. + /// equality is indicated by an implementation of `StructuralPartialEq` for that type. /// /// This function is "shallow" because it may return `true` for a composite type whose fields - /// are not `StructuralEq`. For example, `[T; 4]` has structural equality regardless of `T` + /// are not `StructuralPartialEq`. For example, `[T; 4]` has structural equality regardless of `T` /// because equality for arrays is determined by the equality of each array element. If you /// want to know whether a given call to `PartialEq::eq` will proceed structurally all the way /// down, you will need to use a type visitor. #[inline] pub fn is_structural_eq_shallow(self, tcx: TyCtxt<'tcx>) -> bool { match self.kind() { - // Look for an impl of both `PartialStructuralEq` and `StructuralEq`. - ty::Adt(..) => tcx.has_structural_eq_impls(self), + // Look for an impl of `StructuralPartialEq`. + ty::Adt(..) => tcx.has_structural_eq_impl(self), // Primitive types that satisfy `Eq`. ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Str | ty::Never => true, |
