Move ConstSignature creation to a single method

This commit is contained in:
Ville Penttinen 2019-02-25 10:29:56 +02:00
parent 29f93a7906
commit cff9a7dfad

View file

@ -1,6 +1,6 @@
use std::sync::Arc; use std::sync::Arc;
use ra_syntax::ast::{NameOwner}; use ra_syntax::ast::{self, NameOwner};
use crate::{ use crate::{
Name, AsName, Const, ConstSignature, Static, Name, AsName, Const, ConstSignature, Static,
@ -8,20 +8,23 @@ use crate::{
PersistentHirDatabase, PersistentHirDatabase,
}; };
fn const_signature_for<N: NameOwner>(
node: &N,
type_ref: Option<&ast::TypeRef>,
) -> Arc<ConstSignature> {
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 { impl ConstSignature {
pub(crate) fn const_signature_query( pub(crate) fn const_signature_query(
db: &impl PersistentHirDatabase, db: &impl PersistentHirDatabase,
konst: Const, konst: Const,
) -> Arc<ConstSignature> { ) -> Arc<ConstSignature> {
let (_, node) = konst.source(db); let (_, node) = konst.source(db);
const_signature_for(&*node, node.type_ref())
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)
} }
pub(crate) fn static_signature_query( pub(crate) fn static_signature_query(
@ -29,13 +32,6 @@ impl ConstSignature {
konst: Static, konst: Static,
) -> Arc<ConstSignature> { ) -> Arc<ConstSignature> {
let (_, node) = konst.source(db); let (_, node) = konst.source(db);
const_signature_for(&*node, node.type_ref())
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)
} }
} }