Skip to content

Commit 80f56cd

Browse files
committed
review
1 parent c909b6d commit 80f56cd

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

compiler/rustc_middle/src/ty/impls_ty.rs

+8
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,20 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::subst::GenericArgKin
7070
// See `fn intern_type_list` for more details.
7171
//
7272
// We therefore hash types without adding a hash for their discriminant.
73+
//
74+
// In order to make it very unlikely for the sequence of bytes being hashed for
75+
// a `GenericArgKind::Type` to be the same as the sequence of bytes being
76+
// hashed for one of the other variants, we hash a `0xFF` byte before hashing
77+
// their discriminant (since the discriminant of `TyKind` is unlikely to ever start
78+
// with 0xFF).
7379
ty::subst::GenericArgKind::Type(ty) => ty.hash_stable(hcx, hasher),
7480
ty::subst::GenericArgKind::Const(ct) => {
81+
0xFFu8.hash_stable(hcx, hasher);
7582
mem::discriminant(self).hash_stable(hcx, hasher);
7683
ct.hash_stable(hcx, hasher);
7784
}
7885
ty::subst::GenericArgKind::Lifetime(lt) => {
86+
0xFFu8.hash_stable(hcx, hasher);
7987
mem::discriminant(self).hash_stable(hcx, hasher);
8088
lt.hash_stable(hcx, hasher);
8189
}

compiler/rustc_middle/src/ty/subst.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ pub enum GenericArgKind<'tcx> {
5151
/// This function goes from `&'a [Ty<'tcx>]` to `&'a [GenericArg<'tcx>]`
5252
///
5353
/// This is sound as, for types, `GenericArg` is just
54-
/// `NonZeroUsize::new_unchecked(ty as *const _ as usize)`.
54+
/// `NonZeroUsize::new_unchecked(ty as *const _ as usize)` as
55+
/// long as we use `0` for the `TYPE_TAG`.
5556
pub fn ty_slice_as_generic_args<'a, 'tcx>(ts: &'a [Ty<'tcx>]) -> &'a [GenericArg<'tcx>] {
5657
assert_eq!(TYPE_TAG, 0);
5758
// SAFETY: the whole slice is valid and immutable.

0 commit comments

Comments
 (0)