From 080dd31f8460cba0298405fbcfcab8b61a4667ff Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 15 Nov 2019 19:14:50 +0300 Subject: Add ImplId --- crates/ra_hir_def/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'crates/ra_hir_def/src/lib.rs') diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 3fab7965c..22650db8b 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -321,6 +321,18 @@ impl AstItemDef for TypeAliasId { } } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct ImplId(salsa::InternId); +impl_intern_key!(ImplId); +impl AstItemDef for ImplId { + fn intern(db: &impl InternDatabase, loc: ItemLoc) -> Self { + db.intern_impl(loc) + } + fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc { + db.lookup_intern_impl(self) + } +} + macro_rules! impl_froms { ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => { $( -- cgit v1.2.3 From b21829f7edd71fb14911fc6ba47fe715757e415f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 15 Nov 2019 21:28:00 +0300 Subject: Remove old impls infrastructure --- crates/ra_hir_def/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'crates/ra_hir_def/src/lib.rs') diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 22650db8b..0a59c4ad7 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -13,6 +13,7 @@ pub mod path; pub mod type_ref; pub mod builtin_type; pub mod adt; +pub mod imp; pub mod diagnostics; pub mod expr; pub mod body; @@ -396,3 +397,15 @@ pub enum DefWithBodyId { } impl_froms!(DefWithBodyId: FunctionId, ConstId, StaticId); + +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum AssocItemId { + FunctionId(FunctionId), + ConstId(ConstId), + TypeAliasId(TypeAliasId), +} +// FIXME: not every function, ... is actually an assoc item. maybe we should make +// sure that you can only turn actual assoc items into AssocItemIds. This would +// require not implementing From, and instead having some checked way of +// casting them, and somehow making the constructors private, which would be annoying. +impl_froms!(AssocItemId: FunctionId, ConstId, TypeAliasId); -- cgit v1.2.3 From 4c90b7e2ecd03e739a3c92bbe5afd4c90fe2812d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 15 Nov 2019 23:24:56 +0300 Subject: Sourcify some things If we want to support macros properly, we need to get rid of those FileIds everywhere... --- crates/ra_hir_def/src/lib.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir_def/src/lib.rs') diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 0a59c4ad7..a240a10b8 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -78,14 +78,13 @@ impl ModuleSource { } } - pub fn from_child_node( - db: &impl db::DefDatabase2, - file_id: FileId, - child: &SyntaxNode, - ) -> ModuleSource { - if let Some(m) = child.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) { + pub fn from_child_node(db: &impl db::DefDatabase2, child: Source<&SyntaxNode>) -> ModuleSource { + if let Some(m) = + child.ast.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) + { ModuleSource::Module(m) } else { + let file_id = child.file_id.original_file(db); let source_file = db.parse(file_id).tree(); ModuleSource::SourceFile(source_file) } -- cgit v1.2.3