about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGabriel Smith <ga29smith@gmail.com>2019-03-01 01:16:04 -0500
committervarkor <github@varkor.com>2019-05-01 23:10:57 +0100
commitfa394c2283b6bdfc87711812739a59da29a2fd2a (patch)
tree05274dc32f1ba3fa3497624705f4c3ec8212ef38
parent57d3a5a32de7a10ed7af886dc6ddd3754c9a394c (diff)
impl fold_const for Shifter
Signed-off-by: Gabriel Smith <ga29smith@gmail.com>
-rw-r--r--src/librustc/ty/fold.rs30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs
index 96705124b28..462bba94dd3 100644
--- a/src/librustc/ty/fold.rs
+++ b/src/librustc/ty/fold.rs
@@ -222,9 +222,9 @@ impl<'a, 'gcx, 'tcx, F, G, H> TypeFolder<'gcx, 'tcx> for BottomUpFolder<'a, 'gcx
         (self.lt_op)(r)
     }
 
-    fn fold_const(&mut self, c: &'tcx ty::LazyConst<'tcx>) -> &'tcx ty::LazyConst<'tcx> {
-        let c = c.super_fold_with(self);
-        (self.ct_op)(c)
+    fn fold_const(&mut self, ct: &'tcx ty::LazyConst<'tcx>) -> &'tcx ty::LazyConst<'tcx> {
+        let ct = ct.super_fold_with(self);
+        (self.ct_op)(ct)
     }
 }
 
@@ -747,7 +747,25 @@ impl TypeFolder<'gcx, 'tcx> for Shifter<'a, 'gcx, 'tcx> {
     }
 
     fn fold_const(&mut self, ct: &'tcx ty::LazyConst<'tcx>) -> &'tcx ty::LazyConst<'tcx> {
-        ct // FIXME(const_generics)
+        if let ty::LazyConst::Evaluated(ty::Const {
+            val: ConstValue::Infer(ty::InferConst::Canonical(debruijn, bound_const)),
+            ty,
+        }) = *ct {
+            if self.amount == 0 || debruijn < self.current_index {
+                ct
+            } else {
+                let debruijn = match self.direction {
+                    Direction::In => debruijn.shifted_in(self.amount),
+                    Direction::Out => {
+                        assert!(debruijn.as_u32() >= self.amount);
+                        debruijn.shifted_out(self.amount)
+                    }
+                };
+                self.tcx.mk_const_infer(ty::InferConst::Canonical(debruijn, bound_const), ty)
+            }
+        } else {
+            ct.super_fold_with(self)
+        }
     }
 }
 
@@ -842,11 +860,11 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor {
         r.bound_at_or_above_binder(self.outer_index)
     }
 
-    fn visit_const(&mut self, c: &'tcx ty::LazyConst<'tcx>) -> bool {
+    fn visit_const(&mut self, ct: &'tcx ty::LazyConst<'tcx>) -> bool {
         if let ty::LazyConst::Evaluated(ty::Const {
             val: ConstValue::Infer(ty::InferConst::Canonical(debruijn, _)),
             ..
-        }) = *c {
+        }) = *ct {
             debruijn >= self.outer_index
         } else {
             false