mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-22 04:34:51 +00:00
Move ConstSignature creation to a single method
This commit is contained in:
parent
29f93a7906
commit
cff9a7dfad
@ -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<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 {
|
||||
pub(crate) fn const_signature_query(
|
||||
db: &impl PersistentHirDatabase,
|
||||
konst: Const,
|
||||
) -> Arc<ConstSignature> {
|
||||
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<ConstSignature> {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user