From 52054e1140cc2af19825ebef2aea06c48cf79955 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Tue, 26 Feb 2019 11:47:13 +0200 Subject: 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. --- crates/ra_hir/src/code_model_impl/konst.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'crates/ra_hir/src/code_model_impl') diff --git a/crates/ra_hir/src/code_model_impl/konst.rs b/crates/ra_hir/src/code_model_impl/konst.rs index ecf4c8122..8b861a81f 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::{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( - node: &N, - type_ref: Option<&ast::TypeRef>, -) -> Arc { +fn const_signature_for(node: &N) -> 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 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 { 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 { let (_, node) = konst.source(db); - const_signature_for(&*node, node.type_ref()) + const_signature_for(&*node) } } -- cgit v1.2.3 From d3ce69aee3297e683691ec0123f5a2584a8075a0 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Wed, 27 Feb 2019 14:00:08 +0200 Subject: Remove `TypeRef` from item opts which implement TypeAscriptionOwner --- crates/ra_hir/src/code_model_impl/function.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir/src/code_model_impl') diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs index c401528c6..c1654b069 100644 --- a/crates/ra_hir/src/code_model_impl/function.rs +++ b/crates/ra_hir/src/code_model_impl/function.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use ra_syntax::ast::{self, NameOwner}; +use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; use crate::{ Name, AsName, Function, FnSignature, @@ -19,7 +19,7 @@ impl FnSignature { let mut has_self_param = false; if let Some(param_list) = node.param_list() { if let Some(self_param) = param_list.self_param() { - let self_type = if let Some(type_ref) = self_param.type_ref() { + let self_type = if let Some(type_ref) = self_param.ascribed_type() { TypeRef::from_ast(type_ref) } else { let self_type = TypeRef::Path(Name::self_type().into()); @@ -37,7 +37,7 @@ impl FnSignature { has_self_param = true; } for param in param_list.params() { - let type_ref = TypeRef::from_ast_opt(param.type_ref()); + let type_ref = TypeRef::from_ast_opt(param.ascribed_type()); params.push(type_ref); } } -- cgit v1.2.3