aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/code_model_impl/konst.rs13
-rw-r--r--crates/ra_ide_api_light/src/structure.rs14
2 files changed, 15 insertions, 12 deletions
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 @@
1use std::sync::Arc; 1use std::sync::Arc;
2 2
3use ra_syntax::ast::{self, NameOwner}; 3use ra_syntax::ast::{NameOwner, TypeAscriptionOwner};
4 4
5use crate::{ 5use crate::{
6 Name, AsName, Const, ConstSignature, Static, 6 Name, AsName, Const, ConstSignature, Static,
@@ -8,12 +8,9 @@ use crate::{
8 PersistentHirDatabase, 8 PersistentHirDatabase,
9}; 9};
10 10
11fn const_signature_for<N: NameOwner>( 11fn const_signature_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstSignature> {
12 node: &N,
13 type_ref: Option<&ast::TypeRef>,
14) -> Arc<ConstSignature> {
15 let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); 12 let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
16 let type_ref = TypeRef::from_ast_opt(type_ref); 13 let type_ref = TypeRef::from_ast_opt(node.ascribed_type());
17 let sig = ConstSignature { name, type_ref }; 14 let sig = ConstSignature { name, type_ref };
18 Arc::new(sig) 15 Arc::new(sig)
19} 16}
@@ -24,7 +21,7 @@ impl ConstSignature {
24 konst: Const, 21 konst: Const,
25 ) -> Arc<ConstSignature> { 22 ) -> Arc<ConstSignature> {
26 let (_, node) = konst.source(db); 23 let (_, node) = konst.source(db);
27 const_signature_for(&*node, node.type_ref()) 24 const_signature_for(&*node)
28 } 25 }
29 26
30 pub(crate) fn static_signature_query( 27 pub(crate) fn static_signature_query(
@@ -32,6 +29,6 @@ impl ConstSignature {
32 konst: Static, 29 konst: Static,
33 ) -> Arc<ConstSignature> { 30 ) -> Arc<ConstSignature> {
34 let (_, node) = konst.source(db); 31 let (_, node) = konst.source(db);
35 const_signature_for(&*node, node.type_ref()) 32 const_signature_for(&*node)
36 } 33 }
37} 34}
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();