aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-21 12:39:09 +0000
committerAleksey Kladov <[email protected]>2019-11-21 12:39:09 +0000
commit6d64798a2300858c74b1cc0a22f6d3df578288b3 (patch)
treecd22f6a6a743bf15dc671995c49904477b249604
parent00684d708b64fe81a0264795f27594d450a8d08d (diff)
Move resolver to hir_def
-rw-r--r--crates/ra_hir/src/code_model.rs2
-rw-r--r--crates/ra_hir/src/expr.rs3
-rw-r--r--crates/ra_hir/src/impl_block.rs5
-rw-r--r--crates/ra_hir/src/lib.rs3
-rw-r--r--crates/ra_hir/src/source_binder.rs16
-rw-r--r--crates/ra_hir/src/ty/autoderef.rs3
-rw-r--r--crates/ra_hir/src/ty/infer.rs2
-rw-r--r--crates/ra_hir/src/ty/infer/coerce.rs6
-rw-r--r--crates/ra_hir/src/ty/infer/expr.rs5
-rw-r--r--crates/ra_hir/src/ty/infer/path.rs9
-rw-r--r--crates/ra_hir/src/ty/lower.rs2
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs2
-rw-r--r--crates/ra_hir_def/src/lib.rs1
-rw-r--r--crates/ra_hir_def/src/resolver.rs (renamed from crates/ra_hir/src/resolve.rs)81
14 files changed, 63 insertions, 77 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 3c891547e..92860fb59 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -11,6 +11,7 @@ use hir_def::{
11 body::scope::ExprScopes, 11 body::scope::ExprScopes,
12 builtin_type::BuiltinType, 12 builtin_type::BuiltinType,
13 nameres::per_ns::PerNs, 13 nameres::per_ns::PerNs,
14 resolver::{HasResolver, TypeNs},
14 traits::TraitData, 15 traits::TraitData,
15 type_ref::{Mutability, TypeRef}, 16 type_ref::{Mutability, TypeRef},
16 ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalStructFieldId, Lookup, 17 ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalStructFieldId, Lookup,
@@ -31,7 +32,6 @@ use crate::{
31 AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, 32 AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId,
32 TypeAliasId, 33 TypeAliasId,
33 }, 34 },
34 resolve::{HasResolver, TypeNs},
35 ty::{InferenceResult, Namespace, TraitRef}, 35 ty::{InferenceResult, Namespace, TraitRef},
36 Either, HasSource, ImportId, Name, Source, Ty, 36 Either, HasSource, ImportId, Name, Source, Ty,
37}; 37};
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index 9cdc0c645..6b703d8b4 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -2,7 +2,7 @@
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use hir_def::path::known; 5use hir_def::{path::known, resolver::HasResolver};
6use hir_expand::diagnostics::DiagnosticSink; 6use hir_expand::diagnostics::DiagnosticSink;
7use ra_syntax::ast; 7use ra_syntax::ast;
8use ra_syntax::AstPtr; 8use ra_syntax::AstPtr;
@@ -11,7 +11,6 @@ use rustc_hash::FxHashSet;
11use crate::{ 11use crate::{
12 db::HirDatabase, 12 db::HirDatabase,
13 diagnostics::{MissingFields, MissingOkInTailExpr}, 13 diagnostics::{MissingFields, MissingOkInTailExpr},
14 resolve::HasResolver,
15 ty::{ApplicationTy, InferenceResult, Ty, TypeCtor}, 14 ty::{ApplicationTy, InferenceResult, Ty, TypeCtor},
16 Adt, Function, Name, Path, 15 Adt, Function, Name, Path,
17}; 16};
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index c84ceee62..774fa1d96 100644
--- a/crates/ra_hir/src/impl_block.rs
+++ b/crates/ra_hir/src/impl_block.rs
@@ -1,11 +1,10 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir_def::{type_ref::TypeRef, AstItemDef}; 3use hir_def::{resolver::HasResolver, type_ref::TypeRef, AstItemDef};
4use ra_syntax::ast::{self}; 4use ra_syntax::ast;
5 5
6use crate::{ 6use crate::{
7 db::{AstDatabase, DefDatabase, HirDatabase}, 7 db::{AstDatabase, DefDatabase, HirDatabase},
8 resolve::HasResolver,
9 ty::Ty, 8 ty::Ty,
10 AssocItem, Crate, HasSource, ImplBlock, Module, Source, TraitRef, 9 AssocItem, Crate, HasSource, ImplBlock, Module, Source, TraitRef,
11}; 10};
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 095d4964f..76c96bdcf 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -38,7 +38,6 @@ mod impl_block;
38mod expr; 38mod expr;
39mod lang_item; 39mod lang_item;
40pub mod generics; 40pub mod generics;
41mod resolve;
42pub mod diagnostics; 41pub mod diagnostics;
43mod util; 42mod util;
44 43
@@ -52,8 +51,6 @@ mod test_db;
52#[cfg(test)] 51#[cfg(test)]
53mod marks; 52mod marks;
54 53
55use crate::resolve::Resolver;
56
57pub use crate::{ 54pub use crate::{
58 code_model::{ 55 code_model::{
59 attrs::{AttrDef, Attrs}, 56 attrs::{AttrDef, Attrs},
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 898b823c0..c42ceabdf 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -10,6 +10,7 @@ use std::sync::Arc;
10use hir_def::{ 10use hir_def::{
11 expr::{ExprId, PatId}, 11 expr::{ExprId, PatId},
12 path::known, 12 path::known,
13 resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs},
13 DefWithBodyId, 14 DefWithBodyId,
14}; 15};
15use hir_expand::{name::AsName, AstId, MacroCallId, MacroCallLoc, MacroFileKind, Source}; 16use hir_expand::{name::AsName, AstId, MacroCallId, MacroCallLoc, MacroFileKind, Source};
@@ -24,11 +25,10 @@ use crate::{
24 db::HirDatabase, 25 db::HirDatabase,
25 expr::{BodySourceMap, ExprScopes, ScopeId}, 26 expr::{BodySourceMap, ExprScopes, ScopeId},
26 ids::LocationCtx, 27 ids::LocationCtx,
27 resolve::{self, resolver_for_scope, HasResolver, TypeNs, ValueNs},
28 ty::method_resolution::{self, implements_trait}, 28 ty::method_resolution::{self, implements_trait},
29 Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function, 29 Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function,
30 GenericParam, HasBody, HirFileId, Local, MacroDef, Module, Name, Path, Resolver, ScopeDef, 30 GenericParam, HasBody, HirFileId, Local, MacroDef, Module, Name, Path, ScopeDef, Static,
31 Static, Struct, Trait, Ty, TypeAlias, 31 Struct, Trait, Ty, TypeAlias,
32}; 32};
33 33
34fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> { 34fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> {
@@ -317,14 +317,14 @@ impl SourceAnalyzer {
317 pub fn process_all_names(&self, db: &impl HirDatabase, f: &mut dyn FnMut(Name, ScopeDef)) { 317 pub fn process_all_names(&self, db: &impl HirDatabase, f: &mut dyn FnMut(Name, ScopeDef)) {
318 self.resolver.process_all_names(db, &mut |name, def| { 318 self.resolver.process_all_names(db, &mut |name, def| {
319 let def = match def { 319 let def = match def {
320 resolve::ScopeDef::PerNs(it) => it.into(), 320 resolver::ScopeDef::PerNs(it) => it.into(),
321 resolve::ScopeDef::ImplSelfType(it) => ScopeDef::ImplSelfType(it.into()), 321 resolver::ScopeDef::ImplSelfType(it) => ScopeDef::ImplSelfType(it.into()),
322 resolve::ScopeDef::AdtSelfType(it) => ScopeDef::AdtSelfType(it.into()), 322 resolver::ScopeDef::AdtSelfType(it) => ScopeDef::AdtSelfType(it.into()),
323 resolve::ScopeDef::GenericParam(idx) => { 323 resolver::ScopeDef::GenericParam(idx) => {
324 let parent = self.resolver.generic_def().unwrap().into(); 324 let parent = self.resolver.generic_def().unwrap().into();
325 ScopeDef::GenericParam(GenericParam { parent, idx }) 325 ScopeDef::GenericParam(GenericParam { parent, idx })
326 } 326 }
327 resolve::ScopeDef::Local(pat_id) => { 327 resolver::ScopeDef::Local(pat_id) => {
328 let parent = self.resolver.body_owner().unwrap().into(); 328 let parent = self.resolver.body_owner().unwrap().into();
329 ScopeDef::Local(Local { parent, pat_id }) 329 ScopeDef::Local(Local { parent, pat_id })
330 } 330 }
diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs
index f77492170..5d8518041 100644
--- a/crates/ra_hir/src/ty/autoderef.rs
+++ b/crates/ra_hir/src/ty/autoderef.rs
@@ -5,11 +5,12 @@
5 5
6use std::iter::successors; 6use std::iter::successors;
7 7
8use hir_def::resolver::Resolver;
8use hir_expand::name; 9use hir_expand::name;
9use log::{info, warn}; 10use log::{info, warn};
10 11
11use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk}; 12use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk};
12use crate::{db::HirDatabase, generics::HasGenericParams, Resolver}; 13use crate::{db::HirDatabase, generics::HasGenericParams};
13 14
14const AUTODEREF_RECURSION_LIMIT: usize = 10; 15const AUTODEREF_RECURSION_LIMIT: usize = 10;
15 16
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index c3d65afa6..69b13baef 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -23,6 +23,7 @@ use rustc_hash::FxHashMap;
23 23
24use hir_def::{ 24use hir_def::{
25 path::known, 25 path::known,
26 resolver::{HasResolver, Resolver, TypeNs},
26 type_ref::{Mutability, TypeRef}, 27 type_ref::{Mutability, TypeRef},
27 AdtId, DefWithBodyId, 28 AdtId, DefWithBodyId,
28}; 29};
@@ -41,7 +42,6 @@ use crate::{
41 code_model::TypeAlias, 42 code_model::TypeAlias,
42 db::HirDatabase, 43 db::HirDatabase,
43 expr::{BindingAnnotation, Body, ExprId, PatId}, 44 expr::{BindingAnnotation, Body, ExprId, PatId},
44 resolve::{HasResolver, Resolver, TypeNs},
45 ty::infer::diagnostics::InferenceDiagnostic, 45 ty::infer::diagnostics::InferenceDiagnostic,
46 Adt, AssocItem, ConstData, DefWithBody, FloatTy, FnData, Function, HasBody, IntTy, Path, 46 Adt, AssocItem, ConstData, DefWithBody, FloatTy, FnData, Function, HasBody, IntTy, Path,
47 StructField, Trait, VariantDef, 47 StructField, Trait, VariantDef,
diff --git a/crates/ra_hir/src/ty/infer/coerce.rs b/crates/ra_hir/src/ty/infer/coerce.rs
index 6d297c268..0772b9df5 100644
--- a/crates/ra_hir/src/ty/infer/coerce.rs
+++ b/crates/ra_hir/src/ty/infer/coerce.rs
@@ -4,19 +4,19 @@
4//! 4//!
5//! See: https://doc.rust-lang.org/nomicon/coercions.html 5//! See: https://doc.rust-lang.org/nomicon/coercions.html
6 6
7use hir_def::resolver::Resolver;
7use rustc_hash::FxHashMap; 8use rustc_hash::FxHashMap;
8
9use test_utils::tested_by; 9use test_utils::tested_by;
10 10
11use super::{InferTy, InferenceContext, TypeVarValue};
12use crate::{ 11use crate::{
13 db::HirDatabase, 12 db::HirDatabase,
14 lang_item::LangItemTarget, 13 lang_item::LangItemTarget,
15 resolve::Resolver,
16 ty::{autoderef, Substs, Ty, TypeCtor, TypeWalk}, 14 ty::{autoderef, Substs, Ty, TypeCtor, TypeWalk},
17 Adt, Mutability, 15 Adt, Mutability,
18}; 16};
19 17
18use super::{InferTy, InferenceContext, TypeVarValue};
19
20impl<'a, D: HirDatabase> InferenceContext<'a, D> { 20impl<'a, D: HirDatabase> InferenceContext<'a, D> {
21 /// Unify two types, but may coerce the first one to the second one 21 /// Unify two types, but may coerce the first one to the second one
22 /// using "implicit coercion rules" if needed. 22 /// using "implicit coercion rules" if needed.
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs
index 1ac2709f5..ac570075f 100644
--- a/crates/ra_hir/src/ty/infer/expr.rs
+++ b/crates/ra_hir/src/ty/infer/expr.rs
@@ -6,15 +6,14 @@ use std::sync::Arc;
6use hir_def::{ 6use hir_def::{
7 builtin_type::Signedness, 7 builtin_type::Signedness,
8 path::{GenericArg, GenericArgs}, 8 path::{GenericArg, GenericArgs},
9 resolver::resolver_for_expr,
9}; 10};
10use hir_expand::name; 11use hir_expand::name;
11 12
12use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch};
13use crate::{ 13use crate::{
14 db::HirDatabase, 14 db::HirDatabase,
15 expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, 15 expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp},
16 generics::{GenericParams, HasGenericParams}, 16 generics::{GenericParams, HasGenericParams},
17 resolve::resolver_for_expr,
18 ty::{ 17 ty::{
19 autoderef, method_resolution, op, CallableDef, InferTy, IntTy, Mutability, Namespace, 18 autoderef, method_resolution, op, CallableDef, InferTy, IntTy, Mutability, Namespace,
20 Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, 19 Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk,
@@ -23,6 +22,8 @@ use crate::{
23 Adt, Name, 22 Adt, Name,
24}; 23};
25 24
25use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch};
26
26impl<'a, D: HirDatabase> InferenceContext<'a, D> { 27impl<'a, D: HirDatabase> InferenceContext<'a, D> {
27 pub(super) fn infer_expr(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty { 28 pub(super) fn infer_expr(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty {
28 let ty = self.infer_expr_inner(tgt_expr, expected); 29 let ty = self.infer_expr_inner(tgt_expr, expected);
diff --git a/crates/ra_hir/src/ty/infer/path.rs b/crates/ra_hir/src/ty/infer/path.rs
index 55a5dbec7..70136e514 100644
--- a/crates/ra_hir/src/ty/infer/path.rs
+++ b/crates/ra_hir/src/ty/infer/path.rs
@@ -1,16 +1,19 @@
1//! Path expression resolution. 1//! Path expression resolution.
2 2
3use hir_def::path::PathSegment; 3use hir_def::{
4 path::PathSegment,
5 resolver::{ResolveValueResult, Resolver, TypeNs, ValueNs},
6};
4 7
5use super::{ExprOrPatId, InferenceContext, TraitRef};
6use crate::{ 8use crate::{
7 db::HirDatabase, 9 db::HirDatabase,
8 generics::HasGenericParams, 10 generics::HasGenericParams,
9 resolve::{ResolveValueResult, Resolver, TypeNs, ValueNs},
10 ty::{method_resolution, Namespace, Substs, Ty, TypableDef, TypeWalk}, 11 ty::{method_resolution, Namespace, Substs, Ty, TypableDef, TypeWalk},
11 AssocItem, Container, Function, Name, Path, 12 AssocItem, Container, Function, Name, Path,
12}; 13};
13 14
15use super::{ExprOrPatId, InferenceContext, TraitRef};
16
14impl<'a, D: HirDatabase> InferenceContext<'a, D> { 17impl<'a, D: HirDatabase> InferenceContext<'a, D> {
15 pub(super) fn infer_path( 18 pub(super) fn infer_path(
16 &mut self, 19 &mut self,
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index e477b2439..c6ad0811b 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -11,6 +11,7 @@ use std::sync::Arc;
11use hir_def::{ 11use hir_def::{
12 builtin_type::{BuiltinFloat, BuiltinInt, BuiltinType}, 12 builtin_type::{BuiltinFloat, BuiltinInt, BuiltinType},
13 path::{GenericArg, PathSegment}, 13 path::{GenericArg, PathSegment},
14 resolver::{HasResolver, Resolver, TypeNs},
14 type_ref::{TypeBound, TypeRef}, 15 type_ref::{TypeBound, TypeRef},
15 GenericDefId, 16 GenericDefId,
16}; 17};
@@ -23,7 +24,6 @@ use crate::{
23 db::HirDatabase, 24 db::HirDatabase,
24 generics::HasGenericParams, 25 generics::HasGenericParams,
25 generics::{GenericDef, WherePredicate}, 26 generics::{GenericDef, WherePredicate},
26 resolve::{HasResolver, Resolver, TypeNs},
27 ty::{ 27 ty::{
28 primitive::{FloatTy, IntTy, Uncertain}, 28 primitive::{FloatTy, IntTy, Uncertain},
29 Adt, 29 Adt,
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index 5ad72ef9f..64adb814d 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -5,11 +5,11 @@
5use std::sync::Arc; 5use std::sync::Arc;
6 6
7use arrayvec::ArrayVec; 7use arrayvec::ArrayVec;
8use hir_def::resolver::Resolver;
8use rustc_hash::FxHashMap; 9use rustc_hash::FxHashMap;
9 10
10use crate::{ 11use crate::{
11 db::HirDatabase, 12 db::HirDatabase,
12 resolve::Resolver,
13 ty::primitive::{FloatBitness, Uncertain}, 13 ty::primitive::{FloatBitness, Uncertain},
14 ty::{Ty, TypeCtor}, 14 ty::{Ty, TypeCtor},
15 AssocItem, Crate, Function, ImplBlock, Module, Mutability, Name, Trait, 15 AssocItem, Crate, Function, ImplBlock, Module, Mutability, Name, Trait,
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 0af41de87..d579f5c7e 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -19,6 +19,7 @@ pub mod expr;
19pub mod body; 19pub mod body;
20pub mod generics; 20pub mod generics;
21pub mod traits; 21pub mod traits;
22pub mod resolver;
22 23
23#[cfg(test)] 24#[cfg(test)]
24mod test_db; 25mod test_db;
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir_def/src/resolver.rs
index a616f0ea5..840785baa 100644
--- a/crates/ra_hir/src/resolve.rs
+++ b/crates/ra_hir_def/src/resolver.rs
@@ -1,7 +1,14 @@
1//! Name resolution. 1//! Name resolution façade.
2use std::sync::Arc; 2use std::sync::Arc;
3 3
4use hir_def::{ 4use hir_expand::{
5 name::{self, Name},
6 MacroDefId,
7};
8use ra_db::CrateId;
9use rustc_hash::FxHashSet;
10
11use crate::{
5 body::scope::{ExprScopes, ScopeId}, 12 body::scope::{ExprScopes, ScopeId},
6 builtin_type::BuiltinType, 13 builtin_type::BuiltinType,
7 db::DefDatabase2, 14 db::DefDatabase2,
@@ -13,15 +20,9 @@ use hir_def::{
13 FunctionId, GenericDefId, ImplId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, 20 FunctionId, GenericDefId, ImplId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId,
14 TypeAliasId, UnionId, 21 TypeAliasId, UnionId,
15}; 22};
16use hir_expand::{
17 name::{self, Name},
18 MacroDefId,
19};
20use ra_db::CrateId;
21use rustc_hash::FxHashSet;
22 23
23#[derive(Debug, Clone, Default)] 24#[derive(Debug, Clone, Default)]
24pub(crate) struct Resolver { 25pub struct Resolver {
25 scopes: Vec<Scope>, 26 scopes: Vec<Scope>,
26} 27}
27 28
@@ -54,7 +55,7 @@ pub(crate) enum Scope {
54} 55}
55 56
56#[derive(Debug, Clone, PartialEq, Eq, Hash)] 57#[derive(Debug, Clone, PartialEq, Eq, Hash)]
57pub(crate) enum TypeNs { 58pub enum TypeNs {
58 SelfType(ImplId), 59 SelfType(ImplId),
59 GenericParam(u32), 60 GenericParam(u32),
60 AdtId(AdtId), 61 AdtId(AdtId),
@@ -69,13 +70,13 @@ pub(crate) enum TypeNs {
69} 70}
70 71
71#[derive(Debug, Clone, PartialEq, Eq, Hash)] 72#[derive(Debug, Clone, PartialEq, Eq, Hash)]
72pub(crate) enum ResolveValueResult { 73pub enum ResolveValueResult {
73 ValueNs(ValueNs), 74 ValueNs(ValueNs),
74 Partial(TypeNs, usize), 75 Partial(TypeNs, usize),
75} 76}
76 77
77#[derive(Debug, Clone, PartialEq, Eq, Hash)] 78#[derive(Debug, Clone, PartialEq, Eq, Hash)]
78pub(crate) enum ValueNs { 79pub enum ValueNs {
79 LocalBinding(PatId), 80 LocalBinding(PatId),
80 FunctionId(FunctionId), 81 FunctionId(FunctionId),
81 ConstId(ConstId), 82 ConstId(ConstId),
@@ -86,11 +87,7 @@ pub(crate) enum ValueNs {
86 87
87impl Resolver { 88impl Resolver {
88 /// Resolve known trait from std, like `std::futures::Future` 89 /// Resolve known trait from std, like `std::futures::Future`
89 pub(crate) fn resolve_known_trait( 90 pub fn resolve_known_trait(&self, db: &impl DefDatabase2, path: &Path) -> Option<TraitId> {
90 &self,
91 db: &impl DefDatabase2,
92 path: &Path,
93 ) -> Option<TraitId> {
94 let res = self.resolve_module_path(db, path).take_types()?; 91 let res = self.resolve_module_path(db, path).take_types()?;
95 match res { 92 match res {
96 ModuleDefId::TraitId(it) => Some(it), 93 ModuleDefId::TraitId(it) => Some(it),
@@ -99,11 +96,7 @@ impl Resolver {
99 } 96 }
100 97
101 /// Resolve known struct from std, like `std::boxed::Box` 98 /// Resolve known struct from std, like `std::boxed::Box`
102 pub(crate) fn resolve_known_struct( 99 pub fn resolve_known_struct(&self, db: &impl DefDatabase2, path: &Path) -> Option<StructId> {
103 &self,
104 db: &impl DefDatabase2,
105 path: &Path,
106 ) -> Option<StructId> {
107 let res = self.resolve_module_path(db, path).take_types()?; 100 let res = self.resolve_module_path(db, path).take_types()?;
108 match res { 101 match res {
109 ModuleDefId::AdtId(AdtId::StructId(it)) => Some(it), 102 ModuleDefId::AdtId(AdtId::StructId(it)) => Some(it),
@@ -112,7 +105,7 @@ impl Resolver {
112 } 105 }
113 106
114 /// Resolve known enum from std, like `std::result::Result` 107 /// Resolve known enum from std, like `std::result::Result`
115 pub(crate) fn resolve_known_enum(&self, db: &impl DefDatabase2, path: &Path) -> Option<EnumId> { 108 pub fn resolve_known_enum(&self, db: &impl DefDatabase2, path: &Path) -> Option<EnumId> {
116 let res = self.resolve_module_path(db, path).take_types()?; 109 let res = self.resolve_module_path(db, path).take_types()?;
117 match res { 110 match res {
118 ModuleDefId::AdtId(AdtId::EnumId(it)) => Some(it), 111 ModuleDefId::AdtId(AdtId::EnumId(it)) => Some(it),
@@ -121,7 +114,7 @@ impl Resolver {
121 } 114 }
122 115
123 /// pub only for source-binder 116 /// pub only for source-binder
124 pub(crate) fn resolve_module_path(&self, db: &impl DefDatabase2, path: &Path) -> PerNs { 117 pub fn resolve_module_path(&self, db: &impl DefDatabase2, path: &Path) -> PerNs {
125 let (item_map, module) = match self.module() { 118 let (item_map, module) = match self.module() {
126 Some(it) => it, 119 Some(it) => it,
127 None => return PerNs::none(), 120 None => return PerNs::none(),
@@ -133,7 +126,7 @@ impl Resolver {
133 module_res 126 module_res
134 } 127 }
135 128
136 pub(crate) fn resolve_path_in_type_ns( 129 pub fn resolve_path_in_type_ns(
137 &self, 130 &self,
138 db: &impl DefDatabase2, 131 db: &impl DefDatabase2,
139 path: &Path, 132 path: &Path,
@@ -189,7 +182,7 @@ impl Resolver {
189 None 182 None
190 } 183 }
191 184
192 pub(crate) fn resolve_path_in_type_ns_fully( 185 pub fn resolve_path_in_type_ns_fully(
193 &self, 186 &self,
194 db: &impl DefDatabase2, 187 db: &impl DefDatabase2,
195 path: &Path, 188 path: &Path,
@@ -201,7 +194,7 @@ impl Resolver {
201 Some(res) 194 Some(res)
202 } 195 }
203 196
204 pub(crate) fn resolve_path_in_value_ns<'p>( 197 pub fn resolve_path_in_value_ns<'p>(
205 &self, 198 &self,
206 db: &impl DefDatabase2, 199 db: &impl DefDatabase2,
207 path: &'p Path, 200 path: &'p Path,
@@ -301,7 +294,7 @@ impl Resolver {
301 None 294 None
302 } 295 }
303 296
304 pub(crate) fn resolve_path_in_value_ns_fully( 297 pub fn resolve_path_in_value_ns_fully(
305 &self, 298 &self,
306 db: &impl DefDatabase2, 299 db: &impl DefDatabase2,
307 path: &Path, 300 path: &Path,
@@ -312,26 +305,18 @@ impl Resolver {
312 } 305 }
313 } 306 }
314 307
315 pub(crate) fn resolve_path_as_macro( 308 pub fn resolve_path_as_macro(&self, db: &impl DefDatabase2, path: &Path) -> Option<MacroDefId> {
316 &self,
317 db: &impl DefDatabase2,
318 path: &Path,
319 ) -> Option<MacroDefId> {
320 let (item_map, module) = self.module()?; 309 let (item_map, module) = self.module()?;
321 item_map.resolve_path(db, module, path).0.get_macros() 310 item_map.resolve_path(db, module, path).0.get_macros()
322 } 311 }
323 312
324 pub(crate) fn process_all_names( 313 pub fn process_all_names(&self, db: &impl DefDatabase2, f: &mut dyn FnMut(Name, ScopeDef)) {
325 &self,
326 db: &impl DefDatabase2,
327 f: &mut dyn FnMut(Name, ScopeDef),
328 ) {
329 for scope in self.scopes.iter().rev() { 314 for scope in self.scopes.iter().rev() {
330 scope.process_names(db, f); 315 scope.process_names(db, f);
331 } 316 }
332 } 317 }
333 318
334 pub(crate) fn traits_in_scope(&self, db: &impl DefDatabase2) -> FxHashSet<TraitId> { 319 pub fn traits_in_scope(&self, db: &impl DefDatabase2) -> FxHashSet<TraitId> {
335 let mut traits = FxHashSet::default(); 320 let mut traits = FxHashSet::default();
336 for scope in &self.scopes { 321 for scope in &self.scopes {
337 if let Scope::ModuleScope(m) = scope { 322 if let Scope::ModuleScope(m) = scope {
@@ -353,11 +338,11 @@ impl Resolver {
353 }) 338 })
354 } 339 }
355 340
356 pub(crate) fn krate(&self) -> Option<CrateId> { 341 pub fn krate(&self) -> Option<CrateId> {
357 self.module().map(|t| t.0.krate()) 342 self.module().map(|t| t.0.krate())
358 } 343 }
359 344
360 pub(crate) fn where_predicates_in_scope<'a>( 345 pub fn where_predicates_in_scope<'a>(
361 &'a self, 346 &'a self,
362 ) -> impl Iterator<Item = &'a crate::generics::WherePredicate> + 'a { 347 ) -> impl Iterator<Item = &'a crate::generics::WherePredicate> + 'a {
363 self.scopes 348 self.scopes
@@ -369,14 +354,14 @@ impl Resolver {
369 .flat_map(|params| params.where_predicates.iter()) 354 .flat_map(|params| params.where_predicates.iter())
370 } 355 }
371 356
372 pub(crate) fn generic_def(&self) -> Option<GenericDefId> { 357 pub fn generic_def(&self) -> Option<GenericDefId> {
373 self.scopes.iter().find_map(|scope| match scope { 358 self.scopes.iter().find_map(|scope| match scope {
374 Scope::GenericParams { def, .. } => Some(*def), 359 Scope::GenericParams { def, .. } => Some(*def),
375 _ => None, 360 _ => None,
376 }) 361 })
377 } 362 }
378 363
379 pub(crate) fn body_owner(&self) -> Option<DefWithBodyId> { 364 pub fn body_owner(&self) -> Option<DefWithBodyId> {
380 self.scopes.iter().find_map(|scope| match scope { 365 self.scopes.iter().find_map(|scope| match scope {
381 Scope::ExprScope(it) => Some(it.owner), 366 Scope::ExprScope(it) => Some(it.owner),
382 _ => None, 367 _ => None,
@@ -425,7 +410,7 @@ impl Resolver {
425 } 410 }
426} 411}
427 412
428pub(crate) enum ScopeDef { 413pub enum ScopeDef {
429 PerNs(PerNs), 414 PerNs(PerNs),
430 ImplSelfType(ImplId), 415 ImplSelfType(ImplId),
431 AdtSelfType(AdtId), 416 AdtSelfType(AdtId),
@@ -481,7 +466,7 @@ impl Scope {
481} 466}
482 467
483// needs arbitrary_self_types to be a method... or maybe move to the def? 468// needs arbitrary_self_types to be a method... or maybe move to the def?
484pub(crate) fn resolver_for_expr( 469pub fn resolver_for_expr(
485 db: &impl DefDatabase2, 470 db: &impl DefDatabase2,
486 owner: DefWithBodyId, 471 owner: DefWithBodyId,
487 expr_id: ExprId, 472 expr_id: ExprId,
@@ -490,7 +475,7 @@ pub(crate) fn resolver_for_expr(
490 resolver_for_scope(db, owner, scopes.scope_for(expr_id)) 475 resolver_for_scope(db, owner, scopes.scope_for(expr_id))
491} 476}
492 477
493pub(crate) fn resolver_for_scope( 478pub fn resolver_for_scope(
494 db: &impl DefDatabase2, 479 db: &impl DefDatabase2,
495 owner: DefWithBodyId, 480 owner: DefWithBodyId,
496 scope_id: Option<ScopeId>, 481 scope_id: Option<ScopeId>,
@@ -504,7 +489,7 @@ pub(crate) fn resolver_for_scope(
504 r 489 r
505} 490}
506 491
507pub(crate) trait HasResolver { 492pub trait HasResolver {
508 /// Builds a resolver for type references inside this def. 493 /// Builds a resolver for type references inside this def.
509 fn resolver(self, db: &impl DefDatabase2) -> Resolver; 494 fn resolver(self, db: &impl DefDatabase2) -> Resolver;
510} 495}
@@ -600,7 +585,7 @@ impl HasResolver for ContainerId {
600} 585}
601 586
602impl HasResolver for GenericDefId { 587impl HasResolver for GenericDefId {
603 fn resolver(self, db: &impl DefDatabase2) -> crate::Resolver { 588 fn resolver(self, db: &impl DefDatabase2) -> Resolver {
604 match self { 589 match self {
605 GenericDefId::FunctionId(inner) => inner.resolver(db), 590 GenericDefId::FunctionId(inner) => inner.resolver(db),
606 GenericDefId::AdtId(adt) => adt.resolver(db), 591 GenericDefId::AdtId(adt) => adt.resolver(db),