Use type information from the turbofish
This commit is contained in:
parent
0da1e8b2f8
commit
f6eb44cd9e
@ -1157,6 +1157,32 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||
let typable = typable?;
|
||||
let ty = self.db.type_for_def(typable);
|
||||
let ty = self.insert_type_vars(ty);
|
||||
|
||||
// try to get generic parameters from the path and add them to the
|
||||
// function type substitutions
|
||||
if let Ty::FnDef { ref def, .. } = ty {
|
||||
let last_seg_bindings = path
|
||||
.segments
|
||||
.last()
|
||||
.and_then(|segment| segment.args_and_bindings.as_ref());
|
||||
if let Some(generic_args) = last_seg_bindings {
|
||||
let generic_params = def.generic_params(self.db);
|
||||
if generic_args.args.len() == generic_params.params.len() {
|
||||
let substs = Ty::substs_from_path(
|
||||
self.db,
|
||||
&self.module,
|
||||
self.impl_block.as_ref(),
|
||||
&generic_params,
|
||||
path,
|
||||
(*def).into(),
|
||||
);
|
||||
return Some(ty.apply_substs(substs));
|
||||
} else {
|
||||
// ERROR: incorrect number of type params
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some(ty)
|
||||
}
|
||||
|
||||
@ -1387,9 +1413,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||
let callee_ty = self.infer_expr(*callee, &Expectation::none());
|
||||
let (param_tys, ret_ty) = match &callee_ty {
|
||||
Ty::FnPtr(sig) => (sig.input.clone(), sig.output.clone()),
|
||||
Ty::FnDef {
|
||||
def, substs, sig, ..
|
||||
} => {
|
||||
Ty::FnDef { substs, sig, .. } => {
|
||||
let ret_ty = sig.output.clone().subst(&substs);
|
||||
let param_tys = sig
|
||||
.input
|
||||
@ -1437,9 +1461,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||
(Ty::Unknown, Vec::new(), sig.output.clone())
|
||||
}
|
||||
}
|
||||
Ty::FnDef {
|
||||
def, substs, sig, ..
|
||||
} => {
|
||||
Ty::FnDef { substs, sig, .. } => {
|
||||
let ret_ty = sig.output.clone().subst(&substs);
|
||||
|
||||
if sig.input.len() > 0 {
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
created: "2019-01-26T17:46:03.963745056+00:00"
|
||||
created: "2019-01-26T18:16:16.568375+00:00"
|
||||
creator: insta@0.5.2
|
||||
expression: "&result"
|
||||
source: crates/ra_hir/src/ty/tests.rs
|
||||
@ -10,7 +10,7 @@ source: crates/ra_hir/src/ty/tests.rs
|
||||
[44; 45) 'x': &[unknown]
|
||||
[56; 65) '{ x }': &[unknown]
|
||||
[62; 63) 'x': &[unknown]
|
||||
[77; 138) '{ ...(z); }': ()
|
||||
[77; 197) '{ ...(1); }': ()
|
||||
[87; 88) 'y': u32
|
||||
[91; 96) '10u32': u32
|
||||
[102; 104) 'id': fn id<u32>(T) -> T
|
||||
@ -20,4 +20,7 @@ source: crates/ra_hir/src/ty/tests.rs
|
||||
[127; 132) 'clone': fn clone<bool>(&T) -> T
|
||||
[127; 135) 'clone(z)': bool
|
||||
[133; 134) 'z': &bool
|
||||
[173; 191) 'id::<i...tring>': fn id<i32>(T) -> T
|
||||
[173; 194) 'id::<i...ng>(1)': i32
|
||||
[192; 193) '1': i32
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
created: "2019-01-26T17:46:03.856278205+00:00"
|
||||
created: "2019-01-26T18:16:16.530712344+00:00"
|
||||
creator: insta@0.5.2
|
||||
expression: "&result"
|
||||
source: crates/ra_hir/src/ty/tests.rs
|
||||
@ -11,9 +11,9 @@ source: crates/ra_hir/src/ty/tests.rs
|
||||
[44; 46) 'id': fn id<u32>(T) -> T
|
||||
[44; 52) 'id(1u32)': u32
|
||||
[47; 51) '1u32': u32
|
||||
[58; 68) 'id::<i128>': fn id<i32>(T) -> T
|
||||
[58; 71) 'id::<i128>(1)': i32
|
||||
[69; 70) '1': i32
|
||||
[58; 68) 'id::<i128>': fn id<i128>(T) -> T
|
||||
[58; 71) 'id::<i128>(1)': i128
|
||||
[69; 70) '1': i128
|
||||
[81; 82) 'x': u64
|
||||
[90; 92) 'id': fn id<u64>(T) -> T
|
||||
[90; 95) 'id(1)': u64
|
||||
|
@ -611,6 +611,9 @@ fn test() {
|
||||
let y = 10u32;
|
||||
id(y);
|
||||
let x: bool = clone(z);
|
||||
|
||||
// bad turbofish - ignore!
|
||||
id::<i128, String>(1);
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user