aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/resolve.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/resolve.rs')
-rw-r--r--crates/ra_hir/src/resolve.rs42
1 files changed, 20 insertions, 22 deletions
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs
index 899959532..770864ec5 100644
--- a/crates/ra_hir/src/resolve.rs
+++ b/crates/ra_hir/src/resolve.rs
@@ -8,8 +8,8 @@ use hir_def::{
8 generics::GenericParams, 8 generics::GenericParams,
9 nameres::CrateDefMap, 9 nameres::CrateDefMap,
10 path::{Path, PathKind}, 10 path::{Path, PathKind},
11 AdtId, CrateModuleId, DefWithBodyId, EnumId, EnumVariantId, GenericDefId, ImplId, ModuleDefId, 11 AdtId, ConstId, CrateModuleId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId,
12 StructId, TraitId, TypeAliasId, 12 ImplId, ModuleDefId, StaticId, StructId, TraitId, TypeAliasId,
13}; 13};
14use hir_expand::name::{self, Name}; 14use hir_expand::name::{self, Name};
15use rustc_hash::FxHashSet; 15use rustc_hash::FxHashSet;
@@ -18,8 +18,8 @@ use crate::{
18 code_model::Crate, 18 code_model::Crate,
19 db::{DefDatabase, HirDatabase}, 19 db::{DefDatabase, HirDatabase},
20 expr::{ExprScopes, PatId, ScopeId}, 20 expr::{ExprScopes, PatId, ScopeId},
21 Adt, Const, Container, DefWithBody, EnumVariant, Function, GenericDef, HasBody, ImplBlock, 21 Adt, Const, Container, DefWithBody, Function, GenericDef, ImplBlock, Local, MacroDef, Module,
22 Local, MacroDef, Module, ModuleDef, PerNs, Static, Struct, Trait, TypeAlias, 22 ModuleDef, PerNs, Static, Trait, TypeAlias,
23}; 23};
24 24
25#[derive(Debug, Clone, Default)] 25#[derive(Debug, Clone, Default)]
@@ -79,11 +79,11 @@ pub(crate) enum ResolveValueResult {
79#[derive(Debug, Clone, PartialEq, Eq, Hash)] 79#[derive(Debug, Clone, PartialEq, Eq, Hash)]
80pub(crate) enum ValueNs { 80pub(crate) enum ValueNs {
81 LocalBinding(PatId), 81 LocalBinding(PatId),
82 Function(Function), 82 FunctionId(FunctionId),
83 Const(Const), 83 ConstId(ConstId),
84 Static(Static), 84 StaticId(StaticId),
85 Struct(Struct), 85 StructId(StructId),
86 EnumVariant(EnumVariant), 86 EnumVariantId(EnumVariantId),
87} 87}
88 88
89impl Resolver { 89impl Resolver {
@@ -266,13 +266,11 @@ impl Resolver {
266 return match idx { 266 return match idx {
267 None => { 267 None => {
268 let value = match module_def.take_values()? { 268 let value = match module_def.take_values()? {
269 ModuleDefId::FunctionId(it) => ValueNs::Function(it.into()), 269 ModuleDefId::FunctionId(it) => ValueNs::FunctionId(it),
270 ModuleDefId::AdtId(AdtId::StructId(it)) => { 270 ModuleDefId::AdtId(AdtId::StructId(it)) => ValueNs::StructId(it),
271 ValueNs::Struct(it.into()) 271 ModuleDefId::EnumVariantId(it) => ValueNs::EnumVariantId(it),
272 } 272 ModuleDefId::ConstId(it) => ValueNs::ConstId(it),
273 ModuleDefId::EnumVariantId(it) => ValueNs::EnumVariant(it.into()), 273 ModuleDefId::StaticId(it) => ValueNs::StaticId(it),
274 ModuleDefId::ConstId(it) => ValueNs::Const(it.into()),
275 ModuleDefId::StaticId(it) => ValueNs::Static(it.into()),
276 274
277 ModuleDefId::AdtId(AdtId::EnumId(_)) 275 ModuleDefId::AdtId(AdtId::EnumId(_))
278 | ModuleDefId::AdtId(AdtId::UnionId(_)) 276 | ModuleDefId::AdtId(AdtId::UnionId(_))
@@ -496,23 +494,23 @@ impl Scope {
496// needs arbitrary_self_types to be a method... or maybe move to the def? 494// needs arbitrary_self_types to be a method... or maybe move to the def?
497pub(crate) fn resolver_for_expr( 495pub(crate) fn resolver_for_expr(
498 db: &impl HirDatabase, 496 db: &impl HirDatabase,
499 owner: DefWithBody, 497 owner: DefWithBodyId,
500 expr_id: ExprId, 498 expr_id: ExprId,
501) -> Resolver { 499) -> Resolver {
502 let scopes = owner.expr_scopes(db); 500 let scopes = db.expr_scopes(owner);
503 resolver_for_scope(db, owner, scopes.scope_for(expr_id)) 501 resolver_for_scope(db, owner, scopes.scope_for(expr_id))
504} 502}
505 503
506pub(crate) fn resolver_for_scope( 504pub(crate) fn resolver_for_scope(
507 db: &impl HirDatabase, 505 db: &impl HirDatabase,
508 owner: DefWithBody, 506 owner: DefWithBodyId,
509 scope_id: Option<ScopeId>, 507 scope_id: Option<ScopeId>,
510) -> Resolver { 508) -> Resolver {
511 let mut r = owner.resolver(db); 509 let mut r = DefWithBody::from(owner).resolver(db);
512 let scopes = owner.expr_scopes(db); 510 let scopes = db.expr_scopes(owner);
513 let scope_chain = scopes.scope_chain(scope_id).collect::<Vec<_>>(); 511 let scope_chain = scopes.scope_chain(scope_id).collect::<Vec<_>>();
514 for scope in scope_chain.into_iter().rev() { 512 for scope in scope_chain.into_iter().rev() {
515 r = r.push_expr_scope(owner.into(), Arc::clone(&scopes), scope); 513 r = r.push_expr_scope(owner, Arc::clone(&scopes), scope);
516 } 514 }
517 r 515 r
518} 516}