Skip to content

Commit 15add36

Browse files
committed
Auto merge of #49091 - nikomatsakis:issue-49043-ty-infer-hash, r=michaelwoerister
extend stable hasher to support `CanonicalTy` Fixes #49043 r? @michaelwoerister
2 parents 152217d + f02dc74 commit 15add36

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

src/librustc/ich/impls_ty.rs

+48-2
Original file line numberDiff line numberDiff line change
@@ -902,13 +902,59 @@ for ty::TypeVariants<'gcx>
902902
TyForeign(def_id) => {
903903
def_id.hash_stable(hcx, hasher);
904904
}
905-
TyInfer(..) => {
906-
bug!("ty::TypeVariants::hash_stable() - Unexpected variant {:?}.", *self)
905+
TyInfer(infer_ty) => {
906+
infer_ty.hash_stable(hcx, hasher);
907907
}
908908
}
909909
}
910910
}
911911

912+
impl_stable_hash_for!(enum ty::InferTy {
913+
TyVar(a),
914+
IntVar(a),
915+
FloatVar(a),
916+
FreshTy(a),
917+
FreshIntTy(a),
918+
FreshFloatTy(a),
919+
CanonicalTy(a),
920+
});
921+
922+
impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
923+
for ty::TyVid
924+
{
925+
fn hash_stable<W: StableHasherResult>(&self,
926+
_hcx: &mut StableHashingContext<'a>,
927+
_hasher: &mut StableHasher<W>) {
928+
// TyVid values are confined to an inference context and hence
929+
// should not be hashed.
930+
bug!("ty::TypeVariants::hash_stable() - can't hash a TyVid {:?}.", *self)
931+
}
932+
}
933+
934+
impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
935+
for ty::IntVid
936+
{
937+
fn hash_stable<W: StableHasherResult>(&self,
938+
_hcx: &mut StableHashingContext<'a>,
939+
_hasher: &mut StableHasher<W>) {
940+
// IntVid values are confined to an inference context and hence
941+
// should not be hashed.
942+
bug!("ty::TypeVariants::hash_stable() - can't hash an IntVid {:?}.", *self)
943+
}
944+
}
945+
946+
impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
947+
for ty::FloatVid
948+
{
949+
fn hash_stable<W: StableHasherResult>(&self,
950+
_hcx: &mut StableHashingContext<'a>,
951+
_hasher: &mut StableHasher<W>) {
952+
// FloatVid values are confined to an inference context and hence
953+
// should not be hashed.
954+
bug!("ty::TypeVariants::hash_stable() - can't hash a FloatVid {:?}.", *self)
955+
}
956+
}
957+
912958
impl_stable_hash_for!(struct ty::ParamTy {
913959
idx,
914960
name

src/librustc/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ macro_rules! __impl_stable_hash_field {
7272

7373
#[macro_export]
7474
macro_rules! impl_stable_hash_for {
75-
(enum $enum_name:path { $( $variant:ident $( ( $($arg:ident),* ) )* ),* }) => {
75+
(enum $enum_name:path { $( $variant:ident $( ( $($arg:ident),* ) )* ),* $(,)* }) => {
7676
impl<'a, 'tcx> ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $enum_name {
7777
#[inline]
7878
fn hash_stable<W: ::rustc_data_structures::stable_hasher::StableHasherResult>(&self,

src/librustc/traits/query/dropck_outlives.rs

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ impl<'cx, 'gcx, 'tcx> At<'cx, 'gcx, 'tcx> {
5151
let gcx = tcx.global_tcx();
5252
let (c_ty, orig_values) = self.infcx.canonicalize_query(&self.param_env.and(ty));
5353
let span = self.cause.span;
54+
debug!("c_ty = {:?}", c_ty);
5455
match &gcx.dropck_outlives(c_ty) {
5556
Ok(result) if result.is_proven() => {
5657
match self.infcx.instantiate_query_result(

src/test/incremental/issue-49043.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Regression test for hashing involving canonical variables. In this
12+
// test -- which has an intensional error -- the type of the value
13+
// being dropped winds up including a type variable. Canonicalization
14+
// would then produce a `?0` which -- in turn -- triggered an ICE in
15+
// hashing.
16+
17+
// revisions:cfail1
18+
19+
fn main() {
20+
println!("Hello, world! {}",*thread_rng().choose(&[0, 1, 2, 3]).unwrap());
21+
//[cfail1]~^ ERROR cannot find function `thread_rng`
22+
}

0 commit comments

Comments
 (0)