2442: Move source-related traits to a separate module r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-11-28 16:05:46 +00:00 committed by GitHub
commit 8b278b1ab6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 77 additions and 60 deletions

View File

@ -1,6 +1,9 @@
//! FIXME: write short doc here
use hir_def::{AstItemDef, HasChildSource, HasSource as _, Lookup, VariantId};
use hir_def::{
src::{HasChildSource, HasSource as _},
AstItemDef, Lookup, VariantId,
};
use hir_expand::either::Either;
use ra_syntax::ast;

View File

@ -11,7 +11,7 @@
use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
use crate::{
db::DefDatabase, trace::Trace, type_ref::TypeRef, AstItemDef, EnumId, HasChildSource,
db::DefDatabase, src::HasChildSource, trace::Trace, type_ref::TypeRef, AstItemDef, EnumId,
LocalEnumVariantId, LocalStructFieldId, StructId, UnionId, VariantId,
};

View File

@ -11,7 +11,8 @@
use tt::Subtree;
use crate::{
db::DefDatabase, path::Path, AdtId, AstItemDef, AttrDefId, HasChildSource, HasSource, Lookup,
db::DefDatabase, path::Path, src::HasChildSource, src::HasSource, AdtId, AstItemDef, AttrDefId,
Lookup,
};
#[derive(Default, Debug, Clone, PartialEq, Eq)]

View File

@ -17,7 +17,8 @@
expr::{Expr, ExprId, Pat, PatId},
nameres::CrateDefMap,
path::Path,
DefWithBodyId, HasModule, HasSource, Lookup, ModuleId,
src::HasSource,
DefWithBodyId, HasModule, Lookup, ModuleId,
};
struct Expander {

View File

@ -10,9 +10,10 @@
use crate::{
db::DefDatabase,
src::HasSource,
type_ref::{Mutability, TypeRef},
AssocItemId, AstItemDef, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, HasSource,
ImplId, Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc,
AssocItemId, AstItemDef, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, ImplId,
Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc,
};
#[derive(Debug, Clone, PartialEq, Eq)]

View File

@ -8,7 +8,11 @@
use hir_expand::either::Either;
use ra_syntax::ast;
use crate::{db::DefDatabase, AdtId, AstItemDef, AttrDefId, HasChildSource, HasSource, Lookup};
use crate::{
db::DefDatabase,
src::{HasChildSource, HasSource},
AdtId, AstItemDef, AttrDefId, Lookup,
};
/// Holds documentation
#[derive(Debug, Clone, PartialEq, Eq)]

View File

@ -9,8 +9,9 @@
use crate::{
db::DefDatabase,
src::HasSource,
type_ref::{TypeBound, TypeRef},
AdtId, AstItemDef, ContainerId, GenericDefId, HasSource, Lookup,
AdtId, AstItemDef, ContainerId, GenericDefId, Lookup,
};
/// Data about a generic parameter (to a function, struct, impl, ...).

View File

@ -29,6 +29,8 @@
mod trace;
pub mod nameres;
pub mod src;
#[cfg(test)]
mod test_db;
#[cfg(test)]
@ -37,7 +39,7 @@
use std::hash::{Hash, Hasher};
use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, InFile, MacroDefId};
use ra_arena::{impl_arena_id, map::ArenaMap, RawId};
use ra_arena::{impl_arena_id, RawId};
use ra_db::{impl_intern_key, salsa, CrateId};
use ra_syntax::{ast, AstNode};
@ -514,53 +516,3 @@ fn module(&self, _db: &impl db::DefDatabase) -> ModuleId {
self.container
}
}
pub trait HasSource {
type Value;
fn source(&self, db: &impl db::DefDatabase) -> InFile<Self::Value>;
}
impl HasSource for FunctionLoc {
type Value = ast::FnDef;
fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::FnDef> {
let node = self.ast_id.to_node(db);
InFile::new(self.ast_id.file_id, node)
}
}
impl HasSource for TypeAliasLoc {
type Value = ast::TypeAliasDef;
fn source(&self, db: &impl db::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 db::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 db::DefDatabase) -> InFile<ast::StaticDef> {
let node = self.ast_id.to_node(db);
InFile::new(self.ast_id.file_id, node)
}
}
pub trait HasChildSource {
type ChildId;
type Value;
fn child_source(
&self,
db: &impl db::DefDatabase,
) -> InFile<ArenaMap<Self::ChildId, Self::Value>>;
}

View File

@ -0,0 +1,54 @@
//! Utilities for mapping between hir IDs and the surface syntax.
use hir_expand::InFile;
use ra_arena::map::ArenaMap;
use ra_syntax::ast;
use crate::{db::DefDatabase, ConstLoc, FunctionLoc, StaticLoc, TypeAliasLoc};
pub trait HasSource {
type Value;
fn source(&self, db: &impl DefDatabase) -> InFile<Self::Value>;
}
impl HasSource for FunctionLoc {
type Value = ast::FnDef;
fn source(&self, db: &impl DefDatabase) -> InFile<ast::FnDef> {
let node = self.ast_id.to_node(db);
InFile::new(self.ast_id.file_id, node)
}
}
impl HasSource for TypeAliasLoc {
type Value = ast::TypeAliasDef;
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)
}
}
pub trait HasChildSource {
type ChildId;
type Value;
fn child_source(&self, db: &impl DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>>;
}

View File

@ -693,7 +693,7 @@ fn none() -> Self {
}
mod diagnostics {
use hir_def::{expr::ExprId, FunctionId, HasSource, Lookup};
use hir_def::{expr::ExprId, src::HasSource, FunctionId, Lookup};
use hir_expand::diagnostics::DiagnosticSink;
use crate::{db::HirDatabase, diagnostics::NoSuchField};