aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-01-13 20:12:36 +0000
committerFlorian Diebold <[email protected]>2019-01-19 15:02:06 +0000
commitd37bb128effd19e3aec347e3d4f2e27b5cdb9404 (patch)
treee038fa676e1cce04fa6a757b66077d42e6a07fec /crates/ra_hir
parentcc4562ab6ecfced33f5d7a2e428c8caca8f9c3f1 (diff)
Collect generic args in struct variant paths as well
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/ty.rs29
-rw-r--r--crates/ra_hir/src/ty/tests/data/struct_generics.txt10
2 files changed, 24 insertions, 15 deletions
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> {
1054 } 1054 }
1055 1055
1056 fn resolve_variant(&mut self, path: Option<&Path>) -> (Ty, Option<DefId>) { 1056 fn resolve_variant(&mut self, path: Option<&Path>) -> (Ty, Option<DefId>) {
1057 let path = if let Some(path) = path { 1057 let path = match path {
1058 path 1058 Some(path) => path,
1059 } else { 1059 None => return (Ty::Unknown, None),
1060 return (Ty::Unknown, None);
1061 }; 1060 };
1062 let def_id = if let Some(def_id) = self.module.resolve_path(self.db, &path).take_types() { 1061 let def_id = match self.module.resolve_path(self.db, &path).take_types() {
1063 def_id 1062 Some(def_id) => def_id,
1064 } else { 1063 _ => return (Ty::Unknown, None),
1065 return (Ty::Unknown, None);
1066 }; 1064 };
1065 // TODO remove the duplication between here and `Ty::from_path`?
1066 // TODO provide generics of function
1067 let generics = Generics::default();
1068 let substs = Ty::substs_from_path(
1069 self.db,
1070 &self.module,
1071 self.impl_block.as_ref(),
1072 &generics,
1073 path,
1074 def_id,
1075 );
1067 match def_id.resolve(self.db) { 1076 match def_id.resolve(self.db) {
1068 Def::Struct(s) => { 1077 Def::Struct(s) => {
1069 let ty = type_for_struct(self.db, s); 1078 let ty = type_for_struct(self.db, s);
1070 let ty = self.insert_type_vars(ty); 1079 let ty = self.insert_type_vars(ty.apply_substs(substs));
1071 (ty, Some(def_id)) 1080 (ty, Some(def_id))
1072 } 1081 }
1073 Def::EnumVariant(ev) => { 1082 Def::EnumVariant(ev) => {
1074 let ty = type_for_enum_variant(self.db, ev); 1083 let ty = type_for_enum_variant(self.db, ev);
1075 let ty = self.insert_type_vars(ty); 1084 let ty = self.insert_type_vars(ty.apply_substs(substs));
1076 (ty, Some(def_id)) 1085 (ty, Some(def_id))
1077 } 1086 }
1078 _ => (Ty::Unknown, None), 1087 _ => (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 @@
8[88; 89) 'i': i32 8[88; 89) 'i': i32
9[97; 99) 'a2': A<i32> 9[97; 99) 'a2': A<i32>
10[97; 101) 'a2.x': i32 10[97; 101) 'a2.x': i32
11[111; 113) 'a3': A<i32> 11[111; 113) 'a3': A<i128>
12[116; 134) 'A::<i1...x: 1 }': A<i32> 12[116; 134) 'A::<i1...x: 1 }': A<i128>
13[131; 132) '1': i32 13[131; 132) '1': i128
14[140; 142) 'a3': A<i32> 14[140; 142) 'a3': A<i128>
15[140; 144) 'a3.x': i32 15[140; 144) 'a3.x': i128