From d37bb128effd19e3aec347e3d4f2e27b5cdb9404 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 13 Jan 2019 21:12:36 +0100 Subject: Collect generic args in struct variant paths as well --- crates/ra_hir/src/ty.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'crates/ra_hir/src/ty.rs') diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index fcde918fb..1d2d1b906 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -1054,25 +1054,34 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } fn resolve_variant(&mut self, path: Option<&Path>) -> (Ty, Option) { - let path = if let Some(path) = path { - path - } else { - return (Ty::Unknown, None); + let path = match path { + Some(path) => path, + None => return (Ty::Unknown, None), }; - let def_id = if let Some(def_id) = self.module.resolve_path(self.db, &path).take_types() { - def_id - } else { - return (Ty::Unknown, None); + let def_id = match self.module.resolve_path(self.db, &path).take_types() { + Some(def_id) => def_id, + _ => return (Ty::Unknown, None), }; + // TODO remove the duplication between here and `Ty::from_path`? + // TODO provide generics of function + let generics = Generics::default(); + let substs = Ty::substs_from_path( + self.db, + &self.module, + self.impl_block.as_ref(), + &generics, + path, + def_id, + ); match def_id.resolve(self.db) { Def::Struct(s) => { let ty = type_for_struct(self.db, s); - let ty = self.insert_type_vars(ty); + let ty = self.insert_type_vars(ty.apply_substs(substs)); (ty, Some(def_id)) } Def::EnumVariant(ev) => { let ty = type_for_enum_variant(self.db, ev); - let ty = self.insert_type_vars(ty); + let ty = self.insert_type_vars(ty.apply_substs(substs)); (ty, Some(def_id)) } _ => (Ty::Unknown, None), -- cgit v1.2.3