aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-06-11 16:07:42 +0100
committerAleksey Kladov <[email protected]>2019-06-11 16:28:51 +0100
commit26753f0e4931e2980f008015cbd709a77d71c0f3 (patch)
tree592b8d2c83687540f62c65bb045c94e7b0e1f0e9
parent0dcaded439ae4bd4670bc6a2fbf739cd4fce60af (diff)
remove unneded From(..) impl
-rw-r--r--crates/ra_hir/src/adt.rs11
-rw-r--r--crates/ra_hir/src/code_model/src.rs32
-rw-r--r--crates/ra_hir/src/ids.rs6
-rw-r--r--crates/ra_hir/src/impl_block.rs9
4 files changed, 21 insertions, 37 deletions
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::{
11 11
12use crate::{ 12use crate::{
13 Name, AsName, Struct, Union, Enum, EnumVariant, Crate, AstDatabase, 13 Name, AsName, Struct, Union, Enum, EnumVariant, Crate, AstDatabase,
14 HirDatabase, HirFileId, StructField, FieldSource, Source, HasSource, 14 HirDatabase, StructField, FieldSource, Source, HasSource,
15 type_ref::TypeRef, DefDatabase, 15 type_ref::TypeRef, DefDatabase,
16}; 16};
17 17
@@ -201,10 +201,7 @@ impl VariantDef {
201} 201}
202 202
203impl StructField { 203impl StructField {
204 pub(crate) fn source_impl( 204 pub(crate) fn source_impl(&self, db: &(impl DefDatabase + AstDatabase)) -> Source<FieldSource> {
205 &self,
206 db: &(impl DefDatabase + AstDatabase),
207 ) -> (HirFileId, FieldSource) {
208 let var_data = self.parent.variant_data(db); 205 let var_data = self.parent.variant_data(db);
209 let fields = var_data.fields().unwrap(); 206 let fields = var_data.fields().unwrap();
210 let ss; 207 let ss;
@@ -229,12 +226,12 @@ impl StructField {
229 } 226 }
230 ast::StructKind::Unit => Vec::new(), 227 ast::StructKind::Unit => Vec::new(),
231 }; 228 };
232 let field = field_sources 229 let ast = field_sources
233 .into_iter() 230 .into_iter()
234 .zip(fields.iter()) 231 .zip(fields.iter())
235 .find(|(_syntax, (id, _))| *id == self.id) 232 .find(|(_syntax, (id, _))| *id == self.id)
236 .unwrap() 233 .unwrap()
237 .0; 234 .0;
238 (file_id, field) 235 Source { file_id, ast }
239 } 236 }
240} 237}
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> {
11 pub ast: T, 11 pub ast: T,
12} 12}
13 13
14impl<T> From<(HirFileId, T)> for Source<T> {
15 fn from((file_id, ast): (HirFileId, T)) -> Self {
16 Source { file_id, ast }
17 }
18}
19
20pub trait HasSource { 14pub trait HasSource {
21 type Ast; 15 type Ast;
22 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<Self::Ast>; 16 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<Self::Ast>;
@@ -30,9 +24,9 @@ impl Module {
30 let def_map = db.crate_def_map(self.krate); 24 let def_map = db.crate_def_map(self.krate);
31 let decl_id = def_map[self.module_id].declaration; 25 let decl_id = def_map[self.module_id].declaration;
32 let file_id = def_map[self.module_id].definition; 26 let file_id = def_map[self.module_id].definition;
33 let module_source = ModuleSource::new(db, file_id, decl_id); 27 let ast = ModuleSource::new(db, file_id, decl_id);
34 let file_id = file_id.map(HirFileId::from).unwrap_or_else(|| decl_id.unwrap().file_id()); 28 let file_id = file_id.map(HirFileId::from).unwrap_or_else(|| decl_id.unwrap().file_id());
35 (file_id, module_source).into() 29 Source { file_id, ast }
36 } 30 }
37 31
38 /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. 32 /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`.
@@ -44,32 +38,32 @@ impl Module {
44 let def_map = db.crate_def_map(self.krate); 38 let def_map = db.crate_def_map(self.krate);
45 let decl = def_map[self.module_id].declaration?; 39 let decl = def_map[self.module_id].declaration?;
46 let ast = decl.to_node(db); 40 let ast = decl.to_node(db);
47 Some((decl.file_id(), ast).into()) 41 Some(Source { file_id: decl.file_id(), ast })
48 } 42 }
49} 43}
50 44
51impl HasSource for StructField { 45impl HasSource for StructField {
52 type Ast = FieldSource; 46 type Ast = FieldSource;
53 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<FieldSource> { 47 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<FieldSource> {
54 self.source_impl(db).into() 48 self.source_impl(db)
55 } 49 }
56} 50}
57impl HasSource for Struct { 51impl HasSource for Struct {
58 type Ast = TreeArc<ast::StructDef>; 52 type Ast = TreeArc<ast::StructDef>;
59 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> { 53 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
60 self.id.source(db).into() 54 self.id.source(db)
61 } 55 }
62} 56}
63impl HasSource for Union { 57impl HasSource for Union {
64 type Ast = TreeArc<ast::StructDef>; 58 type Ast = TreeArc<ast::StructDef>;
65 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> { 59 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
66 self.id.source(db).into() 60 self.id.source(db)
67 } 61 }
68} 62}
69impl HasSource for Enum { 63impl HasSource for Enum {
70 type Ast = TreeArc<ast::EnumDef>; 64 type Ast = TreeArc<ast::EnumDef>;
71 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> { 65 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> {
72 self.id.source(db).into() 66 self.id.source(db)
73 } 67 }
74} 68}
75impl HasSource for EnumVariant { 69impl HasSource for EnumVariant {
@@ -82,39 +76,39 @@ impl HasSource for Function {
82 type Ast = TreeArc<ast::FnDef>; 76 type Ast = TreeArc<ast::FnDef>;
83 77
84 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::FnDef>> { 78 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::FnDef>> {
85 self.id.source(db).into() 79 self.id.source(db)
86 } 80 }
87} 81}
88impl HasSource for Const { 82impl HasSource for Const {
89 type Ast = TreeArc<ast::ConstDef>; 83 type Ast = TreeArc<ast::ConstDef>;
90 84
91 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ConstDef>> { 85 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ConstDef>> {
92 self.id.source(db).into() 86 self.id.source(db)
93 } 87 }
94} 88}
95impl HasSource for Static { 89impl HasSource for Static {
96 type Ast = TreeArc<ast::StaticDef>; 90 type Ast = TreeArc<ast::StaticDef>;
97 91
98 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StaticDef>> { 92 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StaticDef>> {
99 self.id.source(db).into() 93 self.id.source(db)
100 } 94 }
101} 95}
102impl HasSource for Trait { 96impl HasSource for Trait {
103 type Ast = TreeArc<ast::TraitDef>; 97 type Ast = TreeArc<ast::TraitDef>;
104 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TraitDef>> { 98 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TraitDef>> {
105 self.id.source(db).into() 99 self.id.source(db)
106 } 100 }
107} 101}
108impl HasSource for TypeAlias { 102impl HasSource for TypeAlias {
109 type Ast = TreeArc<ast::TypeAliasDef>; 103 type Ast = TreeArc<ast::TypeAliasDef>;
110 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TypeAliasDef>> { 104 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TypeAliasDef>> {
111 self.id.source(db).into() 105 self.id.source(db)
112 } 106 }
113} 107}
114impl HasSource for MacroDef { 108impl HasSource for MacroDef {
115 type Ast = TreeArc<ast::MacroCall>; 109 type Ast = TreeArc<ast::MacroCall>;
116 110
117 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::MacroCall>> { 111 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::MacroCall>> {
118 (self.id.0.file_id(), self.id.0.to_node(db)).into() 112 Source { file_id: self.id.0.file_id(), ast: self.id.0.to_node(db) }
119 } 113 }
120} 114}
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;
9use mbe::MacroRules; 9use mbe::MacroRules;
10 10
11use crate::{ 11use crate::{
12 Module, DefDatabase, AstId, FileAstId, AstDatabase, 12 Module, DefDatabase, AstId, FileAstId, AstDatabase, Source,
13}; 13};
14 14
15/// hir makes heavy use of ids: integer (u32) handlers to various things. You 15/// 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 {
265 let loc = ItemLoc { module: ctx.module, ast_id: ast_id.with_file_id(ctx.file_id) }; 265 let loc = ItemLoc { module: ctx.module, ast_id: ast_id.with_file_id(ctx.file_id) };
266 Self::intern(ctx.db, loc) 266 Self::intern(ctx.db, loc)
267 } 267 }
268 fn source(self, db: &(impl AstDatabase + DefDatabase)) -> (HirFileId, TreeArc<N>) { 268 fn source(self, db: &(impl AstDatabase + DefDatabase)) -> Source<TreeArc<N>> {
269 let loc = self.lookup_intern(db); 269 let loc = self.lookup_intern(db);
270 let ast = loc.ast_id.to_node(db); 270 let ast = loc.ast_id.to_node(db);
271 (loc.ast_id.file_id(), ast) 271 Source { file_id: loc.ast_id.file_id(), ast }
272 } 272 }
273 fn module(self, db: &impl DefDatabase) -> Module { 273 fn module(self, db: &impl DefDatabase) -> Module {
274 let loc = self.lookup_intern(db); 274 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 {
49 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ImplBlock>> { 49 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ImplBlock>> {
50 let source_map = db.impls_in_module_with_source_map(self.module).1; 50 let source_map = db.impls_in_module_with_source_map(self.module).1;
51 let src = self.module.definition_source(db); 51 let src = self.module.definition_source(db);
52 (src.file_id, source_map.get(&src.ast, self.impl_id)).into() 52 Source { file_id: src.file_id, ast: source_map.get(&src.ast, self.impl_id) }
53 } 53 }
54} 54}
55 55
@@ -66,13 +66,6 @@ impl ImplBlock {
66 ImplBlock { module, impl_id } 66 ImplBlock { module, impl_id }
67 } 67 }
68 68
69 /// Returns the syntax of the impl block
70 pub fn source(&self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ImplBlock>> {
71 let source_map = db.impls_in_module_with_source_map(self.module).1;
72 let src = self.module.definition_source(db);
73 (src.file_id, source_map.get(&src.ast, self.impl_id)).into()
74 }
75
76 pub fn id(&self) -> ImplId { 69 pub fn id(&self) -> ImplId {
77 self.impl_id 70 self.impl_id
78 } 71 }