diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs
index 090343d12004..7f53f23aa937 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);
}
}
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 34a00a3007c1..8d53079c69ae 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -368,7 +368,7 @@ fn scope_for_offset(
offset: TextUnit,
) -> Option {
scopes
- .scope_for
+ .scope_by_expr()
.iter()
.filter_map(|(id, scope)| Some((source_map.expr_syntax(*id)?, scope)))
// find containing scope
@@ -388,7 +388,7 @@ fn adjust(
) -> Option {
let r = ptr.range();
let child_scopes = scopes
- .scope_for
+ .scope_by_expr()
.iter()
.filter_map(|(id, scope)| Some((source_map.expr_syntax(*id)?, scope)))
.map(|(ptr, scope)| (ptr.range(), scope))