From 693ac892f2db5db1ce7cf86db7bf6207b3515c42 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 13 Jul 2020 16:16:53 +0200 Subject: Don't copy-paste `impl_froms` into every crate --- crates/ra_hir_def/src/lib.rs | 45 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 30 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 564434ccc..b71d626c3 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -65,6 +65,7 @@ use item_tree::{ Const, Enum, Function, Impl, ItemTreeId, ItemTreeNode, ModItem, Static, Struct, Trait, TypeAlias, Union, }; +use stdx::impl_from; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct ModuleId { @@ -223,25 +224,6 @@ pub struct TypeParamId { pub type LocalTypeParamId = Idx; -macro_rules! impl_froms { - ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => { - $( - impl From<$v> for $e { - fn from(it: $v) -> $e { - $e::$v(it) - } - } - $($( - impl From<$sv> for $e { - fn from(it: $sv) -> $e { - $e::$v($v::$sv(it)) - } - } - )*)? - )* - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum ContainerId { ModuleId(ModuleId), @@ -254,7 +236,7 @@ pub enum AssocContainerId { ImplId(ImplId), TraitId(TraitId), } -impl_froms!(AssocContainerId: ContainerId); +impl_from!(ContainerId for AssocContainerId); /// A Data Type #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] @@ -263,7 +245,7 @@ pub enum AdtId { UnionId(UnionId), EnumId(EnumId), } -impl_froms!(AdtId: StructId, UnionId, EnumId); +impl_from!(StructId, UnionId, EnumId for AdtId); /// The defs which can be visible in the module. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -279,8 +261,8 @@ pub enum ModuleDefId { TypeAliasId(TypeAliasId), BuiltinType(BuiltinType), } -impl_froms!( - ModuleDefId: ModuleId, +impl_from!( + ModuleId, FunctionId, AdtId(StructId, EnumId, UnionId), EnumVariantId, @@ -289,6 +271,7 @@ impl_froms!( TraitId, TypeAliasId, BuiltinType + for ModuleDefId ); /// The defs which have a body. @@ -299,7 +282,7 @@ pub enum DefWithBodyId { ConstId(ConstId), } -impl_froms!(DefWithBodyId: FunctionId, ConstId, StaticId); +impl_from!(FunctionId, ConstId, StaticId for DefWithBodyId); #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum AssocItemId { @@ -311,7 +294,7 @@ pub enum AssocItemId { // 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); +impl_from!(FunctionId, ConstId, TypeAliasId for AssocItemId); #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] pub enum GenericDefId { @@ -326,14 +309,15 @@ pub enum GenericDefId { // consts can have type parameters from their parents (i.e. associated consts of traits) ConstId(ConstId), } -impl_froms!( - GenericDefId: FunctionId, +impl_from!( + FunctionId, AdtId(StructId, EnumId, UnionId), TraitId, TypeAliasId, ImplId, EnumVariantId, ConstId + for GenericDefId ); impl From for GenericDefId { @@ -361,8 +345,8 @@ pub enum AttrDefId { ImplId(ImplId), } -impl_froms!( - AttrDefId: ModuleId, +impl_from!( + ModuleId, FieldId, AdtId(StructId, EnumId, UnionId), EnumVariantId, @@ -373,6 +357,7 @@ impl_froms!( TypeAliasId, MacroDefId, ImplId + for AttrDefId ); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -381,7 +366,7 @@ pub enum VariantId { StructId(StructId), UnionId(UnionId), } -impl_froms!(VariantId: EnumVariantId, StructId, UnionId); +impl_from!(EnumVariantId, StructId, UnionId for VariantId); trait Intern { type ID; -- cgit v1.2.3 From 20770044631fd0c21caa12f9bc87489ea6c848ee Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Wed, 15 Jul 2020 21:47:45 +0200 Subject: Remove TypeCtor interning Our TypeCtor and Chalk's TypeName match now! --- crates/ra_hir_def/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 b71d626c3..87000fe98 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -159,17 +159,17 @@ pub struct FunctionId(salsa::InternId); type FunctionLoc = AssocItemLoc; impl_intern!(FunctionId, FunctionLoc, intern_function, lookup_intern_function); -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct StructId(salsa::InternId); type StructLoc = ItemLoc; impl_intern!(StructId, StructLoc, intern_struct, lookup_intern_struct); -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct UnionId(salsa::InternId); pub type UnionLoc = ItemLoc; impl_intern!(UnionId, UnionLoc, intern_union, lookup_intern_union); -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct EnumId(salsa::InternId); pub type EnumLoc = ItemLoc; impl_intern!(EnumId, EnumLoc, intern_enum, lookup_intern_enum); @@ -239,7 +239,7 @@ pub enum AssocContainerId { impl_from!(ContainerId for AssocContainerId); /// A Data Type -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum AdtId { StructId(StructId), UnionId(UnionId), -- cgit v1.2.3 From 6636f56e79b55f22b88094b7edaed6ec88880500 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 00:23:03 +0200 Subject: Rename ModuleItem -> Item --- crates/ra_hir_def/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 87000fe98..237b1038a 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -521,7 +521,7 @@ impl AsMacroCall for AstIdWithPath { } } -impl AsMacroCall for AstIdWithPath { +impl AsMacroCall for AstIdWithPath { fn as_call_id( &self, db: &dyn db::DefDatabase, -- cgit v1.2.3