From 957c0171e63631f67d732f4ce53dc8bfe2602e71 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Dec 2019 13:11:01 +0100 Subject: Remove more copy-paste --- crates/ra_hir_def/src/lib.rs | 87 +++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 57 deletions(-) diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 140eccf26..042fd3f8b 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -45,7 +45,7 @@ use std::hash::Hash; use hir_expand::{ast_id_map::FileAstId, AstId, HirFileId, InFile, MacroDefId}; use ra_arena::{impl_arena_id, RawId}; use ra_db::{impl_intern_key, salsa, CrateId}; -use ra_syntax::ast; +use ra_syntax::{ast, AstNode}; use crate::builtin_type::BuiltinType; @@ -65,16 +65,23 @@ pub struct ModuleId { pub struct LocalModuleId(RawId); impl_arena_id!(LocalModuleId); -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct FunctionId(salsa::InternId); -impl_intern_key!(FunctionId); +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ItemLoc { + pub container: ContainerId, + pub ast_id: AstId, +} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct FunctionLoc { +pub struct AssocItemLoc { pub container: AssocContainerId, - pub ast_id: AstId, + pub ast_id: AstId, } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct FunctionId(salsa::InternId); +impl_intern_key!(FunctionId); +type FunctionLoc = AssocItemLoc; + impl Intern for FunctionLoc { type ID = FunctionId; fn intern(self, db: &impl db::DefDatabase) -> FunctionId { @@ -92,12 +99,7 @@ impl Lookup for FunctionId { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct StructId(salsa::InternId); impl_intern_key!(StructId); - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct StructLoc { - pub container: ContainerId, - pub ast_id: AstId, -} +pub type StructLoc = ItemLoc; impl Intern for StructLoc { type ID = StructId; @@ -116,12 +118,7 @@ impl Lookup for StructId { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct UnionId(salsa::InternId); impl_intern_key!(UnionId); - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct UnionLoc { - pub container: ContainerId, - pub ast_id: AstId, -} +pub type UnionLoc = ItemLoc; impl Intern for UnionLoc { type ID = UnionId; @@ -140,12 +137,7 @@ impl Lookup for UnionId { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct EnumId(salsa::InternId); impl_intern_key!(EnumId); - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct EnumLoc { - pub container: ContainerId, - pub ast_id: AstId, -} +pub type EnumLoc = ItemLoc; impl Intern for EnumLoc { type ID = EnumId; @@ -185,11 +177,7 @@ impl_arena_id!(LocalStructFieldId); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct ConstId(salsa::InternId); impl_intern_key!(ConstId); -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ConstLoc { - pub container: AssocContainerId, - pub ast_id: AstId, -} +type ConstLoc = AssocItemLoc; impl Intern for ConstLoc { type ID = ConstId; @@ -208,12 +196,7 @@ impl Lookup for ConstId { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct StaticId(salsa::InternId); impl_intern_key!(StaticId); - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct StaticLoc { - pub container: ContainerId, - pub ast_id: AstId, -} +pub type StaticLoc = ItemLoc; impl Intern for StaticLoc { type ID = StaticId; @@ -232,12 +215,7 @@ impl Lookup for StaticId { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct TraitId(salsa::InternId); impl_intern_key!(TraitId); - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TraitLoc { - pub container: ContainerId, - pub ast_id: AstId, -} +pub type TraitLoc = ItemLoc; impl Intern for TraitLoc { type ID = TraitId; @@ -256,12 +234,7 @@ impl Lookup for TraitId { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct TypeAliasId(salsa::InternId); impl_intern_key!(TypeAliasId); - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TypeAliasLoc { - pub container: AssocContainerId, - pub ast_id: AstId, -} +type TypeAliasLoc = AssocItemLoc; impl Intern for TypeAliasLoc { type ID = TypeAliasId; @@ -301,6 +274,16 @@ impl Lookup for ImplId { } } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct TypeParamId { + pub parent: GenericDefId, + pub local_id: LocalTypeParamId, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct LocalTypeParamId(RawId); +impl_arena_id!(LocalTypeParamId); + macro_rules! impl_froms { ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => { $( @@ -320,16 +303,6 @@ macro_rules! impl_froms { } } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct TypeParamId { - pub parent: GenericDefId, - pub local_id: LocalTypeParamId, -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct LocalTypeParamId(RawId); -impl_arena_id!(LocalTypeParamId); - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum ContainerId { ModuleId(ModuleId), -- cgit v1.2.3