2610: Reduce copy-paste some more r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-12-20 12:58:55 +00:00 committed by GitHub
commit a2ce8ab275
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 87 deletions

View File

@ -366,19 +366,7 @@ impl HasModule for AssocContainerId {
}
}
impl HasModule for FunctionLoc {
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
self.container.module(db)
}
}
impl HasModule for TypeAliasLoc {
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
self.container.module(db)
}
}
impl HasModule for ConstLoc {
impl<N: AstNode> HasModule for AssocItemLoc<N> {
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
self.container.module(db)
}

View File

@ -2,94 +2,28 @@
use hir_expand::InFile;
use ra_arena::map::ArenaMap;
use ra_syntax::ast;
use ra_syntax::AstNode;
use crate::{
db::DefDatabase, ConstLoc, EnumLoc, FunctionLoc, ImplLoc, StaticLoc, StructLoc, TraitLoc,
TypeAliasLoc, UnionLoc,
};
use crate::{db::DefDatabase, AssocItemLoc, ItemLoc};
pub trait HasSource {
type Value;
fn source(&self, db: &impl DefDatabase) -> InFile<Self::Value>;
}
impl HasSource for FunctionLoc {
type Value = ast::FnDef;
impl<N: AstNode> HasSource for AssocItemLoc<N> {
type Value = N;
fn source(&self, db: &impl DefDatabase) -> InFile<ast::FnDef> {
fn source(&self, db: &impl DefDatabase) -> InFile<N> {
let node = self.ast_id.to_node(db);
InFile::new(self.ast_id.file_id, node)
}
}
impl HasSource for TypeAliasLoc {
type Value = ast::TypeAliasDef;
impl<N: AstNode> HasSource for ItemLoc<N> {
type Value = N;
fn source(&self, db: &impl DefDatabase) -> InFile<ast::TypeAliasDef> {
let node = self.ast_id.to_node(db);
InFile::new(self.ast_id.file_id, node)
}
}
impl HasSource for ConstLoc {
type Value = ast::ConstDef;
fn source(&self, db: &impl DefDatabase) -> InFile<ast::ConstDef> {
let node = self.ast_id.to_node(db);
InFile::new(self.ast_id.file_id, node)
}
}
impl HasSource for StaticLoc {
type Value = ast::StaticDef;
fn source(&self, db: &impl DefDatabase) -> InFile<ast::StaticDef> {
let node = self.ast_id.to_node(db);
InFile::new(self.ast_id.file_id, node)
}
}
impl HasSource for ImplLoc {
type Value = ast::ImplBlock;
fn source(&self, db: &impl DefDatabase) -> InFile<ast::ImplBlock> {
let node = self.ast_id.to_node(db);
InFile::new(self.ast_id.file_id, node)
}
}
impl HasSource for TraitLoc {
type Value = ast::TraitDef;
fn source(&self, db: &impl DefDatabase) -> InFile<ast::TraitDef> {
let node = self.ast_id.to_node(db);
InFile::new(self.ast_id.file_id, node)
}
}
impl HasSource for StructLoc {
type Value = ast::StructDef;
fn source(&self, db: &impl DefDatabase) -> InFile<ast::StructDef> {
let node = self.ast_id.to_node(db);
InFile::new(self.ast_id.file_id, node)
}
}
impl HasSource for UnionLoc {
type Value = ast::UnionDef;
fn source(&self, db: &impl DefDatabase) -> InFile<ast::UnionDef> {
let node = self.ast_id.to_node(db);
InFile::new(self.ast_id.file_id, node)
}
}
impl HasSource for EnumLoc {
type Value = ast::EnumDef;
fn source(&self, db: &impl DefDatabase) -> InFile<ast::EnumDef> {
fn source(&self, db: &impl DefDatabase) -> InFile<N> {
let node = self.ast_id.to_node(db);
InFile::new(self.ast_id.file_id, node)
}