Skip to content

Commit 2704f5b

Browse files
committed
Implement Generalizer::consts
1 parent d0ef85e commit 2704f5b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/librustc/infer/combine.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '
444444
fn tys(&mut self, t: Ty<'tcx>, t2: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
445445
assert_eq!(t, t2); // we are abusing TypeRelation here; both LHS and RHS ought to be ==
446446

447-
// Check to see whether the type we are genealizing references
447+
// Check to see whether the type we are generalizing references
448448
// any other type variable related to `vid` via
449449
// subtyping. This is basically our "occurs check", preventing
450450
// us from creating infinitely sized types.
@@ -551,7 +551,21 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '
551551
-> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
552552
assert_eq!(c, c2); // we are abusing TypeRelation here; both LHS and RHS ought to be ==
553553

554-
unimplemented!() // TODO(const_generics)
554+
match c.val {
555+
ConstValue::Infer(InferConst::Var(vid)) => {
556+
let mut variables = self.infcx.const_unification_table.borrow_mut();
557+
match variables.probe_value(vid) {
558+
Some(u) => {
559+
drop(variables);
560+
self.relate(&u, &u)
561+
}
562+
None => Ok(c),
563+
}
564+
}
565+
_ => {
566+
relate::super_relate_consts(self, c, c)
567+
}
568+
}
555569
}
556570
}
557571

src/librustc/infer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,12 +1571,12 @@ impl<'tcx> fmt::Debug for RegionObligation<'tcx> {
15711571
}
15721572

15731573
pub fn replace_const_if_possible<'tcx>(
1574-
mut table: RefMut<ut::UnificationTable<ut::InPlace<ty::ConstVid<'tcx>>>>,
1574+
mut variables: RefMut<ut::UnificationTable<ut::InPlace<ty::ConstVid<'tcx>>>>,
15751575
c: &'tcx ty::Const<'tcx>,
15761576
) -> &'tcx ty::Const<'tcx> {
15771577
match c.val {
15781578
ConstValue::Infer(InferConst::Var(vid)) => {
1579-
match table.probe_value(vid) {
1579+
match variables.probe_value(vid) {
15801580
Some(c) => c,
15811581
None => c,
15821582
}

0 commit comments

Comments
 (0)