From 688a45e00b53412a7a16360c6d678a5d91a95789 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 12 Jan 2019 21:27:35 +0100 Subject: Implement beginnings of generics - add HIR for generic params - resolve generic params in type paths - add substitions for ADTs - insert type variables for substitutions --- crates/ra_hir/src/ty/method_resolution.rs | 17 +++++++-- .../ra_hir/src/ty/tests/data/function_generics.txt | 20 +++++----- crates/ra_hir/src/ty/tests/data/generic_chain.txt | 44 +++++++++++----------- .../ra_hir/src/ty/tests/data/struct_generics.txt | 22 +++++------ 4 files changed, 57 insertions(+), 46 deletions(-) (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index b221bd142..53b6d15a8 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs @@ -8,7 +8,11 @@ use rustc_hash::FxHashMap; use ra_db::SourceRootId; -use crate::{HirDatabase, DefId, module_tree::ModuleId, Module, Crate, Name, Function, impl_block::{ImplId, ImplBlock, ImplItem}}; +use crate::{ + HirDatabase, DefId, module_tree::ModuleId, Module, Crate, Name, Function, + impl_block::{ImplId, ImplBlock, ImplItem}, + generics::Generics +}; use super::Ty; /// This is used as a key for indexing impls. @@ -64,8 +68,15 @@ impl CrateImplBlocks { if let Some(_target_trait) = impl_data.target_trait() { // ignore for now } else { - let target_ty = - Ty::from_hir(db, &module, Some(&impl_block), impl_data.target_type()); + // TODO provide generics of impl + let generics = Generics::default(); + let target_ty = Ty::from_hir( + db, + &module, + Some(&impl_block), + &generics, + impl_data.target_type(), + ); if let Some(target_ty_fp) = TyFingerprint::for_impl(&target_ty) { self.impls .entry(target_ty_fp) diff --git a/crates/ra_hir/src/ty/tests/data/function_generics.txt b/crates/ra_hir/src/ty/tests/data/function_generics.txt index 179e136a0..e44d26cfd 100644 --- a/crates/ra_hir/src/ty/tests/data/function_generics.txt +++ b/crates/ra_hir/src/ty/tests/data/function_generics.txt @@ -2,13 +2,13 @@ [21; 26) '{ t }': [unknown] [23; 24) 't': [unknown] [38; 98) '{ ...(1); }': () -[44; 46) 'id': fn([unknown]) -> [unknown] -[44; 52) 'id(1u32)': [unknown] -[47; 51) '1u32': [unknown] -[58; 68) 'id::': fn([unknown]) -> [unknown] -[58; 71) 'id::(1)': [unknown] -[69; 70) '1': [unknown] -[81; 82) 'x': u64 -[90; 92) 'id': fn([unknown]) -> u64 -[90; 95) 'id(1)': u64 -[93; 94) '1': [unknown] +[44; 46) 'id': fn(T) -> T +[44; 52) 'id(1u32)': T +[47; 51) '1u32': u32 +[58; 68) 'id::': fn(T) -> T +[58; 71) 'id::(1)': T +[69; 70) '1': T +[81; 82) 'x': T +[90; 92) 'id': fn(T) -> T +[90; 95) 'id(1)': T +[93; 94) '1': T diff --git a/crates/ra_hir/src/ty/tests/data/generic_chain.txt b/crates/ra_hir/src/ty/tests/data/generic_chain.txt index 720609153..568e00846 100644 --- a/crates/ra_hir/src/ty/tests/data/generic_chain.txt +++ b/crates/ra_hir/src/ty/tests/data/generic_chain.txt @@ -1,29 +1,29 @@ -[53; 57) 'self': A +[53; 57) 'self': A<[unknown]> [65; 87) '{ ... }': [unknown] -[75; 79) 'self': A +[75; 79) 'self': A<[unknown]> [75; 81) 'self.x': [unknown] [99; 100) 't': [unknown] [110; 115) '{ t }': [unknown] [112; 113) 't': [unknown] [135; 261) '{ ....x() }': i128 -[146; 147) 'x': [unknown] -[150; 151) '1': [unknown] -[162; 163) 'y': [unknown] -[166; 168) 'id': fn([unknown]) -> [unknown] -[166; 171) 'id(x)': [unknown] -[169; 170) 'x': [unknown] -[182; 183) 'a': A -[186; 200) 'A { x: id(y) }': A -[193; 195) 'id': fn([unknown]) -> [unknown] -[193; 198) 'id(y)': [unknown] -[196; 197) 'y': [unknown] -[211; 212) 'z': [unknown] -[215; 217) 'id': fn([unknown]) -> [unknown] -[215; 222) 'id(a.x)': [unknown] -[218; 219) 'a': A -[218; 221) 'a.x': [unknown] -[233; 234) 'b': A -[237; 247) 'A { x: z }': A -[244; 245) 'z': [unknown] -[254; 255) 'b': A +[146; 147) 'x': T +[150; 151) '1': T +[162; 163) 'y': T +[166; 168) 'id': fn(T) -> T +[166; 171) 'id(x)': T +[169; 170) 'x': T +[182; 183) 'a': A +[186; 200) 'A { x: id(y) }': A +[193; 195) 'id': fn(T) -> T +[193; 198) 'id(y)': T +[196; 197) 'y': T +[211; 212) 'z': T +[215; 217) 'id': fn(T) -> T +[215; 222) 'id(a.x)': T +[218; 219) 'a': A +[218; 221) 'a.x': T +[233; 234) 'b': A +[237; 247) 'A { x: z }': A +[244; 245) 'z': T +[254; 255) 'b': A [254; 259) 'b.x()': i128 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 d1026b459..88cd2b409 100644 --- a/crates/ra_hir/src/ty/tests/data/struct_generics.txt +++ b/crates/ra_hir/src/ty/tests/data/struct_generics.txt @@ -1,15 +1,15 @@ -[36; 38) 'a1': A +[36; 38) 'a1': A<[unknown]> [48; 49) 'i': i32 [56; 147) '{ ...3.x; }': () -[62; 64) 'a1': A +[62; 64) 'a1': A<[unknown]> [62; 66) 'a1.x': [unknown] -[76; 78) 'a2': A -[81; 91) 'A { x: i }': A +[76; 78) 'a2': A +[81; 91) 'A { x: i }': A [88; 89) 'i': i32 -[97; 99) 'a2': A -[97; 101) 'a2.x': [unknown] -[111; 113) 'a3': A -[116; 134) '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 -- cgit v1.2.3