diff options
author | Aleksey Kladov <[email protected]> | 2019-11-15 09:00:36 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-15 09:00:36 +0000 |
commit | b80fa14a850db78b1f45de95b0edde1a65da4625 (patch) | |
tree | 84b91fa8d28871a4c5ae5eed947b05b8b5883e86 /crates/ra_hir/src | |
parent | 31d01efb069065449e53cfd7d0935c4b9fecf1e3 (diff) |
Use Local more
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/expr.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/resolve.rs | 17 | ||||
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 8 |
3 files changed, 11 insertions, 16 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 9262325f2..899e0fa04 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -38,7 +38,7 @@ pub(crate) fn resolver_for_scope( | |||
38 | let scopes = owner.expr_scopes(db); | 38 | let scopes = owner.expr_scopes(db); |
39 | let scope_chain = scopes.scope_chain(scope_id).collect::<Vec<_>>(); | 39 | let scope_chain = scopes.scope_chain(scope_id).collect::<Vec<_>>(); |
40 | for scope in scope_chain.into_iter().rev() { | 40 | for scope in scope_chain.into_iter().rev() { |
41 | r = r.push_expr_scope(Arc::clone(&scopes), scope); | 41 | r = r.push_expr_scope(owner, Arc::clone(&scopes), scope); |
42 | } | 42 | } |
43 | r | 43 | r |
44 | } | 44 | } |
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index 2f3e12eb8..b922fe20f 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs | |||
@@ -16,8 +16,8 @@ use crate::{ | |||
16 | expr::{ExprScopes, PatId, ScopeId}, | 16 | expr::{ExprScopes, PatId, ScopeId}, |
17 | generics::GenericParams, | 17 | generics::GenericParams, |
18 | impl_block::ImplBlock, | 18 | impl_block::ImplBlock, |
19 | Adt, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, PerNs, Static, Struct, Trait, | 19 | Adt, Const, DefWithBody, Enum, EnumVariant, Function, Local, MacroDef, ModuleDef, PerNs, |
20 | TypeAlias, | 20 | Static, Struct, Trait, TypeAlias, |
21 | }; | 21 | }; |
22 | 22 | ||
23 | #[derive(Debug, Clone, Default)] | 23 | #[derive(Debug, Clone, Default)] |
@@ -34,6 +34,7 @@ pub(crate) struct ModuleItemMap { | |||
34 | 34 | ||
35 | #[derive(Debug, Clone)] | 35 | #[derive(Debug, Clone)] |
36 | pub(crate) struct ExprScope { | 36 | pub(crate) struct ExprScope { |
37 | owner: DefWithBody, | ||
37 | expr_scopes: Arc<ExprScopes>, | 38 | expr_scopes: Arc<ExprScopes>, |
38 | scope_id: ScopeId, | 39 | scope_id: ScopeId, |
39 | } | 40 | } |
@@ -399,10 +400,11 @@ impl Resolver { | |||
399 | 400 | ||
400 | pub(crate) fn push_expr_scope( | 401 | pub(crate) fn push_expr_scope( |
401 | self, | 402 | self, |
403 | owner: DefWithBody, | ||
402 | expr_scopes: Arc<ExprScopes>, | 404 | expr_scopes: Arc<ExprScopes>, |
403 | scope_id: ScopeId, | 405 | scope_id: ScopeId, |
404 | ) -> Resolver { | 406 | ) -> Resolver { |
405 | self.push_scope(Scope::ExprScope(ExprScope { expr_scopes, scope_id })) | 407 | self.push_scope(Scope::ExprScope(ExprScope { owner, expr_scopes, scope_id })) |
406 | } | 408 | } |
407 | } | 409 | } |
408 | 410 | ||
@@ -413,7 +415,7 @@ pub enum ScopeDef { | |||
413 | GenericParam(u32), | 415 | GenericParam(u32), |
414 | ImplSelfType(ImplBlock), | 416 | ImplSelfType(ImplBlock), |
415 | AdtSelfType(Adt), | 417 | AdtSelfType(Adt), |
416 | LocalBinding(PatId), | 418 | Local(Local), |
417 | Unknown, | 419 | Unknown, |
418 | } | 420 | } |
419 | 421 | ||
@@ -467,9 +469,10 @@ impl Scope { | |||
467 | Scope::AdtScope(i) => { | 469 | Scope::AdtScope(i) => { |
468 | f(name::SELF_TYPE, ScopeDef::AdtSelfType(*i)); | 470 | f(name::SELF_TYPE, ScopeDef::AdtSelfType(*i)); |
469 | } | 471 | } |
470 | Scope::ExprScope(e) => { | 472 | Scope::ExprScope(scope) => { |
471 | e.expr_scopes.entries(e.scope_id).iter().for_each(|e| { | 473 | scope.expr_scopes.entries(scope.scope_id).iter().for_each(|e| { |
472 | f(e.name().clone(), ScopeDef::LocalBinding(e.pat())); | 474 | let local = Local { parent: scope.owner, pat_id: e.pat() }; |
475 | f(e.name().clone(), ScopeDef::Local(local)); | ||
473 | }); | 476 | }); |
474 | } | 477 | } |
475 | } | 478 | } |
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index ca40e3b54..59046edcc 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -195,14 +195,6 @@ impl SourceAnalyzer { | |||
195 | Some(self.infer.as_ref()?[pat_id].clone()) | 195 | Some(self.infer.as_ref()?[pat_id].clone()) |
196 | } | 196 | } |
197 | 197 | ||
198 | pub fn type_of_pat_by_id( | ||
199 | &self, | ||
200 | _db: &impl HirDatabase, | ||
201 | pat_id: expr::PatId, | ||
202 | ) -> Option<crate::Ty> { | ||
203 | Some(self.infer.as_ref()?[pat_id].clone()) | ||
204 | } | ||
205 | |||
206 | pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> { | 198 | pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> { |
207 | let expr_id = self.expr_id(&call.clone().into())?; | 199 | let expr_id = self.expr_id(&call.clone().into())?; |
208 | self.infer.as_ref()?.method_resolution(expr_id) | 200 | self.infer.as_ref()?.method_resolution(expr_id) |