diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-14 06:11:47 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-14 06:11:47 +0000 |
commit | 38a3c76d154231ded00ca1decfd55bdaebe67bae (patch) | |
tree | 6cadcde235b500a6dd4276c6d2c4ca34cfa2c658 /crates/ra_hir | |
parent | e918b1f2b332e63e4918ca99503a812d1ce41ce0 (diff) | |
parent | b8f62095d6cf07ba521cdb3f7bac147496b313c9 (diff) |
Merge #2234
2234: Normalize data r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/expr/scope.rs | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs index 0e49a28d6..fe5e836f2 100644 --- a/crates/ra_hir/src/expr/scope.rs +++ b/crates/ra_hir/src/expr/scope.rs | |||
@@ -17,7 +17,6 @@ impl_arena_id!(ScopeId); | |||
17 | 17 | ||
18 | #[derive(Debug, PartialEq, Eq)] | 18 | #[derive(Debug, PartialEq, Eq)] |
19 | pub struct ExprScopes { | 19 | pub struct ExprScopes { |
20 | pub(crate) body: Arc<Body>, | ||
21 | scopes: Arena<ScopeId, ScopeData>, | 20 | scopes: Arena<ScopeId, ScopeData>, |
22 | scope_by_expr: FxHashMap<ExprId, ScopeId>, | 21 | scope_by_expr: FxHashMap<ExprId, ScopeId>, |
23 | } | 22 | } |
@@ -47,19 +46,16 @@ pub(crate) struct ScopeData { | |||
47 | impl ExprScopes { | 46 | impl ExprScopes { |
48 | pub(crate) fn expr_scopes_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<ExprScopes> { | 47 | pub(crate) fn expr_scopes_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<ExprScopes> { |
49 | let body = db.body(def); | 48 | let body = db.body(def); |
50 | let res = ExprScopes::new(body); | 49 | let res = ExprScopes::new(&*body); |
51 | Arc::new(res) | 50 | Arc::new(res) |
52 | } | 51 | } |
53 | 52 | ||
54 | fn new(body: Arc<Body>) -> ExprScopes { | 53 | fn new(body: &Body) -> ExprScopes { |
55 | let mut scopes = ExprScopes { | 54 | let mut scopes = |
56 | body: body.clone(), | 55 | ExprScopes { scopes: Arena::default(), scope_by_expr: FxHashMap::default() }; |
57 | scopes: Arena::default(), | ||
58 | scope_by_expr: FxHashMap::default(), | ||
59 | }; | ||
60 | let root = scopes.root_scope(); | 56 | let root = scopes.root_scope(); |
61 | scopes.add_params_bindings(root, body.params()); | 57 | scopes.add_params_bindings(body, root, body.params()); |
62 | compute_expr_scopes(body.body_expr(), &body, &mut scopes, root); | 58 | compute_expr_scopes(body.body_expr(), body, &mut scopes, root); |
63 | scopes | 59 | scopes |
64 | } | 60 | } |
65 | 61 | ||
@@ -99,9 +95,8 @@ impl ExprScopes { | |||
99 | } | 95 | } |
100 | } | 96 | } |
101 | 97 | ||
102 | fn add_params_bindings(&mut self, scope: ScopeId, params: &[PatId]) { | 98 | fn add_params_bindings(&mut self, body: &Body, scope: ScopeId, params: &[PatId]) { |
103 | let body = Arc::clone(&self.body); | 99 | params.iter().for_each(|pat| self.add_bindings(body, scope, *pat)); |
104 | params.iter().for_each(|pat| self.add_bindings(&body, scope, *pat)); | ||
105 | } | 100 | } |
106 | 101 | ||
107 | fn set_scope(&mut self, node: ExprId, scope: ScopeId) { | 102 | fn set_scope(&mut self, node: ExprId, scope: ScopeId) { |
@@ -151,7 +146,7 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope | |||
151 | } | 146 | } |
152 | Expr::Lambda { args, body: body_expr, .. } => { | 147 | Expr::Lambda { args, body: body_expr, .. } => { |
153 | let scope = scopes.new_scope(scope); | 148 | let scope = scopes.new_scope(scope); |
154 | scopes.add_params_bindings(scope, &args); | 149 | scopes.add_params_bindings(body, scope, &args); |
155 | compute_expr_scopes(*body_expr, body, scopes, scope); | 150 | compute_expr_scopes(*body_expr, body, scopes, scope); |
156 | } | 151 | } |
157 | Expr::Match { expr, arms } => { | 152 | Expr::Match { expr, arms } => { |