diff options
author | Florian Diebold <[email protected]> | 2019-01-05 23:33:58 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-01-05 23:38:08 +0000 |
commit | e5a6cf815372150ad40dee995b7b89f29e701427 (patch) | |
tree | 68d63fbccd0f5b6c4432aadf98566f428e6fba9f /crates/ra_hir/src/function | |
parent | 8e3e5ab2c81f238ea4e731f55eac79b74d9d84c3 (diff) |
Various small code review improvements
Diffstat (limited to 'crates/ra_hir/src/function')
-rw-r--r-- | crates/ra_hir/src/function/scope.rs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/crates/ra_hir/src/function/scope.rs b/crates/ra_hir/src/function/scope.rs index 0607a99cb..0a12f0b35 100644 --- a/crates/ra_hir/src/function/scope.rs +++ b/crates/ra_hir/src/function/scope.rs | |||
@@ -66,8 +66,7 @@ impl FnScopes { | |||
66 | .scope_chain_for(context_expr) | 66 | .scope_chain_for(context_expr) |
67 | .flat_map(|scope| self.entries(scope).iter()) | 67 | .flat_map(|scope| self.entries(scope).iter()) |
68 | .filter(|entry| shadowed.insert(entry.name())) | 68 | .filter(|entry| shadowed.insert(entry.name())) |
69 | .filter(|entry| entry.name() == &name) | 69 | .find(|entry| entry.name() == &name); |
70 | .nth(0); | ||
71 | ret | 70 | ret |
72 | } | 71 | } |
73 | 72 | ||
@@ -84,7 +83,7 @@ impl FnScopes { | |||
84 | }) | 83 | }) |
85 | } | 84 | } |
86 | fn add_bindings(&mut self, body: &Body, scope: ScopeId, pat: PatId) { | 85 | fn add_bindings(&mut self, body: &Body, scope: ScopeId, pat: PatId) { |
87 | match body.pat(pat) { | 86 | match &body[pat] { |
88 | Pat::Bind { name } => self.scopes[scope].entries.push(ScopeEntry { | 87 | Pat::Bind { name } => self.scopes[scope].entries.push(ScopeEntry { |
89 | name: name.clone(), | 88 | name: name.clone(), |
90 | pat, | 89 | pat, |
@@ -96,7 +95,7 @@ impl FnScopes { | |||
96 | let body = Arc::clone(&self.body); | 95 | let body = Arc::clone(&self.body); |
97 | params | 96 | params |
98 | .into_iter() | 97 | .into_iter() |
99 | .for_each(|it| self.add_bindings(&body, scope, *it)); | 98 | .for_each(|pat| self.add_bindings(&body, scope, *pat)); |
100 | } | 99 | } |
101 | fn set_scope(&mut self, node: ExprId, scope: ScopeId) { | 100 | fn set_scope(&mut self, node: ExprId, scope: ScopeId) { |
102 | self.scope_for.insert(node, scope); | 101 | self.scope_for.insert(node, scope); |
@@ -218,8 +217,7 @@ impl ScopesWithSyntaxMapping { | |||
218 | node.ancestors() | 217 | node.ancestors() |
219 | .map(LocalSyntaxPtr::new) | 218 | .map(LocalSyntaxPtr::new) |
220 | .filter_map(|ptr| self.syntax_mapping.syntax_expr(ptr)) | 219 | .filter_map(|ptr| self.syntax_mapping.syntax_expr(ptr)) |
221 | .filter_map(|it| self.scopes.scope_for(it)) | 220 | .find_map(|it| self.scopes.scope_for(it)) |
222 | .next() | ||
223 | } | 221 | } |
224 | } | 222 | } |
225 | 223 | ||
@@ -264,7 +262,7 @@ fn compute_block_scopes( | |||
264 | 262 | ||
265 | fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut FnScopes, scope: ScopeId) { | 263 | fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut FnScopes, scope: ScopeId) { |
266 | scopes.set_scope(expr, scope); | 264 | scopes.set_scope(expr, scope); |
267 | match body.expr(expr) { | 265 | match &body[expr] { |
268 | Expr::Block { statements, tail } => { | 266 | Expr::Block { statements, tail } => { |
269 | compute_block_scopes(&statements, *tail, body, scopes, scope); | 267 | compute_block_scopes(&statements, *tail, body, scopes, scope); |
270 | } | 268 | } |