Skip to content

Commit f432741

Browse files
Rollup merge of rust-lang#54936 - RalfJung:layout-hash, r=oli-obk
impl Eq+Hash for TyLayout As proposed by @eddyb at rust-lang#53671 (review). I have an upcoming PR that would also significantly benefit from this.
2 parents 9943961 + 99db3e9 commit f432741

File tree

2 files changed

+2
-23
lines changed

2 files changed

+2
-23
lines changed

src/librustc_mir/interpret/operand.rs

+1-22
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//! Functions concerning immediate values and operands, and reading from operands.
1212
//! All high-level functions to read from memory work on operands as sources.
1313
14-
use std::hash::{Hash, Hasher};
1514
use std::convert::TryInto;
1615

1716
use rustc::{mir, ty};
@@ -290,7 +289,7 @@ impl<Tag> Operand<Tag> {
290289
}
291290
}
292291

293-
#[derive(Copy, Clone, Debug)]
292+
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
294293
pub struct OpTy<'tcx, Tag=()> {
295294
crate op: Operand<Tag>, // ideally we'd make this private, but const_prop needs this
296295
pub layout: TyLayout<'tcx>,
@@ -324,26 +323,6 @@ impl<'tcx, Tag> From<ValTy<'tcx, Tag>> for OpTy<'tcx, Tag> {
324323
}
325324
}
326325

327-
// Validation needs to hash OpTy, but we cannot hash Layout -- so we just hash the type
328-
impl<'tcx, Tag> Hash for OpTy<'tcx, Tag>
329-
where Tag: Hash
330-
{
331-
fn hash<H: Hasher>(&self, state: &mut H) {
332-
self.op.hash(state);
333-
self.layout.ty.hash(state);
334-
}
335-
}
336-
impl<'tcx, Tag> PartialEq for OpTy<'tcx, Tag>
337-
where Tag: PartialEq
338-
{
339-
fn eq(&self, other: &Self) -> bool {
340-
self.op == other.op && self.layout.ty == other.layout.ty
341-
}
342-
}
343-
impl<'tcx, Tag> Eq for OpTy<'tcx, Tag>
344-
where Tag: Eq
345-
{}
346-
347326
impl<'tcx, Tag> OpTy<'tcx, Tag>
348327
{
349328
#[inline]

src/librustc_target/abi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ impl LayoutDetails {
874874
/// to those obtained from `layout_of(ty)`, as we need to produce
875875
/// layouts for which Rust types do not exist, such as enum variants
876876
/// or synthetic fields of enums (i.e. discriminants) and fat pointers.
877-
#[derive(Copy, Clone, Debug)]
877+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
878878
pub struct TyLayout<'a, Ty> {
879879
pub ty: Ty,
880880
pub details: &'a LayoutDetails

0 commit comments

Comments
 (0)