From b260641e0caa3938151afe66fa3bf5691b8c3caa Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 13 Apr 2019 11:29:47 +0300 Subject: slight encapsulation --- crates/ra_hir/src/expr/scope.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'crates/ra_hir/src/expr') diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs index 090343d12..7f53f23aa 100644 --- a/crates/ra_hir/src/expr/scope.rs +++ b/crates/ra_hir/src/expr/scope.rs @@ -18,7 +18,7 @@ impl_arena_id!(ScopeId); pub struct ExprScopes { body: Arc, scopes: Arena, - pub(crate) scope_for: FxHashMap, + scope_by_expr: FxHashMap, } #[derive(Debug, PartialEq, Eq)] @@ -54,7 +54,7 @@ impl ExprScopes { let mut scopes = ExprScopes { body: body.clone(), scopes: Arena::default(), - scope_for: FxHashMap::default(), + scope_by_expr: FxHashMap::default(), }; let root = scopes.root_scope(); scopes.add_params_bindings(root, body.params()); @@ -73,6 +73,14 @@ impl ExprScopes { std::iter::successors(scope, move |&scope| self.scopes[scope].parent) } + pub(crate) fn scope_for(&self, expr: ExprId) -> Option { + self.scope_by_expr.get(&expr).map(|&scope| scope) + } + + pub(crate) fn scope_by_expr(&self) -> &FxHashMap { + &self.scope_by_expr + } + fn root_scope(&mut self) -> ScopeId { self.scopes.alloc(ScopeData { parent: None, entries: vec![] }) } @@ -99,11 +107,7 @@ impl ExprScopes { } fn set_scope(&mut self, node: ExprId, scope: ScopeId) { - self.scope_for.insert(node, scope); - } - - pub(crate) fn scope_for(&self, expr: ExprId) -> Option { - self.scope_for.get(&expr).map(|&scope| scope) + self.scope_by_expr.insert(node, scope); } } -- cgit v1.2.3