From 334ca0d9a790d14414301daa896848bf9a880982 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 30 Dec 2018 19:59:49 +0100 Subject: Rename ImplBlock::target -> target_type, and add target_trait already --- crates/ra_hir/src/impl_block.rs | 20 +++++++++++++++----- crates/ra_hir/src/ty.rs | 4 ++-- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 22f0a4461..77fab24d0 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs @@ -35,8 +35,12 @@ impl ImplBlock { &self.crate_impl_blocks.impls[self.impl_id] } - pub fn target(&self) -> &TypeRef { - &self.impl_data().impl_for + pub fn target_trait(&self) -> Option<&TypeRef> { + self.impl_data().target_trait.as_ref() + } + + pub fn target_type(&self) -> &TypeRef { + &self.impl_data().target_type } pub fn items(&self) -> &[ImplItem] { @@ -46,7 +50,8 @@ impl ImplBlock { #[derive(Debug, Clone, PartialEq, Eq)] pub struct ImplData { - impl_for: TypeRef, + target_trait: Option, + target_type: TypeRef, items: Vec, } @@ -57,7 +62,8 @@ impl ImplData { module: &Module, node: ast::ImplBlock, ) -> Self { - let impl_for = TypeRef::from_ast_opt(node.target_type()); + let target_trait = node.target_type().map(TypeRef::from_ast); + let target_type = TypeRef::from_ast_opt(node.target_type()); let file_id = module.source().file_id(); let items = if let Some(item_list) = node.item_list() { item_list @@ -89,7 +95,11 @@ impl ImplData { } else { Vec::new() }; - ImplData { impl_for, items } + ImplData { + target_trait, + target_type, + items, + } } } diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 45a01679c..e33762e0d 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -306,7 +306,7 @@ impl Ty { } else if let Some(float_ty) = primitive::FloatTy::from_name(name) { return Ok(Ty::Float(float_ty)); } else if name.as_known_name() == Some(KnownName::Self_) { - return Ty::from_hir_opt(db, module, None, impl_block.map(|i| i.target())); + return Ty::from_hir_opt(db, module, None, impl_block.map(|i| i.target_type())); } } @@ -972,7 +972,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { self.insert_type_vars(ty) } else { // TODO this should be handled by desugaring during HIR conversion - let ty = self.make_ty_opt(self.impl_block.as_ref().map(|i| i.target()))?; + let ty = self.make_ty_opt(self.impl_block.as_ref().map(|i| i.target_type()))?; let ty = match self_param.flavor() { ast::SelfParamFlavor::Owned => ty, ast::SelfParamFlavor::Ref => Ty::Ref(Arc::new(ty), Mutability::Shared), -- cgit v1.2.3