about summary refs log tree commit diff
diff options
context:
space:
mode:
authorouz-a <ouz.agz@gmail.com>2023-09-28 12:32:15 +0300
committerouz-a <ouz.agz@gmail.com>2023-09-28 12:32:15 +0300
commitbb17fe8bf5b32cd7fefbab95b6b1b7ee04628dbd (patch)
treed53368e7a3706f0af6797754f3d4ed6005e301f8
parentda2f897e590be03eb4acddfd9df804545b738b65 (diff)
downloadrust-bb17fe8bf5b32cd7fefbab95b6b1b7ee04628dbd.tar.gz
rust-bb17fe8bf5b32cd7fefbab95b6b1b7ee04628dbd.zip
add real folder to Region
-rw-r--r--compiler/rustc_smir/src/rustc_smir/mod.rs2
-rw-r--r--compiler/stable_mir/src/fold.rs41
2 files changed, 40 insertions, 3 deletions
diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs
index 3b6bacaa168..128ba076544 100644
--- a/compiler/rustc_smir/src/rustc_smir/mod.rs
+++ b/compiler/rustc_smir/src/rustc_smir/mod.rs
@@ -1532,7 +1532,7 @@ impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> {
                 })
             }
             ty::ReErased => RegionKind::ReErased,
-            _=> unimplemented!()
+            _ => unimplemented!(),
         }
     }
 }
diff --git a/compiler/stable_mir/src/fold.rs b/compiler/stable_mir/src/fold.rs
index edaf55f2aeb..bdc80bc8aa3 100644
--- a/compiler/stable_mir/src/fold.rs
+++ b/compiler/stable_mir/src/fold.rs
@@ -1,6 +1,9 @@
 use std::ops::ControlFlow;
 
-use crate::Opaque;
+use crate::{
+    ty::{self, BoundRegion, BoundRegionKind},
+    Opaque,
+};
 
 use super::ty::{
     Allocation, Binder, Const, ConstDef, ConstantKind, ExistentialPredicate, FnSig, GenericArgKind,
@@ -15,6 +18,9 @@ pub trait Folder: Sized {
     fn fold_const(&mut self, c: &Const) -> ControlFlow<Self::Break, Const> {
         c.super_fold(self)
     }
+    fn visit_reg(&mut self, reg: &Region) -> ControlFlow<Self::Break, Region> {
+        reg.super_fold(self)
+    }
 }
 
 pub trait Foldable: Sized + Clone {
@@ -107,8 +113,39 @@ impl Foldable for GenericArgs {
 }
 
 impl Foldable for Region {
+    fn fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
+        folder.visit_reg(self)
+    }
+    fn super_fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
+        let mut kind = self.kind.clone();
+        match &mut kind {
+            crate::ty::RegionKind::ReEarlyBound(_) => {}
+            crate::ty::RegionKind::ReLateBound(_, bound_reg) => {
+                *bound_reg = bound_reg.fold(folder)?
+            }
+            crate::ty::RegionKind::ReStatic => {}
+            crate::ty::RegionKind::RePlaceholder(bound_reg) => {
+                bound_reg.bound = bound_reg.bound.fold(folder)?
+            }
+            crate::ty::RegionKind::ReErased => {}
+        }
+        ControlFlow::Continue(ty::Region { kind: kind }.into())
+    }
+}
+
+impl Foldable for BoundRegion {
+    fn super_fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
+        ControlFlow::Continue(BoundRegion { var: self.var, kind: self.kind.fold(folder)? })
+    }
+}
+
+impl Foldable for BoundRegionKind {
     fn super_fold<V: Folder>(&self, _folder: &mut V) -> ControlFlow<V::Break, Self> {
-        ControlFlow::Continue(self.clone())
+        match self {
+            BoundRegionKind::BrAnon => ControlFlow::Continue(self.clone()),
+            BoundRegionKind::BrNamed(_, _) => ControlFlow::Continue(self.clone()),
+            BoundRegionKind::BrEnv => ControlFlow::Continue(self.clone()),
+        }
     }
 }