mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
replace trait by a bunch of functions
This commit is contained in:
parent
d26d0ada50
commit
835173d065
9 changed files with 227 additions and 330 deletions
|
@ -11,9 +11,8 @@ use crate::{
|
|||
db::{AstDatabase, DefDatabase, HirDatabase},
|
||||
ids::{AstItemDef, LocationCtx},
|
||||
name::AsName,
|
||||
AssocItem, Const, Crate, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock,
|
||||
Module, ModuleDef, ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union,
|
||||
VariantDef,
|
||||
Const, Crate, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock, Module,
|
||||
ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union, VariantDef,
|
||||
};
|
||||
|
||||
pub trait FromSource: Sized {
|
||||
|
@ -130,61 +129,6 @@ impl FromSource for StructField {
|
|||
}
|
||||
}
|
||||
|
||||
impl FromSource for AssocItem {
|
||||
type Ast = ast::ImplItem;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
|
||||
macro_rules! def {
|
||||
($kind:ident, $ast:ident) => {
|
||||
$kind::from_source(db, Source { file_id: src.file_id, ast: $ast })
|
||||
.and_then(|it| Some(AssocItem::from(it)))
|
||||
};
|
||||
}
|
||||
|
||||
match src.ast {
|
||||
ast::ImplItem::FnDef(f) => def!(Function, f),
|
||||
ast::ImplItem::ConstDef(c) => def!(Const, c),
|
||||
ast::ImplItem::TypeAliasDef(a) => def!(TypeAlias, a),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// not fully matched
|
||||
impl FromSource for ModuleDef {
|
||||
type Ast = ast::ModuleItem;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
|
||||
macro_rules! def {
|
||||
($kind:ident, $ast:ident) => {
|
||||
$kind::from_source(db, Source { file_id: src.file_id, ast: $ast })
|
||||
.and_then(|it| Some(ModuleDef::from(it)))
|
||||
};
|
||||
}
|
||||
|
||||
match src.ast {
|
||||
ast::ModuleItem::FnDef(f) => def!(Function, f),
|
||||
ast::ModuleItem::ConstDef(c) => def!(Const, c),
|
||||
ast::ModuleItem::TypeAliasDef(a) => def!(TypeAlias, a),
|
||||
ast::ModuleItem::TraitDef(t) => def!(Trait, t),
|
||||
ast::ModuleItem::StaticDef(s) => def!(Static, s),
|
||||
ast::ModuleItem::StructDef(s) => {
|
||||
let src = Source { file_id: src.file_id, ast: s };
|
||||
let s = Struct::from_source(db, src)?;
|
||||
Some(ModuleDef::Adt(s.into()))
|
||||
}
|
||||
ast::ModuleItem::EnumDef(e) => {
|
||||
let src = Source { file_id: src.file_id, ast: e };
|
||||
let e = Enum::from_source(db, src)?;
|
||||
Some(ModuleDef::Adt(e.into()))
|
||||
}
|
||||
ast::ModuleItem::Module(ref m) if !m.has_semi() => {
|
||||
let src = Source { file_id: src.file_id, ast: ModuleSource::Module(m.clone()) };
|
||||
let module = Module::from_definition(db, src)?;
|
||||
Some(ModuleDef::Module(module))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: simplify it
|
||||
impl ModuleSource {
|
||||
pub fn from_position(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue