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 ++++++++++++++-------- .../ra_hir/src/ty/tests/data/struct_generics.txt | 10 ++++---- 2 files changed, 24 insertions(+), 15 deletions(-) (limited to 'crates/ra_hir') 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), diff --git a/crates/ra_hir/src/ty/tests/data/struct_generics.txt b/crates/ra_hir/src/ty/tests/data/struct_generics.txt index c6be2a5f5..1024a39a9 100644 --- a/crates/ra_hir/src/ty/tests/data/struct_generics.txt +++ b/crates/ra_hir/src/ty/tests/data/struct_generics.txt @@ -8,8 +8,8 @@ [88; 89) 'i': i32 [97; 99) 'a2': A [97; 101) 'a2.x': i32 -[111; 113) 'a3': A -[116; 134) 'A:: -[131; 132) '1': i32 -[140; 142) 'a3': A -[140; 144) 'a3.x': i32 +[111; 113) 'a3': A +[116; 134) 'A:: +[131; 132) '1': i128 +[140; 142) 'a3': A +[140; 144) 'a3.x': i128 -- cgit v1.2.3