Skip to content

Commit f55be75

Browse files
committed
Remove irrelevant distinction
1 parent 4d0d113 commit f55be75

File tree

6 files changed

+22
-48
lines changed

6 files changed

+22
-48
lines changed

crates/ra_ide/src/goto_definition.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ pub(crate) fn reference_definition(
7878
Some(Macro(it)) => return Exact(it.to_nav(sb.db)),
7979
Some(Field(it)) => return Exact(it.to_nav(sb.db)),
8080
Some(TypeParam(it)) => return Exact(it.to_nav(sb.db)),
81-
Some(AssocItem(it)) => return Exact(it.to_nav(sb.db)),
8281
Some(Local(it)) => return Exact(it.to_nav(sb.db)),
8382
Some(Def(def)) => match NavigationTarget::from_def(sb.db, def) {
8483
Some(nav) => return Exact(nav),

crates/ra_ide/src/hover.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,6 @@ fn hover_text_from_name_kind(db: &RootDatabase, name_kind: NameKind) -> Option<S
105105
_ => None,
106106
}
107107
}
108-
AssocItem(it) => match it {
109-
hir::AssocItem::Function(it) => from_def_source(db, it),
110-
hir::AssocItem::Const(it) => from_def_source(db, it),
111-
hir::AssocItem::TypeAlias(it) => from_def_source(db, it),
112-
},
113108
Def(it) => match it {
114109
hir::ModuleDef::Module(it) => match it.definition_source(db).value {
115110
hir::ModuleSource::Module(it) => {

crates/ra_ide/src/references.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ pub(crate) fn find_all_refs(
128128
let declaration = match def.kind {
129129
NameKind::Macro(mac) => mac.to_nav(db),
130130
NameKind::Field(field) => field.to_nav(db),
131-
NameKind::AssocItem(assoc) => assoc.to_nav(db),
132131
NameKind::Def(def) => NavigationTarget::from_def(db, def)?,
133132
NameKind::SelfType(imp) => imp.to_nav(db),
134133
NameKind::Local(local) => local.to_nav(db),

crates/ra_ide/src/references/classify.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use test_utils::tested_by;
88
use super::{NameDefinition, NameKind};
99
use ra_ide_db::RootDatabase;
1010

11-
pub use ra_ide_db::defs::{classify_name, from_assoc_item, from_module_def, from_struct_field};
11+
pub use ra_ide_db::defs::{classify_name, from_module_def, from_struct_field};
1212

1313
pub(crate) fn classify_name_ref(
1414
sb: &mut SourceBinder<RootDatabase>,
@@ -22,7 +22,7 @@ pub(crate) fn classify_name_ref(
2222
if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) {
2323
tested_by!(goto_def_for_methods);
2424
if let Some(func) = analyzer.resolve_method_call(&method_call) {
25-
return Some(from_assoc_item(sb.db, func.into()));
25+
return Some(from_module_def(sb.db, func.into(), None));
2626
}
2727
}
2828

@@ -57,27 +57,35 @@ pub(crate) fn classify_name_ref(
5757

5858
let path = name_ref.value.syntax().ancestors().find_map(ast::Path::cast)?;
5959
let resolved = analyzer.resolve_path(sb.db, &path)?;
60-
match resolved {
61-
PathResolution::Def(def) => Some(from_module_def(sb.db, def, Some(container))),
62-
PathResolution::AssocItem(item) => Some(from_assoc_item(sb.db, item)),
60+
let res = match resolved {
61+
PathResolution::Def(def) => from_module_def(sb.db, def, Some(container)),
62+
PathResolution::AssocItem(item) => {
63+
let def = match item {
64+
hir::AssocItem::Function(it) => it.into(),
65+
hir::AssocItem::Const(it) => it.into(),
66+
hir::AssocItem::TypeAlias(it) => it.into(),
67+
};
68+
from_module_def(sb.db, def, Some(container))
69+
}
6370
PathResolution::Local(local) => {
6471
let kind = NameKind::Local(local);
6572
let container = local.module(sb.db);
66-
Some(NameDefinition { kind, container, visibility: None })
73+
NameDefinition { kind, container, visibility: None }
6774
}
6875
PathResolution::TypeParam(par) => {
6976
let kind = NameKind::TypeParam(par);
7077
let container = par.module(sb.db);
71-
Some(NameDefinition { kind, container, visibility })
78+
NameDefinition { kind, container, visibility }
7279
}
7380
PathResolution::Macro(def) => {
7481
let kind = NameKind::Macro(def);
75-
Some(NameDefinition { kind, container, visibility })
82+
NameDefinition { kind, container, visibility }
7683
}
7784
PathResolution::SelfType(impl_block) => {
7885
let kind = NameKind::SelfType(impl_block);
7986
let container = impl_block.module(sb.db);
80-
Some(NameDefinition { kind, container, visibility })
87+
NameDefinition { kind, container, visibility }
8188
}
82-
}
89+
};
90+
Some(res)
8391
}

crates/ra_ide/src/syntax_highlighting.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,6 @@ fn highlight_name(db: &RootDatabase, name_kind: NameKind) -> &'static str {
321321
match name_kind {
322322
Macro(_) => tags::MACRO,
323323
Field(_) => tags::FIELD,
324-
AssocItem(hir::AssocItem::Function(_)) => tags::FUNCTION,
325-
AssocItem(hir::AssocItem::Const(_)) => tags::CONSTANT,
326-
AssocItem(hir::AssocItem::TypeAlias(_)) => tags::TYPE,
327324
Def(hir::ModuleDef::Module(_)) => tags::MODULE,
328325
Def(hir::ModuleDef::Function(_)) => tags::FUNCTION,
329326
Def(hir::ModuleDef::Adt(_)) => tags::TYPE,

crates/ra_ide_db/src/defs.rs

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// FIXME: this badly needs rename/rewrite (matklad, 2020-02-06).
77

88
use hir::{
9-
Adt, AssocItem, HasSource, ImplBlock, InFile, Local, MacroDef, Module, ModuleDef, SourceBinder,
9+
Adt, HasSource, ImplBlock, InFile, Local, MacroDef, Module, ModuleDef, SourceBinder,
1010
StructField, TypeParam, VariantDef,
1111
};
1212
use ra_prof::profile;
@@ -21,7 +21,6 @@ use crate::RootDatabase;
2121
pub enum NameKind {
2222
Macro(MacroDef),
2323
Field(StructField),
24-
AssocItem(AssocItem),
2524
Def(ModuleDef),
2625
SelfType(ImplBlock),
2726
Local(Local),
@@ -92,29 +91,17 @@ pub fn classify_name(
9291
ast::FnDef(it) => {
9392
let src = name.with_value(it);
9493
let def: hir::Function = sb.to_def(src)?;
95-
if parent.parent().and_then(ast::ItemList::cast).map_or(false, |it| it.syntax().parent().and_then(ast::Module::cast).is_none()) {
96-
Some(from_assoc_item(sb.db, def.into()))
97-
} else {
98-
Some(from_module_def(sb.db, def.into(), None))
99-
}
94+
Some(from_module_def(sb.db, def.into(), None))
10095
},
10196
ast::ConstDef(it) => {
10297
let src = name.with_value(it);
10398
let def: hir::Const = sb.to_def(src)?;
104-
if parent.parent().and_then(ast::ItemList::cast).is_some() {
105-
Some(from_assoc_item(sb.db, def.into()))
106-
} else {
107-
Some(from_module_def(sb.db, def.into(), None))
108-
}
99+
Some(from_module_def(sb.db, def.into(), None))
109100
},
110101
ast::TypeAliasDef(it) => {
111102
let src = name.with_value(it);
112103
let def: hir::TypeAlias = sb.to_def(src)?;
113-
if parent.parent().and_then(ast::ItemList::cast).is_some() {
114-
Some(from_assoc_item(sb.db, def.into()))
115-
} else {
116-
Some(from_module_def(sb.db, def.into(), None))
117-
}
104+
Some(from_module_def(sb.db, def.into(), None))
118105
},
119106
ast::MacroCall(it) => {
120107
let src = name.with_value(it);
@@ -142,17 +129,6 @@ pub fn classify_name(
142129
}
143130
}
144131

145-
pub fn from_assoc_item(db: &RootDatabase, item: AssocItem) -> NameDefinition {
146-
let container = item.module(db);
147-
let visibility = match item {
148-
AssocItem::Function(f) => f.source(db).value.visibility(),
149-
AssocItem::Const(c) => c.source(db).value.visibility(),
150-
AssocItem::TypeAlias(a) => a.source(db).value.visibility(),
151-
};
152-
let kind = NameKind::AssocItem(item);
153-
NameDefinition { kind, container, visibility }
154-
}
155-
156132
pub fn from_struct_field(db: &RootDatabase, field: StructField) -> NameDefinition {
157133
let kind = NameKind::Field(field);
158134
let parent = field.parent_def(db);

0 commit comments

Comments
 (0)