about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-10-12 22:04:12 +0800
committerGitHub <noreply@github.com>2018-10-12 22:04:12 +0800
commit4f1a618e5db3b17442ab076d954d3e1f0767a091 (patch)
tree9a810fcc665555f9a6d3829102879b6f0b2d2b99
parentfcb3ce4f539b5b20e8efed45eeac6c7b02e095ab (diff)
parent99db3e9bcecbd4874e71283a6285462b53e47184 (diff)
downloadrust-4f1a618e5db3b17442ab076d954d3e1f0767a091.tar.gz
rust-4f1a618e5db3b17442ab076d954d3e1f0767a091.zip
Rollup merge of #54936 - RalfJung:layout-hash, r=oli-obk
impl Eq+Hash for TyLayout

As proposed by @eddyb at https://github.com/rust-lang/rust/pull/53671#pullrequestreview-159761136.

I have an upcoming PR that would also significantly benefit from this.
-rw-r--r--src/librustc_mir/interpret/operand.rs23
-rw-r--r--src/librustc_target/abi/mod.rs2
2 files changed, 2 insertions, 23 deletions
diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs
index 039a92cee2c..c72a5894b6a 100644
--- a/src/librustc_mir/interpret/operand.rs
+++ b/src/librustc_mir/interpret/operand.rs
@@ -11,7 +11,6 @@
 //! Functions concerning immediate values and operands, and reading from operands.
 //! All high-level functions to read from memory work on operands as sources.
 
-use std::hash::{Hash, Hasher};
 use std::convert::TryInto;
 
 use rustc::{mir, ty};
@@ -290,7 +289,7 @@ impl<Tag> Operand<Tag> {
     }
 }
 
-#[derive(Copy, Clone, Debug)]
+#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
 pub struct OpTy<'tcx, Tag=()> {
     crate op: Operand<Tag>, // ideally we'd make this private, but const_prop needs this
     pub layout: TyLayout<'tcx>,
@@ -324,26 +323,6 @@ impl<'tcx, Tag> From<ValTy<'tcx, Tag>> for OpTy<'tcx, Tag> {
     }
 }
 
-// Validation needs to hash OpTy, but we cannot hash Layout -- so we just hash the type
-impl<'tcx, Tag> Hash for OpTy<'tcx, Tag>
-    where Tag: Hash
-{
-    fn hash<H: Hasher>(&self, state: &mut H) {
-        self.op.hash(state);
-        self.layout.ty.hash(state);
-    }
-}
-impl<'tcx, Tag> PartialEq for OpTy<'tcx, Tag>
-    where Tag: PartialEq
-{
-    fn eq(&self, other: &Self) -> bool {
-        self.op == other.op && self.layout.ty == other.layout.ty
-    }
-}
-impl<'tcx, Tag> Eq for OpTy<'tcx, Tag>
-    where Tag: Eq
-{}
-
 impl<'tcx, Tag> OpTy<'tcx, Tag>
 {
     #[inline]
diff --git a/src/librustc_target/abi/mod.rs b/src/librustc_target/abi/mod.rs
index 96eb6916322..6b28fd09174 100644
--- a/src/librustc_target/abi/mod.rs
+++ b/src/librustc_target/abi/mod.rs
@@ -874,7 +874,7 @@ impl LayoutDetails {
 /// to those obtained from `layout_of(ty)`, as we need to produce
 /// layouts for which Rust types do not exist, such as enum variants
 /// or synthetic fields of enums (i.e. discriminants) and fat pointers.
-#[derive(Copy, Clone, Debug)]
+#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
 pub struct TyLayout<'a, Ty> {
     pub ty: Ty,
     pub details: &'a LayoutDetails