]> git.lizzy.rs Git - rust.git/commitdiff
impl Eq+Hash for TyLayout
authorRalf Jung <post@ralfj.de>
Tue, 9 Oct 2018 16:48:44 +0000 (18:48 +0200)
committerRalf Jung <post@ralfj.de>
Thu, 11 Oct 2018 10:51:53 +0000 (12:51 +0200)
src/librustc_mir/interpret/operand.rs
src/librustc_target/abi/mod.rs

index 039a92cee2ca2fcfba65f06617ece23d6de56141..c72a5894b6ac7f54f0b83bf1f9ed7bcf70e78479 100644 (file)
@@ -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 @@ pub fn to_immediate(self) -> Value<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 @@ fn from(val: ValTy<'tcx, Tag>) -> Self {
     }
 }
 
-// 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]
index 96eb69163220e7b33c57287bd9ac35596ab6b589..6b28fd091748f14114b21d7224e82620b5a65d55 100644 (file)
@@ -874,7 +874,7 @@ pub fn scalar<C: HasDataLayout>(cx: C, scalar: Scalar) -> Self {
 /// 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