Skip to content

Commit 9a798e4

Browse files
authored
Rollup merge of rust-lang#110622 - WaffleLapkin:hashtag#, r=compiler-errors
Stable hash tag (discriminant) of `GenericArg` This is a continuation of my quest of removing `transmute` if generic args and types (rust-lang#110496, rust-lang#110599). r? `@compiler-errors`
2 parents 684bdf8 + 4375af5 commit 9a798e4

File tree

2 files changed

+1
-29
lines changed

2 files changed

+1
-29
lines changed

compiler/rustc_middle/src/ty/impls_ty.rs

-28
Original file line numberDiff line numberDiff line change
@@ -73,34 +73,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::subst::GenericArg<'t
7373
}
7474
}
7575

76-
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::subst::GenericArgKind<'tcx> {
77-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
78-
match self {
79-
// WARNING: We dedup cache the `HashStable` results for `List`
80-
// while ignoring types and freely transmute
81-
// between `List<Ty<'tcx>>` and `List<GenericArg<'tcx>>`.
82-
// See `fn mk_type_list` for more details.
83-
//
84-
// We therefore hash types without adding a hash for their discriminant.
85-
//
86-
// In order to make it very unlikely for the sequence of bytes being hashed for
87-
// a `GenericArgKind::Type` to be the same as the sequence of bytes being
88-
// hashed for one of the other variants, we hash some very high number instead
89-
// of their actual discriminant since `TyKind` should never start with anything
90-
// that high.
91-
ty::subst::GenericArgKind::Type(ty) => ty.hash_stable(hcx, hasher),
92-
ty::subst::GenericArgKind::Const(ct) => {
93-
0xF3u8.hash_stable(hcx, hasher);
94-
ct.hash_stable(hcx, hasher);
95-
}
96-
ty::subst::GenericArgKind::Lifetime(lt) => {
97-
0xF5u8.hash_stable(hcx, hasher);
98-
lt.hash_stable(hcx, hasher);
99-
}
100-
}
101-
}
102-
}
103-
10476
// AllocIds get resolved to whatever they point to (to be stable)
10577
impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
10678
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {

compiler/rustc_middle/src/ty/subst.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const TYPE_TAG: usize = 0b00;
4747
const REGION_TAG: usize = 0b01;
4848
const CONST_TAG: usize = 0b10;
4949

50-
#[derive(Debug, TyEncodable, TyDecodable, PartialEq, Eq, PartialOrd, Ord)]
50+
#[derive(Debug, TyEncodable, TyDecodable, PartialEq, Eq, PartialOrd, Ord, HashStable)]
5151
pub enum GenericArgKind<'tcx> {
5252
Lifetime(ty::Region<'tcx>),
5353
Type(Ty<'tcx>),

0 commit comments

Comments
 (0)