aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/ty.rs34
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__generic_fn.snap7
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap8
-rw-r--r--crates/ra_hir/src/ty/tests.rs3
4 files changed, 40 insertions, 12 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 9332aca9a..00a71a42f 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -1157,6 +1157,32 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1157 let typable = typable?; 1157 let typable = typable?;
1158 let ty = self.db.type_for_def(typable); 1158 let ty = self.db.type_for_def(typable);
1159 let ty = self.insert_type_vars(ty); 1159 let ty = self.insert_type_vars(ty);
1160
1161 // try to get generic parameters from the path and add them to the
1162 // function type substitutions
1163 if let Ty::FnDef { ref def, .. } = ty {
1164 let last_seg_bindings = path
1165 .segments
1166 .last()
1167 .and_then(|segment| segment.args_and_bindings.as_ref());
1168 if let Some(generic_args) = last_seg_bindings {
1169 let generic_params = def.generic_params(self.db);
1170 if generic_args.args.len() == generic_params.params.len() {
1171 let substs = Ty::substs_from_path(
1172 self.db,
1173 &self.module,
1174 self.impl_block.as_ref(),
1175 &generic_params,
1176 path,
1177 (*def).into(),
1178 );
1179 return Some(ty.apply_substs(substs));
1180 } else {
1181 // ERROR: incorrect number of type params
1182 }
1183 }
1184 }
1185
1160 Some(ty) 1186 Some(ty)
1161 } 1187 }
1162 1188
@@ -1387,9 +1413,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1387 let callee_ty = self.infer_expr(*callee, &Expectation::none()); 1413 let callee_ty = self.infer_expr(*callee, &Expectation::none());
1388 let (param_tys, ret_ty) = match &callee_ty { 1414 let (param_tys, ret_ty) = match &callee_ty {
1389 Ty::FnPtr(sig) => (sig.input.clone(), sig.output.clone()), 1415 Ty::FnPtr(sig) => (sig.input.clone(), sig.output.clone()),
1390 Ty::FnDef { 1416 Ty::FnDef { substs, sig, .. } => {
1391 def, substs, sig, ..
1392 } => {
1393 let ret_ty = sig.output.clone().subst(&substs); 1417 let ret_ty = sig.output.clone().subst(&substs);
1394 let param_tys = sig 1418 let param_tys = sig
1395 .input 1419 .input
@@ -1437,9 +1461,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1437 (Ty::Unknown, Vec::new(), sig.output.clone()) 1461 (Ty::Unknown, Vec::new(), sig.output.clone())
1438 } 1462 }
1439 } 1463 }
1440 Ty::FnDef { 1464 Ty::FnDef { substs, sig, .. } => {
1441 def, substs, sig, ..
1442 } => {
1443 let ret_ty = sig.output.clone().subst(&substs); 1465 let ret_ty = sig.output.clone().subst(&substs);
1444 1466
1445 if sig.input.len() > 0 { 1467 if sig.input.len() > 0 {
diff --git a/crates/ra_hir/src/ty/snapshots/tests__generic_fn.snap b/crates/ra_hir/src/ty/snapshots/tests__generic_fn.snap
index 84fbe6e4c..85aeefa0c 100644
--- a/crates/ra_hir/src/ty/snapshots/tests__generic_fn.snap
+++ b/crates/ra_hir/src/ty/snapshots/tests__generic_fn.snap
@@ -1,5 +1,5 @@
1--- 1---
2created: "2019-01-26T17:46:03.963745056+00:00" 2created: "2019-01-26T18:16:16.568375+00:00"
3creator: [email protected] 3creator: [email protected]
4expression: "&result" 4expression: "&result"
5source: crates/ra_hir/src/ty/tests.rs 5source: crates/ra_hir/src/ty/tests.rs
@@ -10,7 +10,7 @@ source: crates/ra_hir/src/ty/tests.rs
10[44; 45) 'x': &[unknown] 10[44; 45) 'x': &[unknown]
11[56; 65) '{ x }': &[unknown] 11[56; 65) '{ x }': &[unknown]
12[62; 63) 'x': &[unknown] 12[62; 63) 'x': &[unknown]
13[77; 138) '{ ...(z); }': () 13[77; 197) '{ ...(1); }': ()
14[87; 88) 'y': u32 14[87; 88) 'y': u32
15[91; 96) '10u32': u32 15[91; 96) '10u32': u32
16[102; 104) 'id': fn id<u32>(T) -> T 16[102; 104) 'id': fn id<u32>(T) -> T
@@ -20,4 +20,7 @@ source: crates/ra_hir/src/ty/tests.rs
20[127; 132) 'clone': fn clone<bool>(&T) -> T 20[127; 132) 'clone': fn clone<bool>(&T) -> T
21[127; 135) 'clone(z)': bool 21[127; 135) 'clone(z)': bool
22[133; 134) 'z': &bool 22[133; 134) 'z': &bool
23[173; 191) 'id::<i...tring>': fn id<i32>(T) -> T
24[173; 194) 'id::<i...ng>(1)': i32
25[192; 193) '1': i32
23 26
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap
index 369705f84..8ff6e55a6 100644
--- a/crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap
+++ b/crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap
@@ -1,5 +1,5 @@
1--- 1---
2created: "2019-01-26T17:46:03.856278205+00:00" 2created: "2019-01-26T18:16:16.530712344+00:00"
3creator: [email protected] 3creator: [email protected]
4expression: "&result" 4expression: "&result"
5source: crates/ra_hir/src/ty/tests.rs 5source: crates/ra_hir/src/ty/tests.rs
@@ -11,9 +11,9 @@ source: crates/ra_hir/src/ty/tests.rs
11[44; 46) 'id': fn id<u32>(T) -> T 11[44; 46) 'id': fn id<u32>(T) -> T
12[44; 52) 'id(1u32)': u32 12[44; 52) 'id(1u32)': u32
13[47; 51) '1u32': u32 13[47; 51) '1u32': u32
14[58; 68) 'id::<i128>': fn id<i32>(T) -> T 14[58; 68) 'id::<i128>': fn id<i128>(T) -> T
15[58; 71) 'id::<i128>(1)': i32 15[58; 71) 'id::<i128>(1)': i128
16[69; 70) '1': i32 16[69; 70) '1': i128
17[81; 82) 'x': u64 17[81; 82) 'x': u64
18[90; 92) 'id': fn id<u64>(T) -> T 18[90; 92) 'id': fn id<u64>(T) -> T
19[90; 95) 'id(1)': u64 19[90; 95) 'id(1)': u64
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 40913b164..fac566626 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -611,6 +611,9 @@ fn test() {
611 let y = 10u32; 611 let y = 10u32;
612 id(y); 612 id(y);
613 let x: bool = clone(z); 613 let x: bool = clone(z);
614
615 // bad turbofish - ignore!
616 id::<i128, String>(1);
614} 617}
615"#, 618"#,
616 ); 619 );