From 26753f0e4931e2980f008015cbd709a77d71c0f3 Mon Sep 17 00:00:00 2001
From: Aleksey Kladov <aleksey.kladov@gmail.com>
Date: Tue, 11 Jun 2019 18:07:42 +0300
Subject: remove unneded From(..) impl

---
 crates/ra_hir/src/adt.rs            | 11 ++++-------
 crates/ra_hir/src/code_model/src.rs | 32 +++++++++++++-------------------
 crates/ra_hir/src/ids.rs            |  6 +++---
 crates/ra_hir/src/impl_block.rs     |  9 +--------
 4 files changed, 21 insertions(+), 37 deletions(-)

(limited to 'crates/ra_hir/src')

diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index 6b8604b3e..b3843b35c 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -11,7 +11,7 @@ use ra_syntax::{
 
 use crate::{
     Name, AsName, Struct, Union, Enum, EnumVariant, Crate, AstDatabase,
-    HirDatabase, HirFileId, StructField, FieldSource, Source, HasSource,
+    HirDatabase, StructField, FieldSource, Source, HasSource,
     type_ref::TypeRef, DefDatabase,
 };
 
@@ -201,10 +201,7 @@ impl VariantDef {
 }
 
 impl StructField {
-    pub(crate) fn source_impl(
-        &self,
-        db: &(impl DefDatabase + AstDatabase),
-    ) -> (HirFileId, FieldSource) {
+    pub(crate) fn source_impl(&self, db: &(impl DefDatabase + AstDatabase)) -> Source<FieldSource> {
         let var_data = self.parent.variant_data(db);
         let fields = var_data.fields().unwrap();
         let ss;
@@ -229,12 +226,12 @@ impl StructField {
             }
             ast::StructKind::Unit => Vec::new(),
         };
-        let field = field_sources
+        let ast = field_sources
             .into_iter()
             .zip(fields.iter())
             .find(|(_syntax, (id, _))| *id == self.id)
             .unwrap()
             .0;
-        (file_id, field)
+        Source { file_id, ast }
     }
 }
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs
index 7484faf04..7d8abb39e 100644
--- a/crates/ra_hir/src/code_model/src.rs
+++ b/crates/ra_hir/src/code_model/src.rs
@@ -11,12 +11,6 @@ pub struct Source<T> {
     pub ast: T,
 }
 
-impl<T> From<(HirFileId, T)> for Source<T> {
-    fn from((file_id, ast): (HirFileId, T)) -> Self {
-        Source { file_id, ast }
-    }
-}
-
 pub trait HasSource {
     type Ast;
     fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<Self::Ast>;
@@ -30,9 +24,9 @@ impl Module {
         let def_map = db.crate_def_map(self.krate);
         let decl_id = def_map[self.module_id].declaration;
         let file_id = def_map[self.module_id].definition;
-        let module_source = ModuleSource::new(db, file_id, decl_id);
+        let ast = ModuleSource::new(db, file_id, decl_id);
         let file_id = file_id.map(HirFileId::from).unwrap_or_else(|| decl_id.unwrap().file_id());
-        (file_id, module_source).into()
+        Source { file_id, ast }
     }
 
     /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`.
@@ -44,32 +38,32 @@ impl Module {
         let def_map = db.crate_def_map(self.krate);
         let decl = def_map[self.module_id].declaration?;
         let ast = decl.to_node(db);
-        Some((decl.file_id(), ast).into())
+        Some(Source { file_id: decl.file_id(), ast })
     }
 }
 
 impl HasSource for StructField {
     type Ast = FieldSource;
     fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<FieldSource> {
-        self.source_impl(db).into()
+        self.source_impl(db)
     }
 }
 impl HasSource for Struct {
     type Ast = TreeArc<ast::StructDef>;
     fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
-        self.id.source(db).into()
+        self.id.source(db)
     }
 }
 impl HasSource for Union {
     type Ast = TreeArc<ast::StructDef>;
     fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
-        self.id.source(db).into()
+        self.id.source(db)
     }
 }
 impl HasSource for Enum {
     type Ast = TreeArc<ast::EnumDef>;
     fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> {
-        self.id.source(db).into()
+        self.id.source(db)
     }
 }
 impl HasSource for EnumVariant {
@@ -82,39 +76,39 @@ impl HasSource for Function {
     type Ast = TreeArc<ast::FnDef>;
 
     fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::FnDef>> {
-        self.id.source(db).into()
+        self.id.source(db)
     }
 }
 impl HasSource for Const {
     type Ast = TreeArc<ast::ConstDef>;
 
     fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ConstDef>> {
-        self.id.source(db).into()
+        self.id.source(db)
     }
 }
 impl HasSource for Static {
     type Ast = TreeArc<ast::StaticDef>;
 
     fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StaticDef>> {
-        self.id.source(db).into()
+        self.id.source(db)
     }
 }
 impl HasSource for Trait {
     type Ast = TreeArc<ast::TraitDef>;
     fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TraitDef>> {
-        self.id.source(db).into()
+        self.id.source(db)
     }
 }
 impl HasSource for TypeAlias {
     type Ast = TreeArc<ast::TypeAliasDef>;
     fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TypeAliasDef>> {
-        self.id.source(db).into()
+        self.id.source(db)
     }
 }
 impl HasSource for MacroDef {
     type Ast = TreeArc<ast::MacroCall>;
 
     fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::MacroCall>> {
-        (self.id.0.file_id(), self.id.0.to_node(db)).into()
+        Source { file_id: self.id.0.file_id(), ast: self.id.0.to_node(db) }
     }
 }
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index a95561812..352f9ffd9 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -9,7 +9,7 @@ use ra_prof::profile;
 use mbe::MacroRules;
 
 use crate::{
-    Module, DefDatabase, AstId, FileAstId, AstDatabase,
+    Module, DefDatabase, AstId, FileAstId, AstDatabase, Source,
 };
 
 /// hir makes heavy use of ids: integer (u32) handlers to various things. You
@@ -265,10 +265,10 @@ pub(crate) trait AstItemDef<N: AstNode>: salsa::InternKey + Clone {
         let loc = ItemLoc { module: ctx.module, ast_id: ast_id.with_file_id(ctx.file_id) };
         Self::intern(ctx.db, loc)
     }
-    fn source(self, db: &(impl AstDatabase + DefDatabase)) -> (HirFileId, TreeArc<N>) {
+    fn source(self, db: &(impl AstDatabase + DefDatabase)) -> Source<TreeArc<N>> {
         let loc = self.lookup_intern(db);
         let ast = loc.ast_id.to_node(db);
-        (loc.ast_id.file_id(), ast)
+        Source { file_id: loc.ast_id.file_id(), ast }
     }
     fn module(self, db: &impl DefDatabase) -> Module {
         let loc = self.lookup_intern(db);
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index 646b603d3..fb9daf1bf 100644
--- a/crates/ra_hir/src/impl_block.rs
+++ b/crates/ra_hir/src/impl_block.rs
@@ -49,7 +49,7 @@ impl HasSource for ImplBlock {
     fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ImplBlock>> {
         let source_map = db.impls_in_module_with_source_map(self.module).1;
         let src = self.module.definition_source(db);
-        (src.file_id, source_map.get(&src.ast, self.impl_id)).into()
+        Source { file_id: src.file_id, ast: source_map.get(&src.ast, self.impl_id) }
     }
 }
 
@@ -66,13 +66,6 @@ impl ImplBlock {
         ImplBlock { module, impl_id }
     }
 
-    /// Returns the syntax of the impl block
-    pub fn source(&self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ImplBlock>> {
-        let source_map = db.impls_in_module_with_source_map(self.module).1;
-        let src = self.module.definition_source(db);
-        (src.file_id, source_map.get(&src.ast, self.impl_id)).into()
-    }
-
     pub fn id(&self) -> ImplId {
         self.impl_id
     }
-- 
cgit v1.2.3