Skip to content

Commit

Permalink
Deny const variables as well
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Oct 19, 2022
1 parent 1e2eb97 commit 6b0ef9c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
11 changes: 10 additions & 1 deletion compiler/rustc_middle/src/ty/consts/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::mir::interpret::{AllocId, ConstValue, Scalar};
use crate::ty::subst::{InternalSubsts, SubstsRef};
use crate::ty::ParamEnv;
use crate::ty::{self, TyCtxt, TypeVisitable};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def_id::DefId;
use rustc_macros::HashStable;
Expand Down Expand Up @@ -108,14 +109,22 @@ impl<'tcx> ConstKind<'tcx> {

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

impl<CTX> HashStable<CTX> for InferConst<'_> {
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
match self {
InferConst::Var(_) => panic!("const variables should not be hashed: {self:?}"),
InferConst::Fresh(i) => i.hash_stable(hcx, hasher),
}
}
}

enum EvalMode {
Typeck,
Mir,
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ impl<'tcx> CtxtInterners<'tcx> {

// It's impossible to hash inference variables (and will ICE), so we don't need to try to cache them.
// Without incremental, we rarely stable-hash types, so let's not do it proactively.
let stable_hash = if flags
.flags
.intersects(TypeFlags::HAS_RE_INFER | TypeFlags::HAS_TY_INFER)
let stable_hash = if flags.flags.intersects(TypeFlags::NEEDS_INFER)
|| sess.opts.incremental.is_none()
{
Fingerprint::ZERO
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_type_ir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ impl<CTX> HashStable<CTX> for InferTy {
discriminant(self).hash_stable(ctx, hasher);
match self {
TyVar(_) | IntVar(_) | FloatVar(_) => {
panic!("inference variables should not be hashed: {self:?}")
panic!("type variables should not be hashed: {self:?}")
}
FreshTy(v) | FreshIntTy(v) | FreshFloatTy(v) => v.hash_stable(ctx, hasher),
}
Expand Down

0 comments on commit 6b0ef9c

Please sign in to comment.