From 3d4b48e481da35f19366514c0e22ed42fef037a0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Dec 2019 14:47:01 +0100 Subject: Fix resolve for field init shorthand --- crates/ra_hir/src/from_source.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'crates/ra_hir/src/from_source.rs') 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 @@ -//! FIXME: write short doc here +//! Finds a corresponding hir data structure for a syntax node in a specific +//! file. + use hir_def::{ child_by_source::ChildBySource, dyn_map::DynMap, keys, keys::Key, nameres::ModuleSource, ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId, ImplId, ModuleId, @@ -11,14 +13,14 @@ use ra_syntax::{ }; use crate::{ - db::{AstDatabase, DefDatabase, HirDatabase}, + db::{DefDatabase, HirDatabase}, Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, ImplBlock, InFile, Local, MacroDef, Module, Static, Struct, StructField, Trait, TypeAlias, TypeParam, Union, }; pub trait FromSource: Sized { type Ast; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option; + fn from_source(db: &impl DefDatabase, src: InFile) -> Option; } pub trait FromSourceByContainer: Sized { @@ -32,7 +34,7 @@ where T: From<::Id>, { type Ast = ::Ast; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option { + fn from_source(db: &impl DefDatabase, src: InFile) -> Option { analyze_container(db, src.as_ref().map(|it| it.syntax()))[T::KEY] .get(&src) .copied() @@ -64,7 +66,7 @@ from_source_by_container_impls![ impl FromSource for MacroDef { type Ast = ast::MacroCall; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option { + fn from_source(db: &impl DefDatabase, src: InFile) -> Option { let kind = MacroDefKind::Declarative; let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); @@ -80,7 +82,7 @@ impl FromSource for MacroDef { impl FromSource for EnumVariant { type Ast = ast::EnumVariant; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option { + fn from_source(db: &impl DefDatabase, src: InFile) -> Option { let parent_enum = src.value.parent_enum(); let src_enum = InFile { file_id: src.file_id, value: parent_enum }; let parent_enum = Enum::from_source(db, src_enum)?; @@ -93,7 +95,7 @@ impl FromSource for EnumVariant { impl FromSource for StructField { type Ast = FieldSource; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option { + fn from_source(db: &impl DefDatabase, src: InFile) -> Option { let src = src.as_ref(); // FIXME this is buggy -- cgit v1.2.3