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_ty/src/infer.rs | 7 +++---- crates/ra_hir_ty/src/lib.rs | 19 ------------------- crates/ra_hir_ty/src/lower.rs | 13 ++++++------- 3 files changed, 9 insertions(+), 30 deletions(-) (limited to 'crates/ra_hir_ty') diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index 5c56c2eb0..2ce4f65cc 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs @@ -18,8 +18,6 @@ use std::mem; use std::ops::Index; use std::sync::Arc; -use rustc_hash::FxHashMap; - use hir_def::{ body::Body, data::{ConstData, FunctionData, StaticData}, @@ -35,6 +33,8 @@ use hir_expand::{diagnostics::DiagnosticSink, name::name}; use ra_arena::map::ArenaMap; use ra_prof::profile; use ra_syntax::SmolStr; +use rustc_hash::FxHashMap; +use stdx::impl_from; use super::{ primitive::{FloatTy, IntTy}, @@ -84,8 +84,7 @@ enum ExprOrPatId { ExprId(ExprId), PatId(PatId), } - -impl_froms!(ExprOrPatId: ExprId, PatId); +impl_from!(ExprId, PatId for ExprOrPatId); /// Binding modes inferred for patterns. /// https://doc.rust-lang.org/reference/patterns.html#binding-modes diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 34f0bd4ce..2652d200f 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs @@ -6,25 +6,6 @@ macro_rules! eprintln { ($($tt:tt)*) => { stdx::eprintln!($($tt)*) }; } -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)) - } - } - )*)? - )* - } -} - mod autoderef; pub mod primitive; pub mod traits; diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs index 3af8d55a1..101b8aebe 100644 --- a/crates/ra_hir_ty/src/lower.rs +++ b/crates/ra_hir_ty/src/lower.rs @@ -5,10 +5,7 @@ //! - Building the type for an item: This happens through the `type_for_def` query. //! //! This usually involves resolving names, collecting generic arguments etc. -use std::iter; -use std::sync::Arc; - -use smallvec::SmallVec; +use std::{iter, sync::Arc}; use hir_def::{ adt::StructKind, @@ -24,6 +21,8 @@ use hir_def::{ use hir_expand::name::Name; use ra_arena::map::ArenaMap; use ra_db::CrateId; +use smallvec::SmallVec; +use stdx::impl_from; use test_utils::mark; use crate::{ @@ -1110,7 +1109,7 @@ pub enum CallableDef { StructId(StructId), EnumVariantId(EnumVariantId), } -impl_froms!(CallableDef: FunctionId, StructId, EnumVariantId); +impl_from!(FunctionId, StructId, EnumVariantId for CallableDef); impl CallableDef { pub fn krate(self, db: &dyn HirDatabase) -> CrateId { @@ -1140,7 +1139,7 @@ pub enum TyDefId { AdtId(AdtId), TypeAliasId(TypeAliasId), } -impl_froms!(TyDefId: BuiltinType, AdtId(StructId, EnumId, UnionId), TypeAliasId); +impl_from!(BuiltinType, AdtId(StructId, EnumId, UnionId), TypeAliasId for TyDefId); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum ValueTyDefId { @@ -1150,7 +1149,7 @@ pub enum ValueTyDefId { ConstId(ConstId), StaticId(StaticId), } -impl_froms!(ValueTyDefId: FunctionId, StructId, EnumVariantId, ConstId, StaticId); +impl_from!(FunctionId, StructId, EnumVariantId, ConstId, StaticId for ValueTyDefId); /// Build the declared type of an item. This depends on the namespace; e.g. for /// `struct Foo(usize)`, we have two types: The type of the struct itself, and -- cgit v1.2.3