Skip to content

Commit 8e897e3

Browse files
authored
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 2b8799b + a0577ee commit 8e897e3

File tree

2 files changed

+2
-17
lines changed

2 files changed

+2
-17
lines changed

src/librustc_mir/interpret/operand.rs

+1-16
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};
@@ -221,7 +220,7 @@ impl Operand {
221220
}
222221
}
223222

224-
#[derive(Copy, Clone, Debug)]
223+
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
225224
pub struct OpTy<'tcx> {
226225
crate op: Operand, // ideally we'd make this private, but const_prop needs this
227226
pub layout: TyLayout<'tcx>,
@@ -255,20 +254,6 @@ impl<'tcx> From<ValTy<'tcx>> for OpTy<'tcx> {
255254
}
256255
}
257256

258-
// Validation needs to hash OpTy, but we cannot hash Layout -- so we just hash the type
259-
impl<'tcx> Hash for OpTy<'tcx> {
260-
fn hash<H: Hasher>(&self, state: &mut H) {
261-
self.op.hash(state);
262-
self.layout.ty.hash(state);
263-
}
264-
}
265-
impl<'tcx> PartialEq for OpTy<'tcx> {
266-
fn eq(&self, other: &Self) -> bool {
267-
self.op == other.op && self.layout.ty == other.layout.ty
268-
}
269-
}
270-
impl<'tcx> Eq for OpTy<'tcx> {}
271-
272257
// Use the existing layout if given (but sanity check in debug mode),
273258
// or compute the layout.
274259
#[inline(always)]

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)