diff options
| author | lcnr <rust@lcnr.de> | 2022-02-18 12:31:12 +0100 |
|---|---|---|
| committer | lcnr <rust@lcnr.de> | 2022-02-21 07:09:11 +0100 |
| commit | 80f56cdc2a749f1262518d2aa7597cf908b9e059 (patch) | |
| tree | beb695dc1bc401a95343da061dd87253e98aa238 | |
| parent | c909b6dc2254b1ceca049f878e67a8ab86118d37 (diff) | |
| download | rust-80f56cdc2a749f1262518d2aa7597cf908b9e059.tar.gz rust-80f56cdc2a749f1262518d2aa7597cf908b9e059.zip | |
review
| -rw-r--r-- | compiler/rustc_middle/src/ty/impls_ty.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/subst.rs | 3 |
2 files changed, 10 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/ty/impls_ty.rs b/compiler/rustc_middle/src/ty/impls_ty.rs index 4e3661dda17..54a345daec8 100644 --- a/compiler/rustc_middle/src/ty/impls_ty.rs +++ b/compiler/rustc_middle/src/ty/impls_ty.rs @@ -70,12 +70,20 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::subst::GenericArgKin // See `fn intern_type_list` for more details. // // We therefore hash types without adding a hash for their discriminant. + // + // In order to make it very unlikely for the sequence of bytes being hashed for + // a `GenericArgKind::Type` to be the same as the sequence of bytes being + // hashed for one of the other variants, we hash a `0xFF` byte before hashing + // their discriminant (since the discriminant of `TyKind` is unlikely to ever start + // with 0xFF). ty::subst::GenericArgKind::Type(ty) => ty.hash_stable(hcx, hasher), ty::subst::GenericArgKind::Const(ct) => { + 0xFFu8.hash_stable(hcx, hasher); mem::discriminant(self).hash_stable(hcx, hasher); ct.hash_stable(hcx, hasher); } ty::subst::GenericArgKind::Lifetime(lt) => { + 0xFFu8.hash_stable(hcx, hasher); mem::discriminant(self).hash_stable(hcx, hasher); lt.hash_stable(hcx, hasher); } diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index 59a560f7342..364ba07a441 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -51,7 +51,8 @@ pub enum GenericArgKind<'tcx> { /// This function goes from `&'a [Ty<'tcx>]` to `&'a [GenericArg<'tcx>]` /// /// This is sound as, for types, `GenericArg` is just -/// `NonZeroUsize::new_unchecked(ty as *const _ as usize)`. +/// `NonZeroUsize::new_unchecked(ty as *const _ as usize)` as +/// long as we use `0` for the `TYPE_TAG`. pub fn ty_slice_as_generic_args<'a, 'tcx>(ts: &'a [Ty<'tcx>]) -> &'a [GenericArg<'tcx>] { assert_eq!(TYPE_TAG, 0); // SAFETY: the whole slice is valid and immutable. |
