]> git.lizzy.rs Git - rust.git/commitdiff
Rename ImplBlock::target -> target_type, and add target_trait already
authorFlorian Diebold <flodiebold@gmail.com>
Sun, 30 Dec 2018 18:59:49 +0000 (19:59 +0100)
committerFlorian Diebold <flodiebold@gmail.com>
Fri, 4 Jan 2019 18:16:39 +0000 (19:16 +0100)
crates/ra_hir/src/impl_block.rs
crates/ra_hir/src/ty.rs

index 22f0a4461b1cfcb67436e4d8e63b2d492267a23c..77fab24d0691ff4caa3b96f2ae8e284d98d36f8c 100644 (file)
@@ -35,8 +35,12 @@ fn impl_data(&self) -> &ImplData {
         &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 @@ pub fn items(&self) -> &[ImplItem] {
 
 #[derive(Debug, Clone, PartialEq, Eq)]
 pub struct ImplData {
-    impl_for: TypeRef,
+    target_trait: Option<TypeRef>,
+    target_type: TypeRef,
     items: Vec<ImplItem>,
 }
 
@@ -57,7 +62,8 @@ pub(crate) fn from_ast(
         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 @@ pub(crate) fn from_ast(
         } else {
             Vec::new()
         };
-        ImplData { impl_for, items }
+        ImplData {
+            target_trait,
+            target_type,
+            items,
+        }
     }
 }
 
index 45a01679ce2fd7dcfed1d19589bb7721e9b2d62a..e33762e0ddb2a11479dc0302d24b4a12ab636627 100644 (file)
@@ -306,7 +306,7 @@ pub(crate) fn from_hir_path(
             } 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 @@ fn collect_fn_signature(&mut self, node: ast::FnDef) -> Cancelable<()> {
                     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),