mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Implement binary operator overloading type inference
This commit is contained in:
parent
0fb069c5b0
commit
4e49b2f731
3 changed files with 120 additions and 5 deletions
|
@ -531,13 +531,20 @@ impl<'a> InferenceContext<'a> {
|
|||
_ => Expectation::none(),
|
||||
};
|
||||
let lhs_ty = self.infer_expr(*lhs, &lhs_expectation);
|
||||
// FIXME: find implementation of trait corresponding to operation
|
||||
// symbol and resolve associated `Output` type
|
||||
let rhs_expectation = op::binary_op_rhs_expectation(*op, lhs_ty.clone());
|
||||
let rhs_ty = self.infer_expr(*rhs, &Expectation::has_type(rhs_expectation));
|
||||
|
||||
// FIXME: similar as above, return ty is often associated trait type
|
||||
op::binary_op_return_ty(*op, lhs_ty, rhs_ty)
|
||||
let ret = op::binary_op_return_ty(*op, lhs_ty.clone(), rhs_ty.clone());
|
||||
|
||||
if ret == Ty::Unknown {
|
||||
self.resolve_associated_type_with_params(
|
||||
lhs_ty,
|
||||
self.resolve_binary_op_output(op),
|
||||
&[rhs_ty],
|
||||
)
|
||||
} else {
|
||||
ret
|
||||
}
|
||||
}
|
||||
_ => Ty::Unknown,
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue