aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-12-20 13:47:01 +0000
committerAleksey Kladov <[email protected]>2019-12-20 13:48:14 +0000
commit3d4b48e481da35f19366514c0e22ed42fef037a0 (patch)
tree9e4ff021db736a76bc82555886d868cd7429f021 /crates/ra_hir
parenta0571359f3ea5361f1676b0777b578c6deefdc7d (diff)
Fix resolve for field init shorthand
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/from_source.rs16
-rw-r--r--crates/ra_hir/src/source_binder.rs8
2 files changed, 16 insertions, 8 deletions
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index 3b6454a1d..42ca55fe7 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -1,4 +1,6 @@
1//! FIXME: write short doc here 1//! Finds a corresponding hir data structure for a syntax node in a specific
2//! file.
3
2use hir_def::{ 4use hir_def::{
3 child_by_source::ChildBySource, dyn_map::DynMap, keys, keys::Key, nameres::ModuleSource, 5 child_by_source::ChildBySource, dyn_map::DynMap, keys, keys::Key, nameres::ModuleSource,
4 ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId, ImplId, ModuleId, 6 ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId, ImplId, ModuleId,
@@ -11,14 +13,14 @@ use ra_syntax::{
11}; 13};
12 14
13use crate::{ 15use crate::{
14 db::{AstDatabase, DefDatabase, HirDatabase}, 16 db::{DefDatabase, HirDatabase},
15 Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, ImplBlock, InFile, Local, 17 Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, ImplBlock, InFile, Local,
16 MacroDef, Module, Static, Struct, StructField, Trait, TypeAlias, TypeParam, Union, 18 MacroDef, Module, Static, Struct, StructField, Trait, TypeAlias, TypeParam, Union,
17}; 19};
18 20
19pub trait FromSource: Sized { 21pub trait FromSource: Sized {
20 type Ast; 22 type Ast;
21 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self>; 23 fn from_source(db: &impl DefDatabase, src: InFile<Self::Ast>) -> Option<Self>;
22} 24}
23 25
24pub trait FromSourceByContainer: Sized { 26pub trait FromSourceByContainer: Sized {
@@ -32,7 +34,7 @@ where
32 T: From<<T as FromSourceByContainer>::Id>, 34 T: From<<T as FromSourceByContainer>::Id>,
33{ 35{
34 type Ast = <T as FromSourceByContainer>::Ast; 36 type Ast = <T as FromSourceByContainer>::Ast;
35 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> { 37 fn from_source(db: &impl DefDatabase, src: InFile<Self::Ast>) -> Option<Self> {
36 analyze_container(db, src.as_ref().map(|it| it.syntax()))[T::KEY] 38 analyze_container(db, src.as_ref().map(|it| it.syntax()))[T::KEY]
37 .get(&src) 39 .get(&src)
38 .copied() 40 .copied()
@@ -64,7 +66,7 @@ from_source_by_container_impls![
64 66
65impl FromSource for MacroDef { 67impl FromSource for MacroDef {
66 type Ast = ast::MacroCall; 68 type Ast = ast::MacroCall;
67 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> { 69 fn from_source(db: &impl DefDatabase, src: InFile<Self::Ast>) -> Option<Self> {
68 let kind = MacroDefKind::Declarative; 70 let kind = MacroDefKind::Declarative;
69 71
70 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); 72 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax()));
@@ -80,7 +82,7 @@ impl FromSource for MacroDef {
80 82
81impl FromSource for EnumVariant { 83impl FromSource for EnumVariant {
82 type Ast = ast::EnumVariant; 84 type Ast = ast::EnumVariant;
83 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> { 85 fn from_source(db: &impl DefDatabase, src: InFile<Self::Ast>) -> Option<Self> {
84 let parent_enum = src.value.parent_enum(); 86 let parent_enum = src.value.parent_enum();
85 let src_enum = InFile { file_id: src.file_id, value: parent_enum }; 87 let src_enum = InFile { file_id: src.file_id, value: parent_enum };
86 let parent_enum = Enum::from_source(db, src_enum)?; 88 let parent_enum = Enum::from_source(db, src_enum)?;
@@ -93,7 +95,7 @@ impl FromSource for EnumVariant {
93 95
94impl FromSource for StructField { 96impl FromSource for StructField {
95 type Ast = FieldSource; 97 type Ast = FieldSource;
96 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> { 98 fn from_source(db: &impl DefDatabase, src: InFile<Self::Ast>) -> Option<Self> {
97 let src = src.as_ref(); 99 let src = src.as_ref();
98 100
99 // FIXME this is buggy 101 // FIXME this is buggy
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index d326169b3..b60a6b87e 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -237,7 +237,13 @@ impl SourceAnalyzer {
237 } 237 }
238 238
239 pub fn resolve_record_field(&self, field: &ast::RecordField) -> Option<crate::StructField> { 239 pub fn resolve_record_field(&self, field: &ast::RecordField) -> Option<crate::StructField> {
240 let expr_id = self.expr_id(&field.expr()?)?; 240 let expr_id = match field.expr() {
241 Some(it) => self.expr_id(&it)?,
242 None => {
243 let src = InFile { file_id: self.file_id, value: field };
244 self.body_source_map.as_ref()?.field_init_shorthand_expr(src)?
245 }
246 };
241 self.infer.as_ref()?.record_field_resolution(expr_id).map(|it| it.into()) 247 self.infer.as_ref()?.record_field_resolution(expr_id).map(|it| it.into())
242 } 248 }
243 249