aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r--crates/ra_hir/src/code_model.rs32
1 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 e86077dd6..1b3525011 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -31,7 +31,7 @@ use hir_ty::{
31 ApplicationTy, Canonical, GenericPredicate, InEnvironment, Substs, TraitEnvironment, Ty, 31 ApplicationTy, Canonical, GenericPredicate, InEnvironment, Substs, TraitEnvironment, Ty,
32 TyDefId, TypeCtor, 32 TyDefId, TypeCtor,
33}; 33};
34use ra_db::{CrateId, CrateName, Edition, FileId}; 34use ra_db::{CrateId, Edition, FileId};
35use ra_prof::profile; 35use ra_prof::profile;
36use ra_syntax::ast::{self, AttrsOwner, NameOwner}; 36use ra_syntax::ast::{self, AttrsOwner, NameOwner};
37use rustc_hash::FxHashSet; 37use rustc_hash::FxHashSet;
@@ -94,8 +94,8 @@ impl Crate {
94 db.crate_graph()[self.id].edition 94 db.crate_graph()[self.id].edition
95 } 95 }
96 96
97 pub fn display_name(self, db: &dyn HirDatabase) -> Option<CrateName> { 97 pub fn display_name(self, db: &dyn HirDatabase) -> Option<String> {
98 db.crate_graph()[self.id].display_name.as_ref().cloned() 98 db.crate_graph()[self.id].display_name.clone()
99 } 99 }
100 100
101 pub fn query_external_importables( 101 pub fn query_external_importables(
@@ -1053,12 +1053,14 @@ pub struct ImplDef {
1053 1053
1054impl ImplDef { 1054impl ImplDef {
1055 pub fn all_in_crate(db: &dyn HirDatabase, krate: Crate) -> Vec<ImplDef> { 1055 pub fn all_in_crate(db: &dyn HirDatabase, krate: Crate) -> Vec<ImplDef> {
1056 let impls = db.impls_in_crate(krate.id); 1056 let inherent = db.inherent_impls_in_crate(krate.id);
1057 impls.all_impls().map(Self::from).collect() 1057 let trait_ = db.trait_impls_in_crate(krate.id);
1058
1059 inherent.all_impls().chain(trait_.all_impls()).map(Self::from).collect()
1058 } 1060 }
1059 pub fn for_trait(db: &dyn HirDatabase, krate: Crate, trait_: Trait) -> Vec<ImplDef> { 1061 pub fn for_trait(db: &dyn HirDatabase, krate: Crate, trait_: Trait) -> Vec<ImplDef> {
1060 let impls = db.impls_in_crate(krate.id); 1062 let impls = db.trait_impls_in_crate(krate.id);
1061 impls.lookup_impl_defs_for_trait(trait_.id).map(Self::from).collect() 1063 impls.for_trait(trait_.id).map(Self::from).collect()
1062 } 1064 }
1063 1065
1064 pub fn target_trait(self, db: &dyn HirDatabase) -> Option<TypeRef> { 1066 pub fn target_trait(self, db: &dyn HirDatabase) -> Option<TypeRef> {
@@ -1187,7 +1189,7 @@ impl Type {
1187 None => return false, 1189 None => return false,
1188 }; 1190 };
1189 1191
1190 let canonical_ty = Canonical { value: self.ty.value.clone(), num_vars: 0 }; 1192 let canonical_ty = Canonical { value: self.ty.value.clone(), kinds: Arc::new([]) };
1191 method_resolution::implements_trait( 1193 method_resolution::implements_trait(
1192 &canonical_ty, 1194 &canonical_ty,
1193 db, 1195 db,
@@ -1211,7 +1213,7 @@ impl Type {
1211 self.ty.environment.clone(), 1213 self.ty.environment.clone(),
1212 hir_ty::Obligation::Trait(trait_ref), 1214 hir_ty::Obligation::Trait(trait_ref),
1213 ), 1215 ),
1214 num_vars: 0, 1216 kinds: Arc::new([]),
1215 }; 1217 };
1216 1218
1217 db.trait_solve(self.krate, goal).is_some() 1219 db.trait_solve(self.krate, goal).is_some()
@@ -1286,7 +1288,7 @@ impl Type {
1286 pub fn autoderef<'a>(&'a self, db: &'a dyn HirDatabase) -> impl Iterator<Item = Type> + 'a { 1288 pub fn autoderef<'a>(&'a self, db: &'a dyn HirDatabase) -> impl Iterator<Item = Type> + 'a {
1287 // There should be no inference vars in types passed here 1289 // There should be no inference vars in types passed here
1288 // FIXME check that? 1290 // FIXME check that?
1289 let canonical = Canonical { value: self.ty.value.clone(), num_vars: 0 }; 1291 let canonical = Canonical { value: self.ty.value.clone(), kinds: Arc::new([]) };
1290 let environment = self.ty.environment.clone(); 1292 let environment = self.ty.environment.clone();
1291 let ty = InEnvironment { value: canonical, environment }; 1293 let ty = InEnvironment { value: canonical, environment };
1292 autoderef(db, Some(self.krate), ty) 1294 autoderef(db, Some(self.krate), ty)
@@ -1303,10 +1305,10 @@ impl Type {
1303 mut callback: impl FnMut(AssocItem) -> Option<T>, 1305 mut callback: impl FnMut(AssocItem) -> Option<T>,
1304 ) -> Option<T> { 1306 ) -> Option<T> {
1305 for krate in self.ty.value.def_crates(db, krate.id)? { 1307 for krate in self.ty.value.def_crates(db, krate.id)? {
1306 let impls = db.impls_in_crate(krate); 1308 let impls = db.inherent_impls_in_crate(krate);
1307 1309
1308 for impl_def in impls.lookup_impl_defs(&self.ty.value) { 1310 for impl_def in impls.for_self_ty(&self.ty.value) {
1309 for &item in db.impl_data(impl_def).items.iter() { 1311 for &item in db.impl_data(*impl_def).items.iter() {
1310 if let Some(result) = callback(item.into()) { 1312 if let Some(result) = callback(item.into()) {
1311 return Some(result); 1313 return Some(result);
1312 } 1314 }
@@ -1327,7 +1329,7 @@ impl Type {
1327 // There should be no inference vars in types passed here 1329 // There should be no inference vars in types passed here
1328 // FIXME check that? 1330 // FIXME check that?
1329 // FIXME replace Unknown by bound vars here 1331 // FIXME replace Unknown by bound vars here
1330 let canonical = Canonical { value: self.ty.value.clone(), num_vars: 0 }; 1332 let canonical = Canonical { value: self.ty.value.clone(), kinds: Arc::new([]) };
1331 1333
1332 let env = self.ty.environment.clone(); 1334 let env = self.ty.environment.clone();
1333 let krate = krate.id; 1335 let krate = krate.id;
@@ -1358,7 +1360,7 @@ impl Type {
1358 // There should be no inference vars in types passed here 1360 // There should be no inference vars in types passed here
1359 // FIXME check that? 1361 // FIXME check that?
1360 // FIXME replace Unknown by bound vars here 1362 // FIXME replace Unknown by bound vars here
1361 let canonical = Canonical { value: self.ty.value.clone(), num_vars: 0 }; 1363 let canonical = Canonical { value: self.ty.value.clone(), kinds: Arc::new([]) };
1362 1364
1363 let env = self.ty.environment.clone(); 1365 let env = self.ty.environment.clone();
1364 let krate = krate.id; 1366 let krate = krate.id;