Skip to content

Commit 03a8cc7

Browse files
committed
Auto merge of #93505 - lcnr:substsref-vs-ty-list, r=michaelwoerister
safely `transmute<&List<Ty<'tcx>>, &List<GenericArg<'tcx>>>` This PR has 3 relevant steps which are is split in distinct commits. The first commit now interns `List<Ty<'tcx>>` and `List<GenericArg<'tcx>>` together, potentially reusing memory while allowing free conversions between these two using `List<Ty<'tcx>>::as_substs()` and `SubstsRef<'tcx>::try_as_type_list()`. Using this, we then use `&'tcx List<Ty<'tcx>>` instead of a `SubstsRef<'tcx>` for tuple fields, simplifying a bunch of code. Finally, as tuple fields and other generic arguments now use a different `TypeFoldable<'tcx>` impl, we optimize the impl for `List<Ty<'tcx>>` improving perf by slightly less than 1% in tuple heavy benchmarks.
2 parents 1103d2e + 80f56cd commit 03a8cc7

File tree

64 files changed

+289
-210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+289
-210
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2298,7 +2298,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22982298
// Closure arguments are wrapped in a tuple, so we need to get the first
22992299
// from that.
23002300
if let ty::Tuple(elems) = argument_ty.kind() {
2301-
let argument_ty = elems.first()?.expect_ty();
2301+
let &argument_ty = elems.first()?;
23022302
if let ty::Ref(_, _, _) = argument_ty.kind() {
23032303
return Some(AnnotatedBorrowFnSignature::Closure {
23042304
argument_ty,

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
480480
let search_stack: &mut Vec<(Ty<'tcx>, &hir::Ty<'_>)> = &mut vec![(ty, hir_ty)];
481481

482482
while let Some((ty, hir_ty)) = search_stack.pop() {
483-
match (&ty.kind(), &hir_ty.kind) {
483+
match (ty.kind(), &hir_ty.kind) {
484484
// Check if the `ty` is `&'X ..` where `'X`
485485
// is the region we are looking for -- if so, and we have a `&T`
486486
// on the RHS, then we want to highlight the `&` like so:
@@ -532,9 +532,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
532532
// The following cases don't have lifetimes, so we
533533
// just worry about trying to match up the rustc type
534534
// with the HIR types:
535-
(ty::Tuple(elem_tys), hir::TyKind::Tup(elem_hir_tys)) => {
536-
search_stack
537-
.extend(iter::zip(elem_tys.iter().map(|k| k.expect_ty()), *elem_hir_tys));
535+
(&ty::Tuple(elem_tys), hir::TyKind::Tup(elem_hir_tys)) => {
536+
search_stack.extend(iter::zip(elem_tys, *elem_hir_tys));
538537
}
539538

540539
(ty::Slice(elem_ty), hir::TyKind::Slice(elem_hir_ty))

compiler/rustc_borrowck/src/type_check/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -832,9 +832,10 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
832832
return match substs
833833
.as_closure()
834834
.tupled_upvars_ty()
835-
.tuple_element_ty(field.index())
835+
.tuple_fields()
836+
.get(field.index())
836837
{
837-
Some(ty) => Ok(ty),
838+
Some(&ty) => Ok(ty),
838839
None => Err(FieldAccessError::OutOfRange {
839840
field_count: substs.as_closure().upvar_tys().count(),
840841
}),
@@ -852,7 +853,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
852853
}
853854
ty::Tuple(tys) => {
854855
return match tys.get(field.index()) {
855-
Some(&ty) => Ok(ty.expect_ty()),
856+
Some(&ty) => Ok(ty),
856857
None => Err(FieldAccessError::OutOfRange { field_count: tys.len() }),
857858
};
858859
}

compiler/rustc_borrowck/src/universal_regions.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -641,15 +641,13 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
641641
let (&output, tuplized_inputs) =
642642
inputs_and_output.skip_binder().split_last().unwrap();
643643
assert_eq!(tuplized_inputs.len(), 1, "multiple closure inputs");
644-
let ty::Tuple(inputs) = tuplized_inputs[0].kind() else {
644+
let &ty::Tuple(inputs) = tuplized_inputs[0].kind() else {
645645
bug!("closure inputs not a tuple: {:?}", tuplized_inputs[0]);
646646
};
647647

648648
ty::Binder::bind_with_vars(
649649
tcx.mk_type_list(
650-
iter::once(closure_ty)
651-
.chain(inputs.iter().map(|k| k.expect_ty()))
652-
.chain(iter::once(output)),
650+
iter::once(closure_ty).chain(inputs).chain(iter::once(output)),
653651
),
654652
bound_vars,
655653
)

compiler/rustc_codegen_cranelift/src/abi/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
117117
.unzip();
118118
let return_layout = self.layout_of(return_ty);
119119
let return_tys = if let ty::Tuple(tup) = return_ty.kind() {
120-
tup.types().map(|ty| AbiParam::new(self.clif_type(ty).unwrap())).collect()
120+
tup.iter().map(|ty| AbiParam::new(self.clif_type(ty).unwrap())).collect()
121121
} else {
122122
vec![AbiParam::new(self.clif_type(return_ty).unwrap())]
123123
};
@@ -199,7 +199,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_
199199
};
200200

201201
let mut params = Vec::new();
202-
for (i, _arg_ty) in tupled_arg_tys.types().enumerate() {
202+
for (i, _arg_ty) in tupled_arg_tys.iter().enumerate() {
203203
let arg_abi = arg_abis_iter.next().unwrap();
204204
let param =
205205
cvalue_for_param(fx, Some(local), Some(i), arg_abi, &mut block_params_iter);

compiler/rustc_codegen_cranelift/src/common.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ fn clif_pair_type_from_ty<'tcx>(
9090
ty: Ty<'tcx>,
9191
) -> Option<(types::Type, types::Type)> {
9292
Some(match ty.kind() {
93-
ty::Tuple(substs) if substs.len() == 2 => {
94-
let mut types = substs.types();
95-
let a = clif_type_from_ty(tcx, types.next().unwrap())?;
96-
let b = clif_type_from_ty(tcx, types.next().unwrap())?;
93+
ty::Tuple(types) if types.len() == 2 => {
94+
let a = clif_type_from_ty(tcx, types[0])?;
95+
let b = clif_type_from_ty(tcx, types[1])?;
9796
if a.is_vector() || b.is_vector() {
9897
return None;
9998
}

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -752,9 +752,8 @@ pub fn type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll
752752
prepare_enum_metadata(cx, t, def.did, unique_type_id, vec![]).finalize(cx)
753753
}
754754
},
755-
ty::Tuple(elements) => {
756-
let tys: Vec<_> = elements.iter().map(|k| k.expect_ty()).collect();
757-
prepare_tuple_metadata(cx, t, &tys, unique_type_id, NO_SCOPE_METADATA).finalize(cx)
755+
ty::Tuple(tys) => {
756+
prepare_tuple_metadata(cx, t, tys, unique_type_id, NO_SCOPE_METADATA).finalize(cx)
758757
}
759758
// Type parameters from polymorphized functions.
760759
ty::Param(_) => MetadataCreationResult::new(param_type_metadata(cx, t), false),

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn push_debuginfo_type_name<'tcx>(
8686
}
8787

8888
for component_type in component_types {
89-
push_debuginfo_type_name(tcx, component_type.expect_ty(), true, output, visited);
89+
push_debuginfo_type_name(tcx, component_type, true, output, visited);
9090
push_arg_separator(cpp_like_debuginfo, output);
9191
}
9292
if !component_types.is_empty() {

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ use rustc_middle::ty::{
6969
self,
7070
error::TypeError,
7171
subst::{GenericArgKind, Subst, SubstsRef},
72-
Binder, Region, Ty, TyCtxt, TypeFoldable,
72+
Binder, List, Region, Ty, TyCtxt, TypeFoldable,
7373
};
7474
use rustc_span::{sym, BytePos, DesugaringKind, MultiSpan, Pos, Span};
7575
use rustc_target::spec::abi;
@@ -1361,7 +1361,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13611361
let mut values =
13621362
(DiagnosticStyledString::normal("("), DiagnosticStyledString::normal("("));
13631363
let len = substs1.len();
1364-
for (i, (left, right)) in substs1.types().zip(substs2.types()).enumerate() {
1364+
for (i, (left, right)) in substs1.iter().zip(substs2).enumerate() {
13651365
let (x1, x2) = self.cmp(left, right);
13661366
(values.0).0.extend(x1.0);
13671367
(values.1).0.extend(x2.0);
@@ -2042,8 +2042,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
20422042
// If a tuple of length one was expected and the found expression has
20432043
// parentheses around it, perhaps the user meant to write `(expr,)` to
20442044
// build a tuple (issue #86100)
2045-
(ty::Tuple(_), _) => {
2046-
self.emit_tuple_wrap_err(&mut err, span, found, expected)
2045+
(ty::Tuple(fields), _) => {
2046+
self.emit_tuple_wrap_err(&mut err, span, found, fields)
20472047
}
20482048
// If a character was expected and the found expression is a string literal
20492049
// containing a single character, perhaps the user meant to write `'c'` to
@@ -2111,12 +2111,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
21112111
err: &mut DiagnosticBuilder<'tcx>,
21122112
span: Span,
21132113
found: Ty<'tcx>,
2114-
expected: Ty<'tcx>,
2114+
expected_fields: &List<Ty<'tcx>>,
21152115
) {
2116-
let [expected_tup_elem] = &expected.tuple_fields().collect::<Vec<_>>()[..]
2117-
else { return };
2116+
let [expected_tup_elem] = expected_fields[..] else { return };
21182117

2119-
if !same_type_modulo_infer(*expected_tup_elem, found) {
2118+
if !same_type_modulo_infer(expected_tup_elem, found) {
21202119
return;
21212120
}
21222121

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ fn closure_args(fn_sig: &ty::PolyFnSig<'_>) -> String {
254254
.skip_binder()
255255
.iter()
256256
.next()
257-
.map(|args| args.tuple_fields().map(|arg| arg.to_string()).collect::<Vec<_>>().join(", "))
257+
.map(|args| {
258+
args.tuple_fields().iter().map(|arg| arg.to_string()).collect::<Vec<_>>().join(", ")
259+
})
258260
.unwrap_or_default()
259261
}
260262

compiler/rustc_lint/src/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2621,7 +2621,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
26212621
}
26222622
Tuple(..) => {
26232623
// Proceed recursively, check all fields.
2624-
ty.tuple_fields().find_map(|field| ty_find_init_error(tcx, field, init))
2624+
ty.tuple_fields().iter().find_map(|field| ty_find_init_error(tcx, field, init))
26252625
}
26262626
// Conservative fallback.
26272627
_ => None,
@@ -2934,7 +2934,7 @@ impl ClashingExternDeclarations {
29342934
)
29352935
}
29362936
(Tuple(a_substs), Tuple(b_substs)) => {
2937-
a_substs.types().eq_by(b_substs.types(), |a_ty, b_ty| {
2937+
a_substs.iter().eq_by(b_substs.iter(), |a_ty, b_ty| {
29382938
structurally_same_type_impl(seen_types, cx, a_ty, b_ty, ckind)
29392939
})
29402940
}

compiler/rustc_lint/src/unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
246246
} else {
247247
vec![]
248248
};
249-
for (i, ty) in tys.iter().map(|k| k.expect_ty()).enumerate() {
249+
for (i, ty) in tys.iter().enumerate() {
250250
let descr_post = &format!(" in tuple element {}", i);
251251
let span = *spans.get(i).unwrap_or(&span);
252252
if check_must_use_ty(cx, ty, expr, span, descr_pre, descr_post, plural_len)

compiler/rustc_middle/src/mir/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ fn use_verbose<'tcx>(ty: Ty<'tcx>, fn_def: bool) -> bool {
428428
ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char | ty::Float(_) => false,
429429
// Unit type
430430
ty::Tuple(g_args) if g_args.is_empty() => false,
431-
ty::Tuple(g_args) => g_args.iter().any(|g_arg| use_verbose(g_arg.expect_ty(), fn_def)),
431+
ty::Tuple(g_args) => g_args.iter().any(|g_arg| use_verbose(g_arg, fn_def)),
432432
ty::Array(ty, _) => use_verbose(ty, fn_def),
433433
ty::FnDef(..) => fn_def,
434434
_ => true,

compiler/rustc_middle/src/mir/tcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'tcx> PlaceTy<'tcx> {
4646
let field_def = &variant_def.fields[f.index()];
4747
field_def.ty(tcx, substs)
4848
}
49-
ty::Tuple(ref tys) => tys[f.index()].expect_ty(),
49+
ty::Tuple(tys) => tys[f.index()],
5050
_ => bug!("extracting field of non-tuple non-adt: {:?}", self),
5151
};
5252
debug!("field_ty self: {:?} f: {:?} yields: {:?}", self, f, answer);

compiler/rustc_middle/src/ty/context.rs

+37-12
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ pub struct CtxtInterners<'tcx> {
101101
// Specifically use a speedy hash algorithm for these hash sets, since
102102
// they're accessed quite often.
103103
type_: InternedSet<'tcx, TyS<'tcx>>,
104-
type_list: InternedSet<'tcx, List<Ty<'tcx>>>,
105104
substs: InternedSet<'tcx, InternalSubsts<'tcx>>,
106105
canonical_var_infos: InternedSet<'tcx, List<CanonicalVarInfo<'tcx>>>,
107106
region: InternedSet<'tcx, RegionKind>,
@@ -129,7 +128,6 @@ impl<'tcx> CtxtInterners<'tcx> {
129128
CtxtInterners {
130129
arena,
131130
type_: Default::default(),
132-
type_list: Default::default(),
133131
substs: Default::default(),
134132
region: Default::default(),
135133
poly_existential_predicates: Default::default(),
@@ -1657,6 +1655,8 @@ macro_rules! nop_lift {
16571655
type Lifted = $lifted;
16581656
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
16591657
if tcx.interners.$set.contains_pointer_to(&InternedInSet(self.0.0)) {
1658+
// SAFETY: `self` is interned and therefore valid
1659+
// for the entire lifetime of the `TyCtxt`.
16601660
Some(unsafe { mem::transmute(self) })
16611661
} else {
16621662
None
@@ -1666,6 +1666,25 @@ macro_rules! nop_lift {
16661666
};
16671667
}
16681668

1669+
// Can't use the macros as we have reuse the `substs` here.
1670+
//
1671+
// See `intern_type_list` for more info.
1672+
impl<'a, 'tcx> Lift<'tcx> for &'a List<Ty<'a>> {
1673+
type Lifted = &'tcx List<Ty<'tcx>>;
1674+
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
1675+
if self.is_empty() {
1676+
return Some(List::empty());
1677+
}
1678+
if tcx.interners.substs.contains_pointer_to(&InternedInSet(self.as_substs())) {
1679+
// SAFETY: `self` is interned and therefore valid
1680+
// for the entire lifetime of the `TyCtxt`.
1681+
Some(unsafe { mem::transmute::<&'a List<Ty<'a>>, &'tcx List<Ty<'tcx>>>(self) })
1682+
} else {
1683+
None
1684+
}
1685+
}
1686+
}
1687+
16691688
macro_rules! nop_list_lift {
16701689
($set:ident; $ty:ty => $lifted:ty) => {
16711690
impl<'a, 'tcx> Lift<'tcx> for &'a List<$ty> {
@@ -1690,7 +1709,6 @@ nop_lift! {const_; Const<'a> => Const<'tcx>}
16901709
nop_lift_old! {const_allocation; &'a Allocation => &'tcx Allocation}
16911710
nop_lift! {predicate; Predicate<'a> => Predicate<'tcx>}
16921711

1693-
nop_list_lift! {type_list; Ty<'a> => Ty<'tcx>}
16941712
nop_list_lift! {poly_existential_predicates; ty::Binder<'a, ExistentialPredicate<'a>> => ty::Binder<'tcx, ExistentialPredicate<'tcx>>}
16951713
nop_list_lift! {predicates; Predicate<'a> => Predicate<'tcx>}
16961714
nop_list_lift! {canonical_var_infos; CanonicalVarInfo<'a> => CanonicalVarInfo<'tcx>}
@@ -2189,7 +2207,6 @@ macro_rules! slice_interners {
21892207
}
21902208

21912209
slice_interners!(
2192-
type_list: _intern_type_list(Ty<'tcx>),
21932210
substs: _intern_substs(GenericArg<'tcx>),
21942211
canonical_var_infos: _intern_canonical_var_infos(CanonicalVarInfo<'tcx>),
21952212
poly_existential_predicates:
@@ -2259,7 +2276,7 @@ impl<'tcx> TyCtxt<'tcx> {
22592276
) -> PolyFnSig<'tcx> {
22602277
sig.map_bound(|s| {
22612278
let params_iter = match s.inputs()[0].kind() {
2262-
ty::Tuple(params) => params.into_iter().map(|k| k.expect_ty()),
2279+
ty::Tuple(params) => params.into_iter(),
22632280
_ => bug!(),
22642281
};
22652282
self.mk_fn_sig(params_iter, s.output(), s.c_variadic, unsafety, abi::Abi::Rust)
@@ -2421,15 +2438,11 @@ impl<'tcx> TyCtxt<'tcx> {
24212438

24222439
#[inline]
24232440
pub fn intern_tup(self, ts: &[Ty<'tcx>]) -> Ty<'tcx> {
2424-
let kinds: Vec<_> = ts.iter().map(|&t| GenericArg::from(t)).collect();
2425-
self.mk_ty(Tuple(self.intern_substs(&kinds)))
2441+
self.mk_ty(Tuple(self.intern_type_list(&ts)))
24262442
}
24272443

24282444
pub fn mk_tup<I: InternAs<[Ty<'tcx>], Ty<'tcx>>>(self, iter: I) -> I::Output {
2429-
iter.intern_with(|ts| {
2430-
let kinds: Vec<_> = ts.iter().map(|&t| GenericArg::from(t)).collect();
2431-
self.mk_ty(Tuple(self.intern_substs(&kinds)))
2432-
})
2445+
iter.intern_with(|ts| self.mk_ty(Tuple(self.intern_type_list(&ts))))
24332446
}
24342447

24352448
#[inline]
@@ -2611,7 +2624,19 @@ impl<'tcx> TyCtxt<'tcx> {
26112624
}
26122625

26132626
pub fn intern_type_list(self, ts: &[Ty<'tcx>]) -> &'tcx List<Ty<'tcx>> {
2614-
if ts.is_empty() { List::empty() } else { self._intern_type_list(ts) }
2627+
if ts.is_empty() {
2628+
List::empty()
2629+
} else {
2630+
// Actually intern type lists as lists of `GenericArg`s.
2631+
//
2632+
// Transmuting from `Ty<'tcx>` to `GenericArg<'tcx>` is sound
2633+
// as explained in ty_slice_as_generic_arg`. With this,
2634+
// we guarantee that even when transmuting between `List<Ty<'tcx>>`
2635+
// and `List<GenericArg<'tcx>>`, the uniqueness requirement for
2636+
// lists is upheld.
2637+
let substs = self._intern_substs(ty::subst::ty_slice_as_generic_args(ts));
2638+
substs.try_as_type_list().unwrap()
2639+
}
26152640
}
26162641

26172642
pub fn intern_substs(self, ts: &[GenericArg<'tcx>]) -> &'tcx List<GenericArg<'tcx>> {

compiler/rustc_middle/src/ty/diagnostics.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,10 @@ impl<'tcx> Ty<'tcx> {
116116
}
117117
_ => true,
118118
}),
119-
Projection(ProjectionTy { substs: args, .. }) | Adt(_, args) | Tuple(args) => {
119+
Projection(ProjectionTy { substs: args, .. }) | Adt(_, args) => {
120120
args.iter().all(generic_arg_is_suggestible)
121121
}
122+
Tuple(args) => args.iter().all(|ty| ty.is_suggestable()),
122123
Slice(ty) | RawPtr(TypeAndMut { ty, .. }) | Ref(_, ty, _) => ty.is_suggestable(),
123124
Array(ty, c) => ty.is_suggestable() && const_is_suggestable(c.val()),
124125
_ => true,

compiler/rustc_middle/src/ty/flags.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ impl FlagComputation {
201201
self.add_ty(ty);
202202
}
203203

204-
&ty::Tuple(ref substs) => {
205-
self.add_substs(substs);
204+
&ty::Tuple(types) => {
205+
self.add_tys(types);
206206
}
207207

208208
&ty::FnDef(_, substs) => {

compiler/rustc_middle/src/ty/impls_ty.rs

+30
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,36 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::subst::GenericArg<'t
6161
}
6262
}
6363

64+
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::subst::GenericArgKind<'tcx> {
65+
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
66+
match self {
67+
// WARNING: We dedup cache the `HashStable` results for `List`
68+
// while ignoring types and freely transmute
69+
// between `List<Ty<'tcx>>` and `List<GenericArg<'tcx>>`.
70+
// See `fn intern_type_list` for more details.
71+
//
72+
// 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).
79+
ty::subst::GenericArgKind::Type(ty) => ty.hash_stable(hcx, hasher),
80+
ty::subst::GenericArgKind::Const(ct) => {
81+
0xFFu8.hash_stable(hcx, hasher);
82+
mem::discriminant(self).hash_stable(hcx, hasher);
83+
ct.hash_stable(hcx, hasher);
84+
}
85+
ty::subst::GenericArgKind::Lifetime(lt) => {
86+
0xFFu8.hash_stable(hcx, hasher);
87+
mem::discriminant(self).hash_stable(hcx, hasher);
88+
lt.hash_stable(hcx, hasher);
89+
}
90+
}
91+
}
92+
}
93+
6494
impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionKind {
6595
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
6696
mem::discriminant(self).hash_stable(hcx, hasher);

0 commit comments

Comments
 (0)