diff --git a/src/twopass.rs b/src/twopass.rs index 66c1888..c30989a 100644 --- a/src/twopass.rs +++ b/src/twopass.rs @@ -112,6 +112,13 @@ struct BuildContext<'a> { } impl BuildContext<'_> { + fn new_toplevel() -> Self { + BuildContext { + parent: None, + scope: RefCell::new(Scope::new_toplevel()), + } + } + fn request(&self, name: &ast::Ident) -> Option { if let Some(ident) = self.scope.borrow().lookup(name) { return Some(ident); @@ -214,9 +221,5 @@ fn build_function(parent: &BuildContext<'_>, code: &ast::Function) -> Function { } pub fn build(code: &ast::Function) -> Function { - let mut root = BuildContext { - parent: None, - scope: RefCell::new(Scope::new_toplevel()), - }; - build_function(&mut root, &code) + build_function(&BuildContext::new_toplevel(), &code) }