diff options
Diffstat (limited to 'crates/ra_hir/src/resolve.rs')
-rw-r--r-- | crates/ra_hir/src/resolve.rs | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index f4165babd..899959532 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs | |||
@@ -4,6 +4,7 @@ use std::sync::Arc; | |||
4 | use hir_def::{ | 4 | use hir_def::{ |
5 | builtin_type::BuiltinType, | 5 | builtin_type::BuiltinType, |
6 | db::DefDatabase2, | 6 | db::DefDatabase2, |
7 | expr::ExprId, | ||
7 | generics::GenericParams, | 8 | generics::GenericParams, |
8 | nameres::CrateDefMap, | 9 | nameres::CrateDefMap, |
9 | path::{Path, PathKind}, | 10 | path::{Path, PathKind}, |
@@ -15,10 +16,10 @@ use rustc_hash::FxHashSet; | |||
15 | 16 | ||
16 | use crate::{ | 17 | use crate::{ |
17 | code_model::Crate, | 18 | code_model::Crate, |
18 | db::DefDatabase, | 19 | db::{DefDatabase, HirDatabase}, |
19 | expr::{ExprScopes, PatId, ScopeId}, | 20 | expr::{ExprScopes, PatId, ScopeId}, |
20 | Adt, Const, Container, DefWithBody, EnumVariant, Function, GenericDef, ImplBlock, Local, | 21 | Adt, Const, Container, DefWithBody, EnumVariant, Function, GenericDef, HasBody, ImplBlock, |
21 | MacroDef, Module, ModuleDef, PerNs, Static, Struct, Trait, TypeAlias, | 22 | Local, MacroDef, Module, ModuleDef, PerNs, Static, Struct, Trait, TypeAlias, |
22 | }; | 23 | }; |
23 | 24 | ||
24 | #[derive(Debug, Clone, Default)] | 25 | #[derive(Debug, Clone, Default)] |
@@ -492,6 +493,30 @@ impl Scope { | |||
492 | } | 493 | } |
493 | } | 494 | } |
494 | 495 | ||
496 | // needs arbitrary_self_types to be a method... or maybe move to the def? | ||
497 | pub(crate) fn resolver_for_expr( | ||
498 | db: &impl HirDatabase, | ||
499 | owner: DefWithBody, | ||
500 | expr_id: ExprId, | ||
501 | ) -> Resolver { | ||
502 | let scopes = owner.expr_scopes(db); | ||
503 | resolver_for_scope(db, owner, scopes.scope_for(expr_id)) | ||
504 | } | ||
505 | |||
506 | pub(crate) fn resolver_for_scope( | ||
507 | db: &impl HirDatabase, | ||
508 | owner: DefWithBody, | ||
509 | scope_id: Option<ScopeId>, | ||
510 | ) -> Resolver { | ||
511 | let mut r = owner.resolver(db); | ||
512 | let scopes = owner.expr_scopes(db); | ||
513 | let scope_chain = scopes.scope_chain(scope_id).collect::<Vec<_>>(); | ||
514 | for scope in scope_chain.into_iter().rev() { | ||
515 | r = r.push_expr_scope(owner.into(), Arc::clone(&scopes), scope); | ||
516 | } | ||
517 | r | ||
518 | } | ||
519 | |||
495 | pub(crate) trait HasResolver { | 520 | pub(crate) trait HasResolver { |
496 | /// Builds a resolver for type references inside this def. | 521 | /// Builds a resolver for type references inside this def. |
497 | fn resolver(self, db: &impl DefDatabase) -> Resolver; | 522 | fn resolver(self, db: &impl DefDatabase) -> Resolver; |