Skip to content

Commit 9b9ea86

Browse files
committed
Made ReprOptions::field_shuffle_seed invariant over layout seed order
1 parent f058493 commit 9b9ea86

File tree

1 file changed

+27
-7
lines changed
  • compiler/rustc_middle/src/ty

1 file changed

+27
-7
lines changed

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,11 @@ pub struct MainDefinition {
224224

225225
impl MainDefinition {
226226
pub fn opt_fn_def_id(self) -> Option<DefId> {
227-
if let Res::Def(DefKind::Fn, def_id) = self.res { Some(def_id) } else { None }
227+
if let Res::Def(DefKind::Fn, def_id) = self.res {
228+
Some(def_id)
229+
} else {
230+
None
231+
}
228232
}
229233
}
230234

@@ -953,11 +957,19 @@ impl<'tcx> Term<'tcx> {
953957
}
954958

955959
pub fn ty(&self) -> Option<Ty<'tcx>> {
956-
if let TermKind::Ty(ty) = self.unpack() { Some(ty) } else { None }
960+
if let TermKind::Ty(ty) = self.unpack() {
961+
Some(ty)
962+
} else {
963+
None
964+
}
957965
}
958966

959967
pub fn ct(&self) -> Option<Const<'tcx>> {
960-
if let TermKind::Const(c) = self.unpack() { Some(c) } else { None }
968+
if let TermKind::Const(c) = self.unpack() {
969+
Some(c)
970+
} else {
971+
None
972+
}
961973
}
962974

963975
pub fn into_arg(self) -> GenericArg<'tcx> {
@@ -990,8 +1002,8 @@ impl<'tcx> TermKind<'tcx> {
9901002
}
9911003
TermKind::Const(ct) => {
9921004
// Ensure we can use the tag bits.
993-
assert_eq!(mem::align_of_val(&*ct.0.0) & TAG_MASK, 0);
994-
(CONST_TAG, ct.0.0 as *const ty::ConstS<'tcx> as usize)
1005+
assert_eq!(mem::align_of_val(&*ct.0 .0) & TAG_MASK, 0);
1006+
(CONST_TAG, ct.0 .0 as *const ty::ConstS<'tcx> as usize)
9951007
}
9961008
};
9971009

@@ -1459,7 +1471,11 @@ impl WithOptConstParam<LocalDefId> {
14591471
}
14601472

14611473
pub fn def_id_for_type_of(self) -> DefId {
1462-
if let Some(did) = self.const_param_did { did } else { self.did.to_def_id() }
1474+
if let Some(did) = self.const_param_did {
1475+
did
1476+
} else {
1477+
self.did.to_def_id()
1478+
}
14631479
}
14641480
}
14651481

@@ -2030,7 +2046,11 @@ impl<'tcx> TyCtxt<'tcx> {
20302046
// path hash with the user defined seed, this will allowing determinism while
20312047
// still allowing users to further randomize layout generation for e.g. fuzzing
20322048
if let Some(user_seed) = self.sess.opts.unstable_opts.layout_seed {
2033-
field_shuffle_seed ^= user_seed;
2049+
// Order-sensitive hash combination
2050+
field_shuffle_seed ^= user_seed
2051+
.wrapping_add(0x9e3779b9)
2052+
.wrapping_add(field_shuffle_seed << 6)
2053+
.wrapping_add(field_shuffle_seed >> 2);
20342054
}
20352055

20362056
for attr in self.get_attrs(did, sym::repr) {

0 commit comments

Comments
 (0)