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_ide_api_light/src/structure.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide_api_light/src') diff --git a/crates/ra_ide_api_light/src/structure.rs b/crates/ra_ide_api_light/src/structure.rs index dea494daa..ec2c9bbc6 100644 --- a/crates/ra_ide_api_light/src/structure.rs +++ b/crates/ra_ide_api_light/src/structure.rs @@ -2,7 +2,7 @@ use crate::TextRange; use ra_syntax::{ algo::visit::{visitor, Visitor}, - ast::{self, AttrsOwner, NameOwner, TypeParamsOwner}, + ast::{self, AttrsOwner, NameOwner, TypeParamsOwner, TypeAscriptionOwner}, AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent, }; @@ -45,6 +45,12 @@ fn structure_node(node: &SyntaxNode) -> Option { decl_with_detail(node, None) } + fn decl_with_ascription( + node: &N, + ) -> Option { + decl_with_type_ref(node, node.ascribed_type()) + } + fn decl_with_type_ref( node: &N, type_ref: Option<&ast::TypeRef>, @@ -107,14 +113,14 @@ fn structure_node(node: &SyntaxNode) -> Option { decl_with_detail(fn_def, Some(detail)) }) .visit(decl::) - .visit(|nfd: &ast::NamedFieldDef| decl_with_type_ref(nfd, nfd.type_ref())) .visit(decl::) .visit(decl::) .visit(decl::) .visit(decl::) .visit(|td: &ast::TypeAliasDef| decl_with_type_ref(td, td.type_ref())) - .visit(|cd: &ast::ConstDef| decl_with_type_ref(cd, cd.type_ref())) - .visit(|sd: &ast::StaticDef| decl_with_type_ref(sd, sd.type_ref())) + .visit(decl_with_ascription::) + .visit(decl_with_ascription::) + .visit(decl_with_ascription::) .visit(|im: &ast::ImplBlock| { let target_type = im.target_type()?; let target_trait = im.target_trait(); -- cgit v1.2.3