Skip to content

Commit 29cbca6

Browse files
RINNE-TANChronostasys
authored andcommitted
refactor:use fn style protect generic context
1 parent c6e68ea commit 29cbca6

File tree

4 files changed

+593
-579
lines changed

4 files changed

+593
-579
lines changed

src/ast/ctx.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,6 @@ impl<'a, 'ctx> Ctx<'a> {
331331
self.send_if_go_to_def(range, range, self.plmod.path.clone());
332332
self.generic_types.insert(name, pltype);
333333
}
334-
pub fn move_generic_types(&mut self) -> FxHashMap<String, Arc<RefCell<PLType>>> {
335-
self.generic_types.clone()
336-
}
337-
pub fn reset_generic_types(&mut self, mp: FxHashMap<String, Arc<RefCell<PLType>>>) {
338-
self.generic_types = mp
339-
}
340334
pub fn add_doc_symbols(&mut self, pltype: Arc<RefCell<PLType>>) {
341335
match &*RefCell::borrow(&pltype) {
342336
PLType::FN(f) => {
@@ -390,6 +384,15 @@ impl<'a, 'ctx> Ctx<'a> {
390384
self.plmod = plmod;
391385
m
392386
}
387+
pub fn protect_generic_context<'b, T, F: FnMut(&mut Ctx<'a>) -> Result<T, PLDiag>>(
388+
&mut self,
389+
mut f: F,
390+
) -> Result<T, PLDiag> {
391+
let mp = self.generic_types.clone();
392+
let res = f(self);
393+
self.generic_types = mp;
394+
res
395+
}
393396
pub fn run_in_st_mod_mut<'b, T, F: FnMut(&mut Ctx<'a>, &mut STType) -> Result<T, PLDiag>>(
394397
&'b mut self,
395398
st: &mut STType,

0 commit comments

Comments
 (0)