mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
Move ConstSignature creation to a single method
This commit is contained in:
parent
29f93a7906
commit
cff9a7dfad
1 changed files with 13 additions and 17 deletions
|
@ -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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue