aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-03-02 18:03:32 +0000
committerAleksey Kladov <[email protected]>2020-03-02 18:03:46 +0000
commit1a6f51da66f16a46eb5fd80dc6ea0a2c179d5ff2 (patch)
tree27f3bad75ee1fcbad9ee6e1af8d9305b9c8efa62 /crates
parent2716a1fa3f8a7410248724a6ce5d4c28837db682 (diff)
Simplify: remove couple of useless functions
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/references/classify.rs6
-rw-r--r--crates/ra_ide_db/src/defs.rs30
2 files changed, 13 insertions, 23 deletions
diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs
index e837ca8a3..571236fdc 100644
--- a/crates/ra_ide/src/references/classify.rs
+++ b/crates/ra_ide/src/references/classify.rs
@@ -7,8 +7,6 @@ use ra_prof::profile;
7use ra_syntax::{ast, AstNode}; 7use ra_syntax::{ast, AstNode};
8use test_utils::tested_by; 8use test_utils::tested_by;
9 9
10pub use ra_ide_db::defs::{from_module_def, from_struct_field};
11
12pub enum NameRefClass { 10pub enum NameRefClass {
13 NameDefinition(NameDefinition), 11 NameDefinition(NameDefinition),
14 FieldShorthand { local: Local, field: NameDefinition }, 12 FieldShorthand { local: Local, field: NameDefinition },
@@ -68,14 +66,14 @@ pub(crate) fn classify_name_ref(
68 let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?; 66 let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?;
69 let resolved = sema.resolve_path(&path)?; 67 let resolved = sema.resolve_path(&path)?;
70 let res = match resolved { 68 let res = match resolved {
71 PathResolution::Def(def) => from_module_def(def), 69 PathResolution::Def(def) => NameDefinition::ModuleDef(def),
72 PathResolution::AssocItem(item) => { 70 PathResolution::AssocItem(item) => {
73 let def = match item { 71 let def = match item {
74 hir::AssocItem::Function(it) => it.into(), 72 hir::AssocItem::Function(it) => it.into(),
75 hir::AssocItem::Const(it) => it.into(), 73 hir::AssocItem::Const(it) => it.into(),
76 hir::AssocItem::TypeAlias(it) => it.into(), 74 hir::AssocItem::TypeAlias(it) => it.into(),
77 }; 75 };
78 from_module_def(def) 76 NameDefinition::ModuleDef(def)
79 } 77 }
80 PathResolution::Local(local) => NameDefinition::Local(local), 78 PathResolution::Local(local) => NameDefinition::Local(local),
81 PathResolution::TypeParam(par) => NameDefinition::TypeParam(par), 79 PathResolution::TypeParam(par) => NameDefinition::TypeParam(par),
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs
index ad4638906..7b1030a14 100644
--- a/crates/ra_ide_db/src/defs.rs
+++ b/crates/ra_ide_db/src/defs.rs
@@ -111,47 +111,47 @@ fn classify_name_inner(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Opti
111 }, 111 },
112 ast::RecordFieldDef(it) => { 112 ast::RecordFieldDef(it) => {
113 let field: hir::StructField = sema.to_def(&it)?; 113 let field: hir::StructField = sema.to_def(&it)?;
114 Some(from_struct_field(field)) 114 Some(NameDefinition::StructField(field))
115 }, 115 },
116 ast::Module(it) => { 116 ast::Module(it) => {
117 let def = sema.to_def(&it)?; 117 let def = sema.to_def(&it)?;
118 Some(from_module_def(def.into())) 118 Some(NameDefinition::ModuleDef(def.into()))
119 }, 119 },
120 ast::StructDef(it) => { 120 ast::StructDef(it) => {
121 let def: hir::Struct = sema.to_def(&it)?; 121 let def: hir::Struct = sema.to_def(&it)?;
122 Some(from_module_def(def.into())) 122 Some(NameDefinition::ModuleDef(def.into()))
123 }, 123 },
124 ast::UnionDef(it) => { 124 ast::UnionDef(it) => {
125 let def: hir::Union = sema.to_def(&it)?; 125 let def: hir::Union = sema.to_def(&it)?;
126 Some(from_module_def(def.into())) 126 Some(NameDefinition::ModuleDef(def.into()))
127 }, 127 },
128 ast::EnumDef(it) => { 128 ast::EnumDef(it) => {
129 let def: hir::Enum = sema.to_def(&it)?; 129 let def: hir::Enum = sema.to_def(&it)?;
130 Some(from_module_def(def.into())) 130 Some(NameDefinition::ModuleDef(def.into()))
131 }, 131 },
132 ast::TraitDef(it) => { 132 ast::TraitDef(it) => {
133 let def: hir::Trait = sema.to_def(&it)?; 133 let def: hir::Trait = sema.to_def(&it)?;
134 Some(from_module_def(def.into())) 134 Some(NameDefinition::ModuleDef(def.into()))
135 }, 135 },
136 ast::StaticDef(it) => { 136 ast::StaticDef(it) => {
137 let def: hir::Static = sema.to_def(&it)?; 137 let def: hir::Static = sema.to_def(&it)?;
138 Some(from_module_def(def.into())) 138 Some(NameDefinition::ModuleDef(def.into()))
139 }, 139 },
140 ast::EnumVariant(it) => { 140 ast::EnumVariant(it) => {
141 let def: hir::EnumVariant = sema.to_def(&it)?; 141 let def: hir::EnumVariant = sema.to_def(&it)?;
142 Some(from_module_def(def.into())) 142 Some(NameDefinition::ModuleDef(def.into()))
143 }, 143 },
144 ast::FnDef(it) => { 144 ast::FnDef(it) => {
145 let def: hir::Function = sema.to_def(&it)?; 145 let def: hir::Function = sema.to_def(&it)?;
146 Some(from_module_def(def.into())) 146 Some(NameDefinition::ModuleDef(def.into()))
147 }, 147 },
148 ast::ConstDef(it) => { 148 ast::ConstDef(it) => {
149 let def: hir::Const = sema.to_def(&it)?; 149 let def: hir::Const = sema.to_def(&it)?;
150 Some(from_module_def(def.into())) 150 Some(NameDefinition::ModuleDef(def.into()))
151 }, 151 },
152 ast::TypeAliasDef(it) => { 152 ast::TypeAliasDef(it) => {
153 let def: hir::TypeAlias = sema.to_def(&it)?; 153 let def: hir::TypeAlias = sema.to_def(&it)?;
154 Some(from_module_def(def.into())) 154 Some(NameDefinition::ModuleDef(def.into()))
155 }, 155 },
156 ast::MacroCall(it) => { 156 ast::MacroCall(it) => {
157 let def = sema.to_def(&it)?; 157 let def = sema.to_def(&it)?;
@@ -165,11 +165,3 @@ fn classify_name_inner(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Opti
165 } 165 }
166 } 166 }
167} 167}
168
169pub fn from_struct_field(field: StructField) -> NameDefinition {
170 NameDefinition::StructField(field)
171}
172
173pub fn from_module_def(def: ModuleDef) -> NameDefinition {
174 NameDefinition::ModuleDef(def)
175}