Skip to content

Commit 0d25889

Browse files
committed
WIP WIP fix for rust-lang#18653
1 parent a4d7c1f commit 0d25889

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

src/librustc/infer/combine.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use super::lub::Lub;
3939
use super::sub::Sub;
4040
use super::InferCtxt;
4141
use super::{MiscVariable, TypeTrace};
42-
use super::type_variable::{RelationDir, BiTo, EqTo, SubtypeOf, SupertypeOf};
42+
use super::type_variable::{RelationDir, BiTo, EqTo, SubtypeOf, SupertypeOf, TypeVariableOrigin};
4343

4444
use ty::{IntType, UintType};
4545
use ty::{self, Ty, TyCtxt};
@@ -322,7 +322,17 @@ impl<'cx, 'gcx, 'tcx> ty::fold::TypeFolder<'gcx, 'tcx> for Generalizer<'cx, 'gcx
322322
drop(variables);
323323
self.fold_ty(u)
324324
}
325-
None => t,
325+
None => {
326+
if self.make_region_vars {
327+
let origin = variables.origin(vid);
328+
let new_var_id = variables.new_var(false, origin, None);
329+
let u = self.tcx().mk_var(new_var_id);
330+
debug!("XXX original-vid={:?} new={:?}", vid, u);
331+
u
332+
} else {
333+
t
334+
}
335+
}
326336
}
327337
}
328338
}

src/librustc/infer/equate.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
5656
let infcx = self.fields.infcx;
5757
let a = infcx.type_variables.borrow_mut().replace_if_possible(a);
5858
let b = infcx.type_variables.borrow_mut().replace_if_possible(b);
59+
debug!("{}.tys: normalized a={:?}", self.tag(), a);
60+
debug!("{}.tys: normalized b={:?}", self.tag(), b);
5961
match (&a.sty, &b.sty) {
6062
(&ty::TyInfer(TyVar(a_id)), &ty::TyInfer(TyVar(b_id))) => {
6163
infcx.type_variables.borrow_mut().relate_vars(a_id, EqTo, b_id);

src/librustc/infer/fudge.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
6565
F: FnOnce() -> Result<T, E>,
6666
T: TypeFoldable<'tcx>,
6767
{
68+
debug!("fudge_regions_if_ok(origin={:?})", origin);
69+
6870
let (region_vars, value) = self.probe(|snapshot| {
6971
let vars_at_start = self.type_variables.borrow().num_vars();
7072

src/librustc/infer/type_variable.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct TypeVariableTable<'tcx> {
3030
}
3131

3232
/// Reasons to create a type inference variable
33-
#[derive(Debug)]
33+
#[derive(Copy, Clone, Debug)]
3434
pub enum TypeVariableOrigin {
3535
MiscVariable(Span),
3636
NormalizeProjectionType(Span),
@@ -44,6 +44,7 @@ pub enum TypeVariableOrigin {
4444
DivergingBlockExpr(Span),
4545
DivergingFn(Span),
4646
LatticeVariable(Span),
47+
Generalized(ty::TyVid),
4748
}
4849

4950
struct TypeVariableData<'tcx> {
@@ -134,9 +135,11 @@ impl<'tcx> TypeVariableTable<'tcx> {
134135
///
135136
/// Precondition: neither `a` nor `b` are known.
136137
pub fn relate_vars(&mut self, a: ty::TyVid, dir: RelationDir, b: ty::TyVid) {
138+
debug!("relate_vars({:?}, {:?}, {:?})", a, dir, b);
137139
let a = self.root_var(a);
138140
let b = self.root_var(b);
139141
if a != b {
142+
debug!("relate_vars: root-a={:?} {:?} root-b={:?}", a, dir, b);
140143
if dir == EqTo {
141144
// a and b must be equal which we mark in the unification table
142145
let root = self.eq_relations.union(a, b);
@@ -223,6 +226,10 @@ impl<'tcx> TypeVariableTable<'tcx> {
223226
self.probe_root(vid)
224227
}
225228

229+
pub fn origin(&self, vid: ty::TyVid) -> TypeVariableOrigin {
230+
self.values.get(vid.index as usize).origin.clone()
231+
}
232+
226233
/// Retrieves the type of `vid` given that it is currently a root in the unification table
227234
pub fn probe_root(&mut self, vid: ty::TyVid) -> Option<Ty<'tcx>> {
228235
debug_assert!(self.root_var(vid) == vid);

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
17951795
pub fn register_predicates(&self,
17961796
obligations: Vec<traits::PredicateObligation<'tcx>>)
17971797
{
1798+
debug!("register_predicates({:?})", obligations);
17981799
for obligation in obligations {
17991800
self.register_predicate(obligation);
18001801
}

0 commit comments

Comments
 (0)