Skip to content

Commit bb17fe8

Browse files
committed
add real folder to Region
1 parent da2f897 commit bb17fe8

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,7 @@ impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> {
15321532
})
15331533
}
15341534
ty::ReErased => RegionKind::ReErased,
1535-
_=> unimplemented!()
1535+
_ => unimplemented!(),
15361536
}
15371537
}
15381538
}

compiler/stable_mir/src/fold.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use std::ops::ControlFlow;
22

3-
use crate::Opaque;
3+
use crate::{
4+
ty::{self, BoundRegion, BoundRegionKind},
5+
Opaque,
6+
};
47

58
use super::ty::{
69
Allocation, Binder, Const, ConstDef, ConstantKind, ExistentialPredicate, FnSig, GenericArgKind,
@@ -15,6 +18,9 @@ pub trait Folder: Sized {
1518
fn fold_const(&mut self, c: &Const) -> ControlFlow<Self::Break, Const> {
1619
c.super_fold(self)
1720
}
21+
fn visit_reg(&mut self, reg: &Region) -> ControlFlow<Self::Break, Region> {
22+
reg.super_fold(self)
23+
}
1824
}
1925

2026
pub trait Foldable: Sized + Clone {
@@ -107,8 +113,39 @@ impl Foldable for GenericArgs {
107113
}
108114

109115
impl Foldable for Region {
116+
fn fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
117+
folder.visit_reg(self)
118+
}
119+
fn super_fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
120+
let mut kind = self.kind.clone();
121+
match &mut kind {
122+
crate::ty::RegionKind::ReEarlyBound(_) => {}
123+
crate::ty::RegionKind::ReLateBound(_, bound_reg) => {
124+
*bound_reg = bound_reg.fold(folder)?
125+
}
126+
crate::ty::RegionKind::ReStatic => {}
127+
crate::ty::RegionKind::RePlaceholder(bound_reg) => {
128+
bound_reg.bound = bound_reg.bound.fold(folder)?
129+
}
130+
crate::ty::RegionKind::ReErased => {}
131+
}
132+
ControlFlow::Continue(ty::Region { kind: kind }.into())
133+
}
134+
}
135+
136+
impl Foldable for BoundRegion {
137+
fn super_fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
138+
ControlFlow::Continue(BoundRegion { var: self.var, kind: self.kind.fold(folder)? })
139+
}
140+
}
141+
142+
impl Foldable for BoundRegionKind {
110143
fn super_fold<V: Folder>(&self, _folder: &mut V) -> ControlFlow<V::Break, Self> {
111-
ControlFlow::Continue(self.clone())
144+
match self {
145+
BoundRegionKind::BrAnon => ControlFlow::Continue(self.clone()),
146+
BoundRegionKind::BrNamed(_, _) => ControlFlow::Continue(self.clone()),
147+
BoundRegionKind::BrEnv => ControlFlow::Continue(self.clone()),
148+
}
112149
}
113150
}
114151

0 commit comments

Comments
 (0)