aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir_def/src/lib.rs24
-rw-r--r--crates/ra_hir_def/src/resolver.rs1
-rw-r--r--crates/ra_hir_ty/src/infer/path.rs2
-rw-r--r--crates/ra_hir_ty/src/method_resolution.rs10
-rw-r--r--crates/ra_hir_ty/src/utils.rs2
5 files changed, 20 insertions, 19 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index f085bbe87..4fc3127c4 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -335,6 +335,7 @@ pub enum ContainerId {
335 ModuleId(ModuleId), 335 ModuleId(ModuleId),
336 ImplId(ImplId), 336 ImplId(ImplId),
337 TraitId(TraitId), 337 TraitId(TraitId),
338 DefWithBodyId(DefWithBodyId),
338} 339}
339 340
340/// A Data Type 341/// A Data Type
@@ -478,33 +479,32 @@ pub trait HasModule {
478 fn module(&self, db: &impl db::DefDatabase) -> ModuleId; 479 fn module(&self, db: &impl db::DefDatabase) -> ModuleId;
479} 480}
480 481
481impl HasModule for FunctionLoc { 482impl HasModule for ContainerId {
482 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 483 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
483 match self.container { 484 match *self {
484 ContainerId::ModuleId(it) => it, 485 ContainerId::ModuleId(it) => it,
485 ContainerId::ImplId(it) => it.lookup(db).container, 486 ContainerId::ImplId(it) => it.lookup(db).container,
486 ContainerId::TraitId(it) => it.lookup(db).container, 487 ContainerId::TraitId(it) => it.lookup(db).container,
488 ContainerId::DefWithBodyId(it) => it.module(db),
487 } 489 }
488 } 490 }
489} 491}
490 492
493impl HasModule for FunctionLoc {
494 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
495 self.container.module(db)
496 }
497}
498
491impl HasModule for TypeAliasLoc { 499impl HasModule for TypeAliasLoc {
492 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 500 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
493 match self.container { 501 self.container.module(db)
494 ContainerId::ModuleId(it) => it,
495 ContainerId::ImplId(it) => it.lookup(db).container,
496 ContainerId::TraitId(it) => it.lookup(db).container,
497 }
498 } 502 }
499} 503}
500 504
501impl HasModule for ConstLoc { 505impl HasModule for ConstLoc {
502 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 506 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
503 match self.container { 507 self.container.module(db)
504 ContainerId::ModuleId(it) => it,
505 ContainerId::ImplId(it) => it.lookup(db).container,
506 ContainerId::TraitId(it) => it.lookup(db).container,
507 }
508 } 508 }
509} 509}
510 510
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs
index 2694c0438..250329271 100644
--- a/crates/ra_hir_def/src/resolver.rs
+++ b/crates/ra_hir_def/src/resolver.rs
@@ -586,6 +586,7 @@ impl HasResolver for ContainerId {
586 ContainerId::TraitId(it) => it.resolver(db), 586 ContainerId::TraitId(it) => it.resolver(db),
587 ContainerId::ImplId(it) => it.resolver(db), 587 ContainerId::ImplId(it) => it.resolver(db),
588 ContainerId::ModuleId(it) => it.resolver(db), 588 ContainerId::ModuleId(it) => it.resolver(db),
589 ContainerId::DefWithBodyId(it) => it.resolver(db),
589 } 590 }
590 } 591 }
591} 592}
diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs
index 402a89386..31c90ea1e 100644
--- a/crates/ra_hir_ty/src/infer/path.rs
+++ b/crates/ra_hir_ty/src/infer/path.rs
@@ -237,7 +237,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
237 })); 237 }));
238 Some(substs) 238 Some(substs)
239 } 239 }
240 ContainerId::ModuleId(_) => None, 240 ContainerId::ModuleId(_) | ContainerId::DefWithBodyId(_) => None,
241 }; 241 };
242 242
243 self.write_assoc_resolution(id, item.into()); 243 self.write_assoc_resolution(id, item.into());
diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs
index 848e306e9..d0b2b016d 100644
--- a/crates/ra_hir_ty/src/method_resolution.rs
+++ b/crates/ra_hir_ty/src/method_resolution.rs
@@ -6,8 +6,8 @@ use std::sync::Arc;
6 6
7use arrayvec::ArrayVec; 7use arrayvec::ArrayVec;
8use hir_def::{ 8use hir_def::{
9 lang_item::LangItemTarget, resolver::Resolver, type_ref::Mutability, AssocItemId, FunctionId, 9 lang_item::LangItemTarget, resolver::Resolver, type_ref::Mutability, AssocItemId, ContainerId,
10 HasModule, ImplId, Lookup, TraitId, 10 FunctionId, HasModule, ImplId, Lookup, TraitId,
11}; 11};
12use hir_expand::name::Name; 12use hir_expand::name::Name;
13use ra_db::CrateId; 13use ra_db::CrateId;
@@ -451,12 +451,12 @@ fn transform_receiver_ty(
451 self_ty: &Canonical<Ty>, 451 self_ty: &Canonical<Ty>,
452) -> Option<Ty> { 452) -> Option<Ty> {
453 let substs = match function_id.lookup(db).container { 453 let substs = match function_id.lookup(db).container {
454 hir_def::ContainerId::TraitId(_) => Substs::build_for_def(db, function_id) 454 ContainerId::TraitId(_) => Substs::build_for_def(db, function_id)
455 .push(self_ty.value.clone()) 455 .push(self_ty.value.clone())
456 .fill_with_unknown() 456 .fill_with_unknown()
457 .build(), 457 .build(),
458 hir_def::ContainerId::ImplId(impl_id) => inherent_impl_substs(db, impl_id, &self_ty)?, 458 ContainerId::ImplId(impl_id) => inherent_impl_substs(db, impl_id, &self_ty)?,
459 hir_def::ContainerId::ModuleId(_) => unreachable!(), 459 ContainerId::ModuleId(_) | ContainerId::DefWithBodyId(_) => unreachable!(),
460 }; 460 };
461 let sig = db.callable_item_signature(function_id.into()); 461 let sig = db.callable_item_signature(function_id.into());
462 Some(sig.params()[0].clone().subst(&substs)) 462 Some(sig.params()[0].clone().subst(&substs))
diff --git a/crates/ra_hir_ty/src/utils.rs b/crates/ra_hir_ty/src/utils.rs
index 29799a8cb..34defc1a2 100644
--- a/crates/ra_hir_ty/src/utils.rs
+++ b/crates/ra_hir_ty/src/utils.rs
@@ -157,6 +157,6 @@ fn parent_generic_def(db: &impl DefDatabase, def: GenericDefId) -> Option<Generi
157 match container { 157 match container {
158 ContainerId::ImplId(it) => Some(it.into()), 158 ContainerId::ImplId(it) => Some(it.into()),
159 ContainerId::TraitId(it) => Some(it.into()), 159 ContainerId::TraitId(it) => Some(it.into()),
160 ContainerId::ModuleId(_) => None, 160 ContainerId::ModuleId(_) | ContainerId::DefWithBodyId(_) => None,
161 } 161 }
162} 162}