diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 20 | ||||
-rw-r--r-- | crates/ra_hir/src/source_analyzer.rs | 12 |
2 files changed, 17 insertions, 15 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 4b150ef06..e91abf6f5 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -10,7 +10,7 @@ use hir_def::{ | |||
10 | docs::Documentation, | 10 | docs::Documentation, |
11 | expr::{BindingAnnotation, Pat, PatId}, | 11 | expr::{BindingAnnotation, Pat, PatId}, |
12 | per_ns::PerNs, | 12 | per_ns::PerNs, |
13 | resolver::HasResolver, | 13 | resolver::{HasResolver, Resolver}, |
14 | type_ref::{Mutability, TypeRef}, | 14 | type_ref::{Mutability, TypeRef}, |
15 | AdtId, AssocContainerId, ConstId, DefWithBodyId, EnumId, FunctionId, GenericDefId, HasModule, | 15 | AdtId, AssocContainerId, ConstId, DefWithBodyId, EnumId, FunctionId, GenericDefId, HasModule, |
16 | ImplId, LocalEnumVariantId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId, | 16 | ImplId, LocalEnumVariantId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId, |
@@ -912,10 +912,8 @@ impl Local { | |||
912 | let def = DefWithBodyId::from(self.parent); | 912 | let def = DefWithBodyId::from(self.parent); |
913 | let infer = db.infer(def); | 913 | let infer = db.infer(def); |
914 | let ty = infer[self.pat_id].clone(); | 914 | let ty = infer[self.pat_id].clone(); |
915 | let resolver = def.resolver(db.upcast()); | ||
916 | let krate = def.module(db.upcast()).krate; | 915 | let krate = def.module(db.upcast()).krate; |
917 | let environment = TraitEnvironment::lower(db, &resolver); | 916 | Type::new(db, krate, def, ty) |
918 | Type { krate, ty: InEnvironment { value: ty, environment } } | ||
919 | } | 917 | } |
920 | 918 | ||
921 | pub fn source(self, db: &dyn HirDatabase) -> InFile<Either<ast::BindPat, ast::SelfParam>> { | 919 | pub fn source(self, db: &dyn HirDatabase) -> InFile<Either<ast::BindPat, ast::SelfParam>> { |
@@ -1020,11 +1018,21 @@ impl ImplDef { | |||
1020 | 1018 | ||
1021 | #[derive(Clone, PartialEq, Eq, Debug)] | 1019 | #[derive(Clone, PartialEq, Eq, Debug)] |
1022 | pub struct Type { | 1020 | pub struct Type { |
1023 | pub(crate) krate: CrateId, | 1021 | krate: CrateId, |
1024 | pub(crate) ty: InEnvironment<Ty>, | 1022 | ty: InEnvironment<Ty>, |
1025 | } | 1023 | } |
1026 | 1024 | ||
1027 | impl Type { | 1025 | impl Type { |
1026 | pub(crate) fn new_with_resolver( | ||
1027 | db: &dyn HirDatabase, | ||
1028 | resolver: &Resolver, | ||
1029 | ty: Ty, | ||
1030 | ) -> Option<Type> { | ||
1031 | let krate = resolver.krate()?; | ||
1032 | let environment = TraitEnvironment::lower(db, &resolver); | ||
1033 | Some(Type { krate, ty: InEnvironment { value: ty, environment } }) | ||
1034 | } | ||
1035 | |||
1028 | fn new(db: &dyn HirDatabase, krate: CrateId, lexical_env: impl HasResolver, ty: Ty) -> Type { | 1036 | fn new(db: &dyn HirDatabase, krate: CrateId, lexical_env: impl HasResolver, ty: Ty) -> Type { |
1029 | let resolver = lexical_env.resolver(db.upcast()); | 1037 | let resolver = lexical_env.resolver(db.upcast()); |
1030 | let environment = TraitEnvironment::lower(db, &resolver); | 1038 | let environment = TraitEnvironment::lower(db, &resolver); |
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs index e8afef328..10c12c910 100644 --- a/crates/ra_hir/src/source_analyzer.rs +++ b/crates/ra_hir/src/source_analyzer.rs | |||
@@ -17,7 +17,7 @@ use hir_def::{ | |||
17 | AsMacroCall, DefWithBodyId, | 17 | AsMacroCall, DefWithBodyId, |
18 | }; | 18 | }; |
19 | use hir_expand::{hygiene::Hygiene, name::AsName, HirFileId, InFile}; | 19 | use hir_expand::{hygiene::Hygiene, name::AsName, HirFileId, InFile}; |
20 | use hir_ty::{InEnvironment, InferenceResult, TraitEnvironment}; | 20 | use hir_ty::InferenceResult; |
21 | use ra_syntax::{ | 21 | use ra_syntax::{ |
22 | ast::{self, AstNode}, | 22 | ast::{self, AstNode}, |
23 | SyntaxNode, SyntaxNodePtr, TextUnit, | 23 | SyntaxNode, SyntaxNodePtr, TextUnit, |
@@ -103,10 +103,6 @@ impl SourceAnalyzer { | |||
103 | Some(res) | 103 | Some(res) |
104 | } | 104 | } |
105 | 105 | ||
106 | fn trait_env(&self, db: &dyn HirDatabase) -> Arc<TraitEnvironment> { | ||
107 | TraitEnvironment::lower(db, &self.resolver) | ||
108 | } | ||
109 | |||
110 | pub(crate) fn type_of(&self, db: &dyn HirDatabase, expr: &ast::Expr) -> Option<Type> { | 106 | pub(crate) fn type_of(&self, db: &dyn HirDatabase, expr: &ast::Expr) -> Option<Type> { |
111 | let expr_id = match expr { | 107 | let expr_id = match expr { |
112 | ast::Expr::MacroCall(call) => { | 108 | ast::Expr::MacroCall(call) => { |
@@ -117,15 +113,13 @@ impl SourceAnalyzer { | |||
117 | }?; | 113 | }?; |
118 | 114 | ||
119 | let ty = self.infer.as_ref()?[expr_id].clone(); | 115 | let ty = self.infer.as_ref()?[expr_id].clone(); |
120 | let environment = self.trait_env(db); | 116 | Type::new_with_resolver(db, &self.resolver, ty) |
121 | Some(Type { krate: self.resolver.krate()?, ty: InEnvironment { value: ty, environment } }) | ||
122 | } | 117 | } |
123 | 118 | ||
124 | pub(crate) fn type_of_pat(&self, db: &dyn HirDatabase, pat: &ast::Pat) -> Option<Type> { | 119 | pub(crate) fn type_of_pat(&self, db: &dyn HirDatabase, pat: &ast::Pat) -> Option<Type> { |
125 | let pat_id = self.pat_id(pat)?; | 120 | let pat_id = self.pat_id(pat)?; |
126 | let ty = self.infer.as_ref()?[pat_id].clone(); | 121 | let ty = self.infer.as_ref()?[pat_id].clone(); |
127 | let environment = self.trait_env(db); | 122 | Type::new_with_resolver(db, &self.resolver, ty) |
128 | Some(Type { krate: self.resolver.krate()?, ty: InEnvironment { value: ty, environment } }) | ||
129 | } | 123 | } |
130 | 124 | ||
131 | pub(crate) fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> { | 125 | pub(crate) fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> { |