From cff9a7dfadc6069bbc7b49c3ceb8497c78d426ab Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Mon, 25 Feb 2019 10:29:56 +0200 Subject: Move ConstSignature creation to a single method --- crates/ra_hir/src/code_model_impl/konst.rs | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/code_model_impl/konst.rs b/crates/ra_hir/src/code_model_impl/konst.rs index d7722ccc2..ecf4c8122 100644 --- a/crates/ra_hir/src/code_model_impl/konst.rs +++ b/crates/ra_hir/src/code_model_impl/konst.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use ra_syntax::ast::{NameOwner}; +use ra_syntax::ast::{self, NameOwner}; use crate::{ Name, AsName, Const, ConstSignature, Static, @@ -8,20 +8,23 @@ use crate::{ PersistentHirDatabase, }; +fn const_signature_for( + node: &N, + type_ref: Option<&ast::TypeRef>, +) -> Arc { + let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); + let type_ref = TypeRef::from_ast_opt(type_ref); + let sig = ConstSignature { name, type_ref }; + Arc::new(sig) +} + impl ConstSignature { pub(crate) fn const_signature_query( db: &impl PersistentHirDatabase, konst: Const, ) -> Arc { let (_, node) = konst.source(db); - - let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); - - let type_ref = TypeRef::from_ast_opt(node.type_ref()); - - let sig = ConstSignature { name, type_ref }; - - Arc::new(sig) + const_signature_for(&*node, node.type_ref()) } pub(crate) fn static_signature_query( @@ -29,13 +32,6 @@ impl ConstSignature { konst: Static, ) -> Arc { let (_, node) = konst.source(db); - - let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); - - let type_ref = TypeRef::from_ast_opt(node.type_ref()); - - let sig = ConstSignature { name, type_ref }; - - Arc::new(sig) + const_signature_for(&*node, node.type_ref()) } } -- cgit v1.2.3