Skip to content

Commit 91af4f5

Browse files
Don't hash non-fresh Ty::Infer or RegionKind::Infer
1 parent 4b8f431 commit 91af4f5

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

compiler/rustc_middle/src/ty/context.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,11 @@ impl<'tcx> CtxtInterners<'tcx> {
198198
.intern(kind, |kind| {
199199
let flags = super::flags::FlagComputation::for_kind(&kind);
200200

201-
// It's impossible to hash inference regions (and will ICE), so we don't need to try to cache them.
201+
// It's impossible to hash inference variables (and will ICE), so we don't need to try to cache them.
202202
// Without incremental, we rarely stable-hash types, so let's not do it proactively.
203-
let stable_hash = if flags.flags.intersects(TypeFlags::HAS_RE_INFER)
203+
let stable_hash = if flags
204+
.flags
205+
.intersects(TypeFlags::HAS_RE_INFER | TypeFlags::HAS_TY_INFER)
204206
|| sess.opts.incremental.is_none()
205207
{
206208
Fingerprint::ZERO

compiler/rustc_type_ir/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -675,9 +675,9 @@ impl<CTX> HashStable<CTX> for InferTy {
675675
use InferTy::*;
676676
discriminant(self).hash_stable(ctx, hasher);
677677
match self {
678-
TyVar(v) => v.as_u32().hash_stable(ctx, hasher),
679-
IntVar(v) => v.index.hash_stable(ctx, hasher),
680-
FloatVar(v) => v.index.hash_stable(ctx, hasher),
678+
TyVar(_) | IntVar(_) | FloatVar(_) => {
679+
panic!("inference variables should not be hashed: {self:?}")
680+
}
681681
FreshTy(v) | FreshIntTy(v) | FreshFloatTy(v) => v.hash_stable(ctx, hasher),
682682
}
683683
}

compiler/rustc_type_ir/src/sty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1332,8 +1332,8 @@ where
13321332
RePlaceholder(p) => {
13331333
p.hash_stable(hcx, hasher);
13341334
}
1335-
ReVar(reg) => {
1336-
reg.hash_stable(hcx, hasher);
1335+
ReVar(_) => {
1336+
panic!("region variables should not be hashed: {self:?}")
13371337
}
13381338
}
13391339
}

0 commit comments

Comments
 (0)