diff options
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 52ad4e5d1..87c78d98e 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -6,8 +6,10 @@ use std::sync::Arc; | |||
6 | 6 | ||
7 | use hir_def::{ | 7 | use hir_def::{ |
8 | adt::VariantData, | 8 | adt::VariantData, |
9 | body::{Body, BodySourceMap}, | ||
9 | builtin_type::BuiltinType, | 10 | builtin_type::BuiltinType, |
10 | docs::Documentation, | 11 | docs::Documentation, |
12 | expr::{BindingAnnotation, Pat, PatId}, | ||
11 | per_ns::PerNs, | 13 | per_ns::PerNs, |
12 | resolver::HasResolver, | 14 | resolver::HasResolver, |
13 | type_ref::{Mutability, TypeRef}, | 15 | type_ref::{Mutability, TypeRef}, |
@@ -20,12 +22,12 @@ use hir_expand::{ | |||
20 | name::{self, AsName}, | 22 | name::{self, AsName}, |
21 | AstId, MacroDefId, | 23 | AstId, MacroDefId, |
22 | }; | 24 | }; |
25 | use hir_ty::expr::ExprValidator; | ||
23 | use ra_db::{CrateId, Edition, FileId, FilePosition}; | 26 | use ra_db::{CrateId, Edition, FileId, FilePosition}; |
24 | use ra_syntax::{ast, AstNode, SyntaxNode}; | 27 | use ra_syntax::{ast, AstNode, SyntaxNode}; |
25 | 28 | ||
26 | use crate::{ | 29 | use crate::{ |
27 | db::{DefDatabase, HirDatabase}, | 30 | db::{DefDatabase, HirDatabase}, |
28 | expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId}, | ||
29 | ty::display::HirFormatter, | 31 | ty::display::HirFormatter, |
30 | ty::{ | 32 | ty::{ |
31 | self, InEnvironment, InferenceResult, TraitEnvironment, TraitRef, Ty, TyDefId, TypeCtor, | 33 | self, InEnvironment, InferenceResult, TraitEnvironment, TraitRef, Ty, TyDefId, TypeCtor, |
@@ -353,8 +355,8 @@ impl Struct { | |||
353 | .map(|(id, _)| StructField { parent: self.into(), id }) | 355 | .map(|(id, _)| StructField { parent: self.into(), id }) |
354 | } | 356 | } |
355 | 357 | ||
356 | pub fn ty(self, db: &impl HirDatabase) -> Ty { | 358 | pub fn ty(self, db: &impl HirDatabase) -> Type { |
357 | db.ty(self.id.into()) | 359 | Type::from_def(db, self.id.module(db).krate, self.id) |
358 | } | 360 | } |
359 | 361 | ||
360 | pub fn constructor_ty(self, db: &impl HirDatabase) -> Ty { | 362 | pub fn constructor_ty(self, db: &impl HirDatabase) -> Ty { |
@@ -380,8 +382,8 @@ impl Union { | |||
380 | Module { id: self.id.module(db) } | 382 | Module { id: self.id.module(db) } |
381 | } | 383 | } |
382 | 384 | ||
383 | pub fn ty(self, db: &impl HirDatabase) -> Ty { | 385 | pub fn ty(self, db: &impl HirDatabase) -> Type { |
384 | db.ty(self.id.into()) | 386 | Type::from_def(db, self.id.module(db).krate, self.id) |
385 | } | 387 | } |
386 | 388 | ||
387 | pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> { | 389 | pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> { |
@@ -441,8 +443,8 @@ impl Enum { | |||
441 | .map(|(id, _)| EnumVariant { parent: self, id }) | 443 | .map(|(id, _)| EnumVariant { parent: self, id }) |
442 | } | 444 | } |
443 | 445 | ||
444 | pub fn ty(self, db: &impl HirDatabase) -> Ty { | 446 | pub fn ty(self, db: &impl HirDatabase) -> Type { |
445 | db.ty(self.id.into()) | 447 | Type::from_def(db, self.id.module(db).krate, self.id) |
446 | } | 448 | } |
447 | } | 449 | } |
448 | 450 | ||
@@ -640,7 +642,7 @@ impl Function { | |||
640 | pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) { | 642 | pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) { |
641 | let infer = self.infer(db); | 643 | let infer = self.infer(db); |
642 | infer.add_diagnostics(db, self.id, sink); | 644 | infer.add_diagnostics(db, self.id, sink); |
643 | let mut validator = ExprValidator::new(self, infer, sink); | 645 | let mut validator = ExprValidator::new(self.id, infer, sink); |
644 | validator.validate_body(db); | 646 | validator.validate_body(db); |
645 | } | 647 | } |
646 | } | 648 | } |
@@ -946,13 +948,12 @@ impl ImplBlock { | |||
946 | db.impl_data(self.id).target_type.clone() | 948 | db.impl_data(self.id).target_type.clone() |
947 | } | 949 | } |
948 | 950 | ||
949 | pub fn target_ty(&self, db: &impl HirDatabase) -> Ty { | 951 | pub fn target_ty(&self, db: &impl HirDatabase) -> Type { |
950 | Ty::from_hir(db, &self.id.resolver(db), &self.target_type(db)) | 952 | let impl_data = db.impl_data(self.id); |
951 | } | 953 | let resolver = self.id.resolver(db); |
952 | 954 | let environment = TraitEnvironment::lower(db, &resolver); | |
953 | pub fn target_trait_ref(&self, db: &impl HirDatabase) -> Option<TraitRef> { | 955 | let ty = Ty::from_hir(db, &resolver, &impl_data.target_type); |
954 | let target_ty = self.target_ty(db); | 956 | Type { krate: self.id.module(db).krate, ty: InEnvironment { value: ty, environment } } |
955 | TraitRef::from_hir(db, &self.id.resolver(db), &self.target_trait(db)?, Some(target_ty)) | ||
956 | } | 957 | } |
957 | 958 | ||
958 | pub fn items(&self, db: &impl DefDatabase) -> Vec<AssocItem> { | 959 | pub fn items(&self, db: &impl DefDatabase) -> Vec<AssocItem> { |
@@ -1130,6 +1131,22 @@ impl Type { | |||
1130 | Some(adt.into()) | 1131 | Some(adt.into()) |
1131 | } | 1132 | } |
1132 | 1133 | ||
1134 | // FIXME: provide required accessors such that it becomes implementable from outside. | ||
1135 | pub fn is_equal_for_find_impls(&self, other: &Type) -> bool { | ||
1136 | match (&self.ty.value, &other.ty.value) { | ||
1137 | (Ty::Apply(a_original_ty), Ty::Apply(ty::ApplicationTy { ctor, parameters })) => { | ||
1138 | match ctor { | ||
1139 | TypeCtor::Ref(..) => match parameters.as_single() { | ||
1140 | Ty::Apply(a_ty) => a_original_ty.ctor == a_ty.ctor, | ||
1141 | _ => false, | ||
1142 | }, | ||
1143 | _ => a_original_ty.ctor == *ctor, | ||
1144 | } | ||
1145 | } | ||
1146 | _ => false, | ||
1147 | } | ||
1148 | } | ||
1149 | |||
1133 | fn derived(&self, ty: Ty) -> Type { | 1150 | fn derived(&self, ty: Ty) -> Type { |
1134 | Type { | 1151 | Type { |
1135 | krate: self.krate, | 1152 | krate: self.krate, |