From 46bc8675edd403ffcd8963e4f26447b283e9d09e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 11 Jun 2019 17:13:20 +0300 Subject: use Source for statics and consts --- crates/ra_hir/src/code_model.rs | 34 ++++++++++++++++++++++------------ crates/ra_hir/src/docs.rs | 4 ++-- crates/ra_hir/src/expr.rs | 12 ++++++------ 3 files changed, 30 insertions(+), 20 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index aa6eb741b..a8a0875e0 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -761,12 +761,17 @@ pub struct Const { pub(crate) id: ConstId, } +impl HasSource for Const { + type Ast = TreeArc; + + fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source> { + self.id.source(db).into() + } +} + impl Const { - pub fn source( - self, - db: &(impl DefDatabase + AstDatabase), - ) -> (HirFileId, TreeArc) { - self.id.source(db) + pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source> { + self.id.source(db).into() } pub fn module(self, db: &impl DefDatabase) -> Module { @@ -819,7 +824,7 @@ impl ConstSignature { db: &(impl DefDatabase + AstDatabase), konst: Const, ) -> Arc { - let (_, node) = konst.source(db); + let node = konst.source(db).ast; const_signature_for(&*node) } @@ -827,7 +832,7 @@ impl ConstSignature { db: &(impl DefDatabase + AstDatabase), konst: Static, ) -> Arc { - let (_, node) = konst.source(db); + let node = konst.source(db).ast; const_signature_for(&*node) } } @@ -844,12 +849,17 @@ pub struct Static { pub(crate) id: StaticId, } +impl HasSource for Static { + type Ast = TreeArc; + + fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source> { + self.id.source(db).into() + } +} + impl Static { - pub fn source( - self, - db: &(impl DefDatabase + AstDatabase), - ) -> (HirFileId, TreeArc) { - self.id.source(db) + pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source> { + self.id.source(db).into() } pub fn module(self, db: &impl DefDatabase) -> Module { diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs index 8d7a5255f..86ca981f4 100644 --- a/crates/ra_hir/src/docs.rs +++ b/crates/ra_hir/src/docs.rs @@ -79,8 +79,8 @@ pub(crate) fn documentation_query( DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast), DocDef::Enum(it) => docs_from_ast(&*it.source(db).ast), DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).ast), - DocDef::Static(it) => docs_from_ast(&*it.source(db).1), - DocDef::Const(it) => docs_from_ast(&*it.source(db).1), + DocDef::Static(it) => docs_from_ast(&*it.source(db).ast), + DocDef::Const(it) => docs_from_ast(&*it.source(db).ast), DocDef::Function(it) => docs_from_ast(&*it.source(db).ast), DocDef::Union(it) => docs_from_ast(&*it.source(db).1), DocDef::Trait(it) => docs_from_ast(&*it.source(db).1), diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 46d51e0db..48e597519 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -1018,9 +1018,9 @@ pub(crate) fn body_with_source_map_query( match def { DefWithBody::Const(ref c) => { - let (file_id, src) = c.source(db); - collector = ExprCollector::new(def, file_id, def.resolver(db), db); - collector.collect_const_body(&src) + let src = c.source(db); + collector = ExprCollector::new(def, src.file_id, def.resolver(db), db); + collector.collect_const_body(&src.ast) } DefWithBody::Function(ref f) => { let src = f.source(db); @@ -1028,9 +1028,9 @@ pub(crate) fn body_with_source_map_query( collector.collect_fn_body(&src.ast) } DefWithBody::Static(ref s) => { - let (file_id, src) = s.source(db); - collector = ExprCollector::new(def, file_id, def.resolver(db), db); - collector.collect_static_body(&src) + let src = s.source(db); + collector = ExprCollector::new(def, src.file_id, def.resolver(db), db); + collector.collect_static_body(&src.ast) } } -- cgit v1.2.3