3406: Simplify: remove couple of useless functions r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-03-02 18:09:00 +00:00 committed by GitHub
commit a484e9c730
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 23 deletions

View file

@ -7,8 +7,6 @@ use ra_prof::profile;
use ra_syntax::{ast, AstNode}; use ra_syntax::{ast, AstNode};
use test_utils::tested_by; use test_utils::tested_by;
pub use ra_ide_db::defs::{from_module_def, from_struct_field};
pub enum NameRefClass { pub enum NameRefClass {
NameDefinition(NameDefinition), NameDefinition(NameDefinition),
FieldShorthand { local: Local, field: NameDefinition }, FieldShorthand { local: Local, field: NameDefinition },
@ -68,14 +66,14 @@ pub(crate) fn classify_name_ref(
let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?; let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?;
let resolved = sema.resolve_path(&path)?; let resolved = sema.resolve_path(&path)?;
let res = match resolved { let res = match resolved {
PathResolution::Def(def) => from_module_def(def), PathResolution::Def(def) => NameDefinition::ModuleDef(def),
PathResolution::AssocItem(item) => { PathResolution::AssocItem(item) => {
let def = match item { let def = match item {
hir::AssocItem::Function(it) => it.into(), hir::AssocItem::Function(it) => it.into(),
hir::AssocItem::Const(it) => it.into(), hir::AssocItem::Const(it) => it.into(),
hir::AssocItem::TypeAlias(it) => it.into(), hir::AssocItem::TypeAlias(it) => it.into(),
}; };
from_module_def(def) NameDefinition::ModuleDef(def)
} }
PathResolution::Local(local) => NameDefinition::Local(local), PathResolution::Local(local) => NameDefinition::Local(local),
PathResolution::TypeParam(par) => NameDefinition::TypeParam(par), PathResolution::TypeParam(par) => NameDefinition::TypeParam(par),

View file

@ -111,47 +111,47 @@ fn classify_name_inner(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Opti
}, },
ast::RecordFieldDef(it) => { ast::RecordFieldDef(it) => {
let field: hir::StructField = sema.to_def(&it)?; let field: hir::StructField = sema.to_def(&it)?;
Some(from_struct_field(field)) Some(NameDefinition::StructField(field))
}, },
ast::Module(it) => { ast::Module(it) => {
let def = sema.to_def(&it)?; let def = sema.to_def(&it)?;
Some(from_module_def(def.into())) Some(NameDefinition::ModuleDef(def.into()))
}, },
ast::StructDef(it) => { ast::StructDef(it) => {
let def: hir::Struct = sema.to_def(&it)?; let def: hir::Struct = sema.to_def(&it)?;
Some(from_module_def(def.into())) Some(NameDefinition::ModuleDef(def.into()))
}, },
ast::UnionDef(it) => { ast::UnionDef(it) => {
let def: hir::Union = sema.to_def(&it)?; let def: hir::Union = sema.to_def(&it)?;
Some(from_module_def(def.into())) Some(NameDefinition::ModuleDef(def.into()))
}, },
ast::EnumDef(it) => { ast::EnumDef(it) => {
let def: hir::Enum = sema.to_def(&it)?; let def: hir::Enum = sema.to_def(&it)?;
Some(from_module_def(def.into())) Some(NameDefinition::ModuleDef(def.into()))
}, },
ast::TraitDef(it) => { ast::TraitDef(it) => {
let def: hir::Trait = sema.to_def(&it)?; let def: hir::Trait = sema.to_def(&it)?;
Some(from_module_def(def.into())) Some(NameDefinition::ModuleDef(def.into()))
}, },
ast::StaticDef(it) => { ast::StaticDef(it) => {
let def: hir::Static = sema.to_def(&it)?; let def: hir::Static = sema.to_def(&it)?;
Some(from_module_def(def.into())) Some(NameDefinition::ModuleDef(def.into()))
}, },
ast::EnumVariant(it) => { ast::EnumVariant(it) => {
let def: hir::EnumVariant = sema.to_def(&it)?; let def: hir::EnumVariant = sema.to_def(&it)?;
Some(from_module_def(def.into())) Some(NameDefinition::ModuleDef(def.into()))
}, },
ast::FnDef(it) => { ast::FnDef(it) => {
let def: hir::Function = sema.to_def(&it)?; let def: hir::Function = sema.to_def(&it)?;
Some(from_module_def(def.into())) Some(NameDefinition::ModuleDef(def.into()))
}, },
ast::ConstDef(it) => { ast::ConstDef(it) => {
let def: hir::Const = sema.to_def(&it)?; let def: hir::Const = sema.to_def(&it)?;
Some(from_module_def(def.into())) Some(NameDefinition::ModuleDef(def.into()))
}, },
ast::TypeAliasDef(it) => { ast::TypeAliasDef(it) => {
let def: hir::TypeAlias = sema.to_def(&it)?; let def: hir::TypeAlias = sema.to_def(&it)?;
Some(from_module_def(def.into())) Some(NameDefinition::ModuleDef(def.into()))
}, },
ast::MacroCall(it) => { ast::MacroCall(it) => {
let def = sema.to_def(&it)?; let def = sema.to_def(&it)?;
@ -165,11 +165,3 @@ fn classify_name_inner(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Opti
} }
} }
} }
pub fn from_struct_field(field: StructField) -> NameDefinition {
NameDefinition::StructField(field)
}
pub fn from_module_def(def: ModuleDef) -> NameDefinition {
NameDefinition::ModuleDef(def)
}