From a2cc76ce63c3449d33d4a2261392e452df1d31b1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 13 Apr 2019 11:02:23 +0300 Subject: make resolver private --- crates/ra_hir/src/code_model_api.rs | 16 ++++++++-------- crates/ra_hir/src/expr.rs | 8 ++++++-- crates/ra_hir/src/impl_block.rs | 2 +- crates/ra_hir/src/lib.rs | 3 ++- crates/ra_hir/src/resolve.rs | 18 +++++------------- crates/ra_hir/src/ty/method_resolution.rs | 2 +- 6 files changed, 23 insertions(+), 26 deletions(-) (limited to 'crates') 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 { } } - pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { + pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { let def_map = db.crate_def_map(self.krate); Resolver::default().push_module_scope(def_map, self.module_id) } @@ -313,7 +313,7 @@ impl Struct { // FIXME move to a more general type /// Builds a resolver for type references inside this struct. - pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { + pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { // take the outer scope... let r = self.module(db).resolver(db); // ...and add generic params, if present @@ -373,7 +373,7 @@ impl Enum { // FIXME: move to a more general type /// Builds a resolver for type references inside this struct. - pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { + pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { // take the outer scope... let r = self.module(db).resolver(db); // ...and add generic params, if present @@ -459,7 +459,7 @@ impl DefWithBody { } /// Builds a resolver for code inside this item. - pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { + pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { match *self { DefWithBody::Const(ref c) => c.resolver(db), DefWithBody::Function(ref f) => f.resolver(db), @@ -549,7 +549,7 @@ impl Function { // FIXME: move to a more general type for 'body-having' items /// Builds a resolver for code inside this item. - pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { + pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { // take the outer scope... let r = self .impl_block(db) @@ -602,7 +602,7 @@ impl Const { // FIXME: move to a more general type for 'body-having' items /// Builds a resolver for code inside this item. - pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { + pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { // take the outer scope... let r = self .impl_block(db) @@ -654,7 +654,7 @@ impl Static { } /// Builds a resolver for code inside this item. - pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { + pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { // take the outer scope... self.module(db).resolver(db) } @@ -736,7 +736,7 @@ impl TypeAlias { } /// Builds a resolver for the type references in this type alias. - pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { + pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { // take the outer scope... let r = self .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 { } // needs arbitrary_self_types to be a method... or maybe move to the def? -pub fn resolver_for_expr(body: Arc, db: &impl HirDatabase, expr_id: ExprId) -> Resolver { +pub(crate) fn resolver_for_expr( + body: Arc, + db: &impl HirDatabase, + expr_id: ExprId, +) -> Resolver { let scopes = db.expr_scopes(body.owner); resolver_for_scope(body, db, scopes.scope_for(expr_id)) } -pub fn resolver_for_scope( +pub(crate) fn resolver_for_scope( body: Arc, db: &impl HirDatabase, scope_id: Option, 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 { db.generic_params((*self).into()) } - pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { + pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { let r = self.module().resolver(db); // add generic params, if present 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::{ db::{HirDatabase, DefDatabase}, name::{AsName, KnownName}, source_id::{FileAstId, AstId}, + resolve::Resolver, }; pub use self::{ @@ -65,7 +66,7 @@ pub use self::{ docs::{Docs, Documentation}, adt::AdtDef, expr::{ExprScopes, ScopeEntryWithSyntax}, - resolve::{Resolver, Resolution}, + resolve::Resolution, source_binder::{SourceAnalyzer, PathResolution}, }; 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::{ name::{Name, KnownName}, nameres::{PerNs, CrateDefMap, CrateModuleId}, generics::GenericParams, - expr::{scope::{ExprScopes, ScopeId}, PatId, Body}, + expr::{scope::{ExprScopes, ScopeId}, PatId}, impl_block::ImplBlock, path::Path, Trait }; #[derive(Debug, Clone, Default)] -pub struct Resolver { +pub(crate) struct Resolver { scopes: Vec, } @@ -117,7 +117,7 @@ pub enum Resolution { } impl Resolver { - pub fn resolve_name(&self, db: &impl HirDatabase, name: &Name) -> PerNs { + pub(crate) fn resolve_name(&self, db: &impl HirDatabase, name: &Name) -> PerNs { let mut resolution = PerNs::none(); for scope in self.scopes.iter().rev() { resolution = resolution.or(scope.resolve_name(db, name)); @@ -154,12 +154,12 @@ impl Resolver { /// Returns the fully resolved path if we were able to resolve it. /// otherwise returns `PerNs::none` - pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs { + pub(crate) fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs { // into_fully_resolved() returns the fully resolved path or PerNs::none() otherwise self.resolve_path_segments(db, path).into_fully_resolved() } - pub fn all_names(&self, db: &impl HirDatabase) -> FxHashMap> { + pub(crate) fn all_names(&self, db: &impl HirDatabase) -> FxHashMap> { let mut names = FxHashMap::default(); for scope in self.scopes.iter().rev() { scope.collect_names(db, &mut |name, res| { @@ -197,14 +197,6 @@ impl Resolver { _ => None, }) } - - /// The body from which any `LocalBinding` resolutions in this resolver come. - pub fn body(&self) -> Option> { - self.scopes.iter().rev().find_map(|scope| match scope { - Scope::ExprScope(expr_scope) => Some(expr_scope.expr_scopes.body()), - _ => None, - }) - } } impl 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 { impl Ty { /// Look up the method with the given name, returning the actual autoderefed /// receiver type (but without autoref applied yet). - pub fn lookup_method( + pub(crate) fn lookup_method( self, db: &impl HirDatabase, name: &Name, -- cgit v1.2.3