Skip to content

Commit 6b0ef9c

Browse files
Deny const variables as well
1 parent 1e2eb97 commit 6b0ef9c

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

compiler/rustc_middle/src/ty/consts/kind.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::mir::interpret::{AllocId, ConstValue, Scalar};
55
use crate::ty::subst::{InternalSubsts, SubstsRef};
66
use crate::ty::ParamEnv;
77
use crate::ty::{self, TyCtxt, TypeVisitable};
8+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
89
use rustc_errors::ErrorGuaranteed;
910
use rustc_hir::def_id::DefId;
1011
use rustc_macros::HashStable;
@@ -108,14 +109,22 @@ impl<'tcx> ConstKind<'tcx> {
108109

109110
/// An inference variable for a const, for use in const generics.
110111
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Hash)]
111-
#[derive(HashStable)]
112112
pub enum InferConst<'tcx> {
113113
/// Infer the value of the const.
114114
Var(ty::ConstVid<'tcx>),
115115
/// A fresh const variable. See `infer::freshen` for more details.
116116
Fresh(u32),
117117
}
118118

119+
impl<CTX> HashStable<CTX> for InferConst<'_> {
120+
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
121+
match self {
122+
InferConst::Var(_) => panic!("const variables should not be hashed: {self:?}"),
123+
InferConst::Fresh(i) => i.hash_stable(hcx, hasher),
124+
}
125+
}
126+
}
127+
119128
enum EvalMode {
120129
Typeck,
121130
Mir,

compiler/rustc_middle/src/ty/context.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ impl<'tcx> CtxtInterners<'tcx> {
200200

201201
// 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
204-
.flags
205-
.intersects(TypeFlags::HAS_RE_INFER | TypeFlags::HAS_TY_INFER)
203+
let stable_hash = if flags.flags.intersects(TypeFlags::NEEDS_INFER)
206204
|| sess.opts.incremental.is_none()
207205
{
208206
Fingerprint::ZERO

compiler/rustc_type_ir/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ impl<CTX> HashStable<CTX> for InferTy {
676676
discriminant(self).hash_stable(ctx, hasher);
677677
match self {
678678
TyVar(_) | IntVar(_) | FloatVar(_) => {
679-
panic!("inference variables should not be hashed: {self:?}")
679+
panic!("type variables should not be hashed: {self:?}")
680680
}
681681
FreshTy(v) | FreshIntTy(v) | FreshFloatTy(v) => v.hash_stable(ctx, hasher),
682682
}

0 commit comments

Comments
 (0)