make resolver private

This commit is contained in:
Aleksey Kladov 2019-04-13 11:02:23 +03:00
parent 62d01dd4df
commit a2cc76ce63
6 changed files with 23 additions and 26 deletions

View File

@ -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)

View File

@ -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<Body>, db: &impl HirDatabase, expr_id: ExprId) -> Resolver {
pub(crate) fn resolver_for_expr(
body: Arc<Body>,
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<Body>,
db: &impl HirDatabase,
scope_id: Option<scope::ScopeId>,

View File

@ -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);

View File

@ -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},
};

View File

@ -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<Scope>,
}
@ -117,7 +117,7 @@ pub enum Resolution {
}
impl Resolver {
pub fn resolve_name(&self, db: &impl HirDatabase, name: &Name) -> PerNs<Resolution> {
pub(crate) fn resolve_name(&self, db: &impl HirDatabase, name: &Name) -> PerNs<Resolution> {
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<Resolution> {
pub(crate) fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs<Resolution> {
// 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<Name, PerNs<Resolution>> {
pub(crate) fn all_names(&self, db: &impl HirDatabase) -> FxHashMap<Name, PerNs<Resolution>> {
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<Arc<Body>> {
self.scopes.iter().rev().find_map(|scope| match scope {
Scope::ExprScope(expr_scope) => Some(expr_scope.expr_scopes.body()),
_ => None,
})
}
}
impl Resolver {

View File

@ -135,7 +135,7 @@ fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Option<Crate> {
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,