Skip to main content

luaur_ast/methods/
parser_restore_locals.rs

1use crate::records::ast_local::AstLocal;
2use crate::records::parser::Parser;
3
4impl Parser {
5    #[allow(non_snake_case)]
6    pub fn restore_locals(&mut self, offset: u32) {
7        let offset = offset as usize;
8
9        for i in (offset + 1..=self.local_stack.len()).rev() {
10            let l_ptr = self.local_stack[i - 1];
11
12            // Safety: local_stack holds live arena pointers; `l` borrows the arena,
13            // not `self`, so the local_map mutation below does not alias it.
14            let l = unsafe { &*l_ptr };
15            *self.local_map.get_or_insert(l.name) = l.shadow;
16        }
17
18        self.local_stack.truncate(offset);
19    }
20}