aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api_light
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-02-27 12:18:55 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-02-27 12:18:55 +0000
commit2e2a6dd2fbeb4da16e602fa1902ab6bbd850b442 (patch)
treeb42e6faf8618c3625e41d5a2011b4ffd145f22de /crates/ra_ide_api_light
parent1927eb088ac9aa3851f77bb929296873ccb4faed (diff)
parentd3ce69aee3297e683691ec0123f5a2584a8075a0 (diff)
Merge #900
900: Add new trait ast::TypeAscriptionOwner r=vipentti a=vipentti This trait should be implemented for nodes which have an ascribed type, e.g. thing : Type. Such as let, const, static, param, named struct fields. In addition, we update some places where previously we used node + node.type_ref() with `TypeAscriptionOwner` in the trait bounds. Co-authored-by: Ville Penttinen <[email protected]>
Diffstat (limited to 'crates/ra_ide_api_light')
-rw-r--r--crates/ra_ide_api_light/src/structure.rs14
1 files changed, 10 insertions, 4 deletions
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;
2 2
3use ra_syntax::{ 3use ra_syntax::{
4 algo::visit::{visitor, Visitor}, 4 algo::visit::{visitor, Visitor},
5 ast::{self, AttrsOwner, NameOwner, TypeParamsOwner}, 5 ast::{self, AttrsOwner, NameOwner, TypeParamsOwner, TypeAscriptionOwner},
6 AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent, 6 AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent,
7}; 7};
8 8
@@ -45,6 +45,12 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
45 decl_with_detail(node, None) 45 decl_with_detail(node, None)
46 } 46 }
47 47
48 fn decl_with_ascription<N: NameOwner + AttrsOwner + TypeAscriptionOwner>(
49 node: &N,
50 ) -> Option<StructureNode> {
51 decl_with_type_ref(node, node.ascribed_type())
52 }
53
48 fn decl_with_type_ref<N: NameOwner + AttrsOwner>( 54 fn decl_with_type_ref<N: NameOwner + AttrsOwner>(
49 node: &N, 55 node: &N,
50 type_ref: Option<&ast::TypeRef>, 56 type_ref: Option<&ast::TypeRef>,
@@ -107,14 +113,14 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
107 decl_with_detail(fn_def, Some(detail)) 113 decl_with_detail(fn_def, Some(detail))
108 }) 114 })
109 .visit(decl::<ast::StructDef>) 115 .visit(decl::<ast::StructDef>)
110 .visit(|nfd: &ast::NamedFieldDef| decl_with_type_ref(nfd, nfd.type_ref()))
111 .visit(decl::<ast::EnumDef>) 116 .visit(decl::<ast::EnumDef>)
112 .visit(decl::<ast::EnumVariant>) 117 .visit(decl::<ast::EnumVariant>)
113 .visit(decl::<ast::TraitDef>) 118 .visit(decl::<ast::TraitDef>)
114 .visit(decl::<ast::Module>) 119 .visit(decl::<ast::Module>)
115 .visit(|td: &ast::TypeAliasDef| decl_with_type_ref(td, td.type_ref())) 120 .visit(|td: &ast::TypeAliasDef| decl_with_type_ref(td, td.type_ref()))
116 .visit(|cd: &ast::ConstDef| decl_with_type_ref(cd, cd.type_ref())) 121 .visit(decl_with_ascription::<ast::NamedFieldDef>)
117 .visit(|sd: &ast::StaticDef| decl_with_type_ref(sd, sd.type_ref())) 122 .visit(decl_with_ascription::<ast::ConstDef>)
123 .visit(decl_with_ascription::<ast::StaticDef>)
118 .visit(|im: &ast::ImplBlock| { 124 .visit(|im: &ast::ImplBlock| {
119 let target_type = im.target_type()?; 125 let target_type = im.target_type()?;
120 let target_trait = im.target_trait(); 126 let target_trait = im.target_trait();