remove inherent source impls

This commit is contained in:
Aleksey Kladov 2019-06-11 17:54:51 +03:00
parent dd63f17027
commit c4512fadb1
15 changed files with 22 additions and 67 deletions

View file

@ -1,6 +1,6 @@
use crate::{Assist, AssistId, AssistCtx, ast_editor::{AstEditor, AstBuilder}}; use crate::{Assist, AssistId, AssistCtx, ast_editor::{AstEditor, AstBuilder}};
use hir::db::HirDatabase; use hir::{HasSource, db::HirDatabase};
use ra_syntax::{SmolStr, TreeArc}; use ra_syntax::{SmolStr, TreeArc};
use ra_syntax::ast::{self, AstNode, FnDef, ImplItem, ImplItemKind, NameOwner}; use ra_syntax::ast::{self, AstNode, FnDef, ImplItem, ImplItemKind, NameOwner};
use ra_db::FilePosition; use ra_db::FilePosition;

View file

@ -1,7 +1,7 @@
use std::fmt::Write; use std::fmt::Write;
use hir::{ use hir::{
AdtDef, FieldSource, AdtDef, FieldSource, HasSource,
db::HirDatabase, db::HirDatabase,
}; };
use ra_syntax::ast::{self, AstNode}; use ra_syntax::ast::{self, AstNode};

View file

@ -11,7 +11,7 @@ use ra_syntax::{
use crate::{ use crate::{
Name, AsName, Struct, Union, Enum, EnumVariant, Crate, AstDatabase, Name, AsName, Struct, Union, Enum, EnumVariant, Crate, AstDatabase,
HirDatabase, HirFileId, StructField, FieldSource, Source, HirDatabase, HirFileId, StructField, FieldSource, Source, HasSource,
type_ref::TypeRef, DefDatabase, type_ref::TypeRef, DefDatabase,
}; };

View file

@ -355,10 +355,6 @@ impl StructField {
self.parent.variant_data(db).fields().unwrap()[self.id].name.clone() self.parent.variant_data(db).fields().unwrap()[self.id].name.clone()
} }
pub fn source(&self, db: &(impl DefDatabase + AstDatabase)) -> Source<FieldSource> {
self.source_impl(db).into()
}
pub fn ty(&self, db: &impl HirDatabase) -> Ty { pub fn ty(&self, db: &impl HirDatabase) -> Ty {
db.type_for_field(*self) db.type_for_field(*self)
} }
@ -381,10 +377,6 @@ impl HasSource for Struct {
} }
impl Struct { impl Struct {
pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
self.id.source(db).into()
}
pub fn module(self, db: &impl HirDatabase) -> Module { pub fn module(self, db: &impl HirDatabase) -> Module {
self.id.module(db) self.id.module(db)
} }
@ -446,10 +438,6 @@ impl HasSource for Union {
} }
impl Union { impl Union {
pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
self.id.source(db).into()
}
pub fn name(self, db: &impl DefDatabase) -> Option<Name> { pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
db.struct_data(Struct { id: self.id }).name.clone() db.struct_data(Struct { id: self.id }).name.clone()
} }
@ -483,10 +471,6 @@ impl HasSource for Enum {
} }
impl Enum { impl Enum {
pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> {
self.id.source(db).into()
}
pub fn module(self, db: &impl HirDatabase) -> Module { pub fn module(self, db: &impl HirDatabase) -> Module {
self.id.module(db) self.id.module(db)
} }
@ -537,12 +521,6 @@ impl HasSource for EnumVariant {
} }
impl EnumVariant { impl EnumVariant {
pub fn source(
&self,
db: &(impl DefDatabase + AstDatabase),
) -> Source<TreeArc<ast::EnumVariant>> {
self.source_impl(db)
}
pub fn module(&self, db: &impl HirDatabase) -> Module { pub fn module(&self, db: &impl HirDatabase) -> Module {
self.parent.module(db) self.parent.module(db)
} }
@ -692,10 +670,6 @@ impl FnSignature {
} }
impl Function { impl Function {
pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::FnDef>> {
self.id.source(db).into()
}
pub fn module(self, db: &impl DefDatabase) -> Module { pub fn module(self, db: &impl DefDatabase) -> Module {
self.id.module(db) self.id.module(db)
} }
@ -778,10 +752,6 @@ impl HasSource for Const {
} }
impl Const { impl Const {
pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ConstDef>> {
self.id.source(db).into()
}
pub fn module(self, db: &impl DefDatabase) -> Module { pub fn module(self, db: &impl DefDatabase) -> Module {
self.id.module(db) self.id.module(db)
} }
@ -866,10 +836,6 @@ impl HasSource for Static {
} }
impl Static { impl Static {
pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StaticDef>> {
self.id.source(db).into()
}
pub fn module(self, db: &impl DefDatabase) -> Module { pub fn module(self, db: &impl DefDatabase) -> Module {
self.id.module(db) self.id.module(db)
} }
@ -902,10 +868,6 @@ impl HasSource for Trait {
} }
impl Trait { impl Trait {
pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TraitDef>> {
self.id.source(db).into()
}
pub fn module(self, db: &impl DefDatabase) -> Module { pub fn module(self, db: &impl DefDatabase) -> Module {
self.id.module(db) self.id.module(db)
} }
@ -952,13 +914,6 @@ impl HasSource for TypeAlias {
} }
impl TypeAlias { impl TypeAlias {
pub fn source(
self,
db: &(impl DefDatabase + AstDatabase),
) -> Source<TreeArc<ast::TypeAliasDef>> {
self.id.source(db).into()
}
pub fn module(self, db: &impl DefDatabase) -> Module { pub fn module(self, db: &impl DefDatabase) -> Module {
self.id.module(db) self.id.module(db)
} }
@ -1015,11 +970,7 @@ impl HasSource for MacroDef {
} }
} }
impl MacroDef { impl MacroDef {}
pub fn source(&self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::MacroCall>> {
(self.id.0.file_id(), self.id.0.to_node(db)).into()
}
}
pub enum Container { pub enum Container {
Trait(Trait), Trait(Trait),

View file

@ -3,7 +3,7 @@ use std::sync::Arc;
use ra_syntax::ast; use ra_syntax::ast;
use crate::{ use crate::{
HirDatabase, DefDatabase, AstDatabase, HirDatabase, DefDatabase, AstDatabase, HasSource,
Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union, Trait, TypeAlias, FieldSource, MacroDef, Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union, Trait, TypeAlias, FieldSource, MacroDef,
}; };

View file

@ -11,6 +11,7 @@ use ra_syntax::{
use crate::{ use crate::{
Path, Name, HirDatabase, Resolver,DefWithBody, Either, HirFileId, MacroCallLoc, MacroFileKind, Path, Name, HirDatabase, Resolver,DefWithBody, Either, HirFileId, MacroCallLoc, MacroFileKind,
HasSource,
name::AsName, name::AsName,
type_ref::{Mutability, TypeRef}, type_ref::{Mutability, TypeRef},
}; };

View file

@ -5,7 +5,7 @@ use ra_syntax::ast::{AstNode, StructLit};
use crate::{ use crate::{
expr::AstPtr, expr::AstPtr,
HirDatabase, Function, Name, HirDatabase, Function, Name, HasSource,
diagnostics::{DiagnosticSink, MissingFields}, diagnostics::{DiagnosticSink, MissingFields},
adt::AdtDef, adt::AdtDef,
Path, Path,

View file

@ -8,8 +8,10 @@ use std::sync::Arc;
use ra_syntax::ast::{self, NameOwner, TypeParamsOwner, TypeBoundsOwner, DefaultTypeParamOwner}; use ra_syntax::ast::{self, NameOwner, TypeParamsOwner, TypeBoundsOwner, DefaultTypeParamOwner};
use crate::{ use crate::{
HasSource,
Name, AsName, Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlock, Container, AdtDef,
db::{HirDatabase, DefDatabase, AstDatabase}, db::{HirDatabase, DefDatabase, AstDatabase},
Name, AsName, Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlock, Container, path::Path, type_ref::TypeRef, AdtDef path::Path, type_ref::TypeRef,
}; };
/// Data about a generic parameter (to a function, struct, impl, ...). /// Data about a generic parameter (to a function, struct, impl, ...).

View file

@ -6,7 +6,7 @@ use rustc_hash::FxHashMap;
use ra_syntax::ast::{self, NameOwner}; use ra_syntax::ast::{self, NameOwner};
use crate::{ use crate::{
Function, Const, TypeAlias, Name, DefDatabase, Trait, AstDatabase, Module, Function, Const, TypeAlias, Name, DefDatabase, Trait, AstDatabase, Module, HasSource,
ids::LocationCtx, name::AsName, ids::LocationCtx, name::AsName,
}; };

View file

@ -1415,7 +1415,7 @@ mod diagnostics {
use crate::{ use crate::{
expr::ExprId, expr::ExprId,
diagnostics::{DiagnosticSink, NoSuchField}, diagnostics::{DiagnosticSink, NoSuchField},
HirDatabase, Function, HirDatabase, Function, HasSource,
}; };
#[derive(Debug, PartialEq, Eq, Clone)] #[derive(Debug, PartialEq, Eq, Clone)]

View file

@ -2,7 +2,7 @@
use std::sync::Arc; use std::sync::Arc;
use crate::{TypeAlias, DefDatabase, AstDatabase, type_ref::TypeRef}; use crate::{TypeAlias, DefDatabase, AstDatabase, HasSource, type_ref::TypeRef};
pub(crate) fn type_alias_ref_query( pub(crate) fn type_alias_ref_query(
db: &(impl DefDatabase + AstDatabase), db: &(impl DefDatabase + AstDatabase),

View file

@ -1,7 +1,7 @@
//! This modules takes care of rendering various defenitions as completion items. //! This modules takes care of rendering various defenitions as completion items.
use join_to_string::join; use join_to_string::join;
use test_utils::tested_by; use test_utils::tested_by;
use hir::{Docs, PerNs, Resolution, HirDisplay}; use hir::{Docs, PerNs, Resolution, HirDisplay, HasSource};
use ra_syntax::ast::NameOwner; use ra_syntax::ast::NameOwner;
use crate::completion::{ use crate::completion::{

View file

@ -1,10 +1,11 @@
use super::{where_predicates, generic_parameters};
use crate::db;
use std::fmt::{self, Display}; use std::fmt::{self, Display};
use join_to_string::join; use join_to_string::join;
use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner};
use std::convert::From; use std::convert::From;
use hir::{Docs, Documentation}; use hir::{Docs, Documentation, HasSource};
use crate::{db, display::{where_predicates, generic_parameters}};
/// Contains information about a function signature /// Contains information about a function signature
#[derive(Debug)] #[derive(Debug)]

View file

@ -5,7 +5,7 @@ use ra_syntax::{
ast::{self, DocCommentsOwner}, ast::{self, DocCommentsOwner},
algo::visit::{visitor, Visitor}, algo::visit::{visitor, Visitor},
}; };
use hir::{ModuleSource, FieldSource, ImplItem}; use hir::{ModuleSource, FieldSource, ImplItem, HasSource};
use crate::{FileSymbol, db::RootDatabase}; use crate::{FileSymbol, db::RootDatabase};
use super::short_label::ShortLabel; use super::short_label::ShortLabel;
@ -182,7 +182,7 @@ impl NavigationTarget {
pub(crate) fn from_def_source<A, D>(db: &RootDatabase, def: D) -> NavigationTarget pub(crate) fn from_def_source<A, D>(db: &RootDatabase, def: D) -> NavigationTarget
where where
D: hir::HasSource<Ast = TreeArc<A>>, D: HasSource<Ast = TreeArc<A>>,
A: ast::DocCommentsOwner + ast::NameOwner + ShortLabel, A: ast::DocCommentsOwner + ast::NameOwner + ShortLabel,
{ {
let src = def.source(db); let src = def.source(db);

View file

@ -4,7 +4,7 @@ use ra_syntax::{
ast::{self, DocCommentsOwner}, ast::{self, DocCommentsOwner},
algo::{find_covering_element, find_node_at_offset, ancestors_at_offset, visit::{visitor, Visitor}}, algo::{find_covering_element, find_node_at_offset, ancestors_at_offset, visit::{visitor, Visitor}},
}; };
use hir::HirDisplay; use hir::{HirDisplay, HasSource};
use crate::{ use crate::{
db::RootDatabase, db::RootDatabase,
@ -226,7 +226,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
fn from_def_source<A, D>(db: &RootDatabase, def: D) -> Option<String> fn from_def_source<A, D>(db: &RootDatabase, def: D) -> Option<String>
where where
D: hir::HasSource<Ast = TreeArc<A>>, D: HasSource<Ast = TreeArc<A>>,
A: ast::DocCommentsOwner + ast::NameOwner + ShortLabel, A: ast::DocCommentsOwner + ast::NameOwner + ShortLabel,
{ {
let src = def.source(db); let src = def.source(db);