Use TypeAscriptionOwner

This replaces places where we would use node + node.type_ref() with things that
have an ascribed type, with using the TypeAscriptionOwner as the trait bound so
we can simply pass the node.
This commit is contained in:
Ville Penttinen
2019-02-26 11:47:13 +02:00
parent 6eb070d661
commit 52054e1140
2 changed files with 15 additions and 12 deletions

View File

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