diff --git a/src/librustc/infer/fudge.rs b/src/librustc/infer/fudge.rs index 18573b9ce176f..4c603cb54559d 100644 --- a/src/librustc/infer/fudge.rs +++ b/src/librustc/infer/fudge.rs @@ -3,8 +3,10 @@ use crate::ty::fold::{TypeFoldable, TypeFolder}; use super::InferCtxt; use super::RegionVariableOrigin; +use super::type_variable::TypeVariableOrigin; use std::ops::Range; +use rustc_data_structures::fx::FxHashMap; impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { /// This rather funky routine is used while processing expected @@ -115,7 +117,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { pub struct InferenceFudger<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, - type_vars: Range, + type_vars: FxHashMap, int_vars: Range, float_vars: Range, region_vars: Range, @@ -130,10 +132,9 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, 'tcx> fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { match ty.sty { ty::Infer(ty::InferTy::TyVar(vid)) => { - if self.type_vars.contains(&vid) { + if let Some(&origin) = self.type_vars.get(&vid) { // This variable was created during the fudging. // Recreate it with a fresh variable here. - let origin = self.infcx.type_variables.borrow().var_origin(vid).clone(); self.infcx.next_ty_var(origin) } else { // This variable was created before the diff --git a/src/librustc/infer/type_variable.rs b/src/librustc/infer/type_variable.rs index 5b9c3f25b20fd..cde695aefc10a 100644 --- a/src/librustc/infer/type_variable.rs +++ b/src/librustc/infer/type_variable.rs @@ -4,8 +4,8 @@ use crate::ty::{self, Ty, TyVid}; use std::cmp; use std::marker::PhantomData; -use std::ops::Range; use std::u32; +use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::snapshot_vec as sv; use rustc_data_structures::unify as ut; @@ -291,9 +291,15 @@ impl<'tcx> TypeVariableTable<'tcx> { } /// Returns a range of the type variables created during the snapshot. - pub fn vars_since_snapshot(&mut self, s: &Snapshot<'tcx>) -> Range { + pub fn vars_since_snapshot( + &mut self, + s: &Snapshot<'tcx>, + ) -> FxHashMap { let range = self.eq_relations.vars_since_snapshot(&s.eq_snapshot); - range.start.vid..range.end.vid + (range.start.vid.index..range.end.vid.index).map(|index| { + let origin = self.values.get(index as usize).origin.clone(); + (TyVid { index }, origin) + }).collect() } /// Finds the set of type variables that existed *before* `s`