aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/code_model_api.rs16
-rw-r--r--crates/ra_hir/src/expr.rs8
-rw-r--r--crates/ra_hir/src/impl_block.rs2
-rw-r--r--crates/ra_hir/src/lib.rs3
-rw-r--r--crates/ra_hir/src/resolve.rs18
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs2
6 files changed, 23 insertions, 26 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 882208ec1..5d8cf57b6 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -189,7 +189,7 @@ impl Module {
189 } 189 }
190 } 190 }
191 191
192 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { 192 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
193 let def_map = db.crate_def_map(self.krate); 193 let def_map = db.crate_def_map(self.krate);
194 Resolver::default().push_module_scope(def_map, self.module_id) 194 Resolver::default().push_module_scope(def_map, self.module_id)
195 } 195 }
@@ -313,7 +313,7 @@ impl Struct {
313 313
314 // FIXME move to a more general type 314 // FIXME move to a more general type
315 /// Builds a resolver for type references inside this struct. 315 /// Builds a resolver for type references inside this struct.
316 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { 316 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
317 // take the outer scope... 317 // take the outer scope...
318 let r = self.module(db).resolver(db); 318 let r = self.module(db).resolver(db);
319 // ...and add generic params, if present 319 // ...and add generic params, if present
@@ -373,7 +373,7 @@ impl Enum {
373 373
374 // FIXME: move to a more general type 374 // FIXME: move to a more general type
375 /// Builds a resolver for type references inside this struct. 375 /// Builds a resolver for type references inside this struct.
376 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { 376 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
377 // take the outer scope... 377 // take the outer scope...
378 let r = self.module(db).resolver(db); 378 let r = self.module(db).resolver(db);
379 // ...and add generic params, if present 379 // ...and add generic params, if present
@@ -459,7 +459,7 @@ impl DefWithBody {
459 } 459 }
460 460
461 /// Builds a resolver for code inside this item. 461 /// Builds a resolver for code inside this item.
462 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { 462 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
463 match *self { 463 match *self {
464 DefWithBody::Const(ref c) => c.resolver(db), 464 DefWithBody::Const(ref c) => c.resolver(db),
465 DefWithBody::Function(ref f) => f.resolver(db), 465 DefWithBody::Function(ref f) => f.resolver(db),
@@ -549,7 +549,7 @@ impl Function {
549 549
550 // FIXME: move to a more general type for 'body-having' items 550 // FIXME: move to a more general type for 'body-having' items
551 /// Builds a resolver for code inside this item. 551 /// Builds a resolver for code inside this item.
552 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { 552 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
553 // take the outer scope... 553 // take the outer scope...
554 let r = self 554 let r = self
555 .impl_block(db) 555 .impl_block(db)
@@ -602,7 +602,7 @@ impl Const {
602 602
603 // FIXME: move to a more general type for 'body-having' items 603 // FIXME: move to a more general type for 'body-having' items
604 /// Builds a resolver for code inside this item. 604 /// Builds a resolver for code inside this item.
605 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { 605 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
606 // take the outer scope... 606 // take the outer scope...
607 let r = self 607 let r = self
608 .impl_block(db) 608 .impl_block(db)
@@ -654,7 +654,7 @@ impl Static {
654 } 654 }
655 655
656 /// Builds a resolver for code inside this item. 656 /// Builds a resolver for code inside this item.
657 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { 657 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
658 // take the outer scope... 658 // take the outer scope...
659 self.module(db).resolver(db) 659 self.module(db).resolver(db)
660 } 660 }
@@ -736,7 +736,7 @@ impl TypeAlias {
736 } 736 }
737 737
738 /// Builds a resolver for the type references in this type alias. 738 /// Builds a resolver for the type references in this type alias.
739 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { 739 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
740 // take the outer scope... 740 // take the outer scope...
741 let r = self 741 let r = self
742 .impl_block(db) 742 .impl_block(db)
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index 038a25a97..239874792 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -81,12 +81,16 @@ impl Body {
81} 81}
82 82
83// needs arbitrary_self_types to be a method... or maybe move to the def? 83// needs arbitrary_self_types to be a method... or maybe move to the def?
84pub fn resolver_for_expr(body: Arc<Body>, db: &impl HirDatabase, expr_id: ExprId) -> Resolver { 84pub(crate) fn resolver_for_expr(
85 body: Arc<Body>,
86 db: &impl HirDatabase,
87 expr_id: ExprId,
88) -> Resolver {
85 let scopes = db.expr_scopes(body.owner); 89 let scopes = db.expr_scopes(body.owner);
86 resolver_for_scope(body, db, scopes.scope_for(expr_id)) 90 resolver_for_scope(body, db, scopes.scope_for(expr_id))
87} 91}
88 92
89pub fn resolver_for_scope( 93pub(crate) fn resolver_for_scope(
90 body: Arc<Body>, 94 body: Arc<Body>,
91 db: &impl HirDatabase, 95 db: &impl HirDatabase,
92 scope_id: Option<scope::ScopeId>, 96 scope_id: Option<scope::ScopeId>,
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index 40d368cd9..b306874cc 100644
--- a/crates/ra_hir/src/impl_block.rs
+++ b/crates/ra_hir/src/impl_block.rs
@@ -105,7 +105,7 @@ impl ImplBlock {
105 db.generic_params((*self).into()) 105 db.generic_params((*self).into())
106 } 106 }
107 107
108 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { 108 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
109 let r = self.module().resolver(db); 109 let r = self.module().resolver(db);
110 // add generic params, if present 110 // add generic params, if present
111 let p = self.generic_params(db); 111 let p = self.generic_params(db);
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index eb2aa0e6c..5eb2f32bd 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -51,6 +51,7 @@ use crate::{
51 db::{HirDatabase, DefDatabase}, 51 db::{HirDatabase, DefDatabase},
52 name::{AsName, KnownName}, 52 name::{AsName, KnownName},
53 source_id::{FileAstId, AstId}, 53 source_id::{FileAstId, AstId},
54 resolve::Resolver,
54}; 55};
55 56
56pub use self::{ 57pub use self::{
@@ -65,7 +66,7 @@ pub use self::{
65 docs::{Docs, Documentation}, 66 docs::{Docs, Documentation},
66 adt::AdtDef, 67 adt::AdtDef,
67 expr::{ExprScopes, ScopeEntryWithSyntax}, 68 expr::{ExprScopes, ScopeEntryWithSyntax},
68 resolve::{Resolver, Resolution}, 69 resolve::Resolution,
69 source_binder::{SourceAnalyzer, PathResolution}, 70 source_binder::{SourceAnalyzer, PathResolution},
70}; 71};
71 72
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs
index 2609585b1..685f4b8b1 100644
--- a/crates/ra_hir/src/resolve.rs
+++ b/crates/ra_hir/src/resolve.rs
@@ -9,13 +9,13 @@ use crate::{
9 name::{Name, KnownName}, 9 name::{Name, KnownName},
10 nameres::{PerNs, CrateDefMap, CrateModuleId}, 10 nameres::{PerNs, CrateDefMap, CrateModuleId},
11 generics::GenericParams, 11 generics::GenericParams,
12 expr::{scope::{ExprScopes, ScopeId}, PatId, Body}, 12 expr::{scope::{ExprScopes, ScopeId}, PatId},
13 impl_block::ImplBlock, 13 impl_block::ImplBlock,
14 path::Path, Trait 14 path::Path, Trait
15}; 15};
16 16
17#[derive(Debug, Clone, Default)] 17#[derive(Debug, Clone, Default)]
18pub struct Resolver { 18pub(crate) struct Resolver {
19 scopes: Vec<Scope>, 19 scopes: Vec<Scope>,
20} 20}
21 21
@@ -117,7 +117,7 @@ pub enum Resolution {
117} 117}
118 118
119impl Resolver { 119impl Resolver {
120 pub fn resolve_name(&self, db: &impl HirDatabase, name: &Name) -> PerNs<Resolution> { 120 pub(crate) fn resolve_name(&self, db: &impl HirDatabase, name: &Name) -> PerNs<Resolution> {
121 let mut resolution = PerNs::none(); 121 let mut resolution = PerNs::none();
122 for scope in self.scopes.iter().rev() { 122 for scope in self.scopes.iter().rev() {
123 resolution = resolution.or(scope.resolve_name(db, name)); 123 resolution = resolution.or(scope.resolve_name(db, name));
@@ -154,12 +154,12 @@ impl Resolver {
154 154
155 /// Returns the fully resolved path if we were able to resolve it. 155 /// Returns the fully resolved path if we were able to resolve it.
156 /// otherwise returns `PerNs::none` 156 /// otherwise returns `PerNs::none`
157 pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs<Resolution> { 157 pub(crate) fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs<Resolution> {
158 // into_fully_resolved() returns the fully resolved path or PerNs::none() otherwise 158 // into_fully_resolved() returns the fully resolved path or PerNs::none() otherwise
159 self.resolve_path_segments(db, path).into_fully_resolved() 159 self.resolve_path_segments(db, path).into_fully_resolved()
160 } 160 }
161 161
162 pub fn all_names(&self, db: &impl HirDatabase) -> FxHashMap<Name, PerNs<Resolution>> { 162 pub(crate) fn all_names(&self, db: &impl HirDatabase) -> FxHashMap<Name, PerNs<Resolution>> {
163 let mut names = FxHashMap::default(); 163 let mut names = FxHashMap::default();
164 for scope in self.scopes.iter().rev() { 164 for scope in self.scopes.iter().rev() {
165 scope.collect_names(db, &mut |name, res| { 165 scope.collect_names(db, &mut |name, res| {
@@ -197,14 +197,6 @@ impl Resolver {
197 _ => None, 197 _ => None,
198 }) 198 })
199 } 199 }
200
201 /// The body from which any `LocalBinding` resolutions in this resolver come.
202 pub fn body(&self) -> Option<Arc<Body>> {
203 self.scopes.iter().rev().find_map(|scope| match scope {
204 Scope::ExprScope(expr_scope) => Some(expr_scope.expr_scopes.body()),
205 _ => None,
206 })
207 }
208} 200}
209 201
210impl Resolver { 202impl Resolver {
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index 3ac8dc46b..bb23246a6 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -135,7 +135,7 @@ fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Option<Crate> {
135impl Ty { 135impl Ty {
136 /// Look up the method with the given name, returning the actual autoderefed 136 /// Look up the method with the given name, returning the actual autoderefed
137 /// receiver type (but without autoref applied yet). 137 /// receiver type (but without autoref applied yet).
138 pub fn lookup_method( 138 pub(crate) fn lookup_method(
139 self, 139 self,
140 db: &impl HirDatabase, 140 db: &impl HirDatabase,
141 name: &Name, 141 name: &Name,