From 82e9b245587046d2a1ed432225b19023adbe3245 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 12 Dec 2019 14:34:03 +0100 Subject: Move traits to the new loc --- crates/ra_hir/src/code_model.rs | 2 +- crates/ra_hir/src/from_source.rs | 6 ++++-- crates/ra_hir/src/has_source.rs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 117ca2fe3..78c7792bf 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -577,7 +577,7 @@ pub struct Trait { impl Trait { pub fn module(self, db: &impl DefDatabase) -> Module { - Module { id: self.id.module(db) } + Module { id: self.id.lookup(db).container } } pub fn name(self, db: &impl DefDatabase) -> Name { diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index b35188a21..0cf4bcae1 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs @@ -44,8 +44,10 @@ impl FromSource for Enum { impl FromSource for Trait { type Ast = ast::TraitDef; fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option { - let id = from_source(db, src)?; - Some(Trait { id }) + // XXX: use `.parent()` to avoid finding ourselves + let parent = src.value.syntax().parent()?; + let container = Container::find(db, src.with_value(parent).as_ref())?; + container.child_by_source(db)[keys::TRAIT].get(&src).copied().map(Trait::from) } } impl FromSource for Function { diff --git a/crates/ra_hir/src/has_source.rs b/crates/ra_hir/src/has_source.rs index a888fe995..c4c6d66b7 100644 --- a/crates/ra_hir/src/has_source.rs +++ b/crates/ra_hir/src/has_source.rs @@ -93,7 +93,7 @@ impl HasSource for Static { impl HasSource for Trait { type Ast = ast::TraitDef; fn source(self, db: &impl DefDatabase) -> InFile { - self.id.source(db) + self.id.lookup(db).source(db) } } impl HasSource for TypeAlias { -- cgit v1.2.3