mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Handle coercion on binary operator RHS
This commit is contained in:
parent
3f4c515223
commit
104d6124d7
2 changed files with 20 additions and 1 deletions
|
@ -679,7 +679,8 @@ impl<'a> InferenceContext<'a> {
|
||||||
let lhs_ty = self.infer_expr(*lhs, &lhs_expectation);
|
let lhs_ty = self.infer_expr(*lhs, &lhs_expectation);
|
||||||
let lhs_ty = self.resolve_ty_shallow(&lhs_ty);
|
let lhs_ty = self.resolve_ty_shallow(&lhs_ty);
|
||||||
let rhs_expectation = op::binary_op_rhs_expectation(*op, lhs_ty.clone());
|
let rhs_expectation = op::binary_op_rhs_expectation(*op, lhs_ty.clone());
|
||||||
let rhs_ty = self.infer_expr(*rhs, &Expectation::has_type(rhs_expectation));
|
let rhs_ty =
|
||||||
|
self.infer_expr_coerce(*rhs, &Expectation::has_type(rhs_expectation));
|
||||||
let rhs_ty = self.resolve_ty_shallow(&rhs_ty);
|
let rhs_ty = self.resolve_ty_shallow(&rhs_ty);
|
||||||
|
|
||||||
let ret = op::binary_op_return_ty(*op, lhs_ty.clone(), rhs_ty.clone());
|
let ret = op::binary_op_return_ty(*op, lhs_ty.clone(), rhs_ty.clone());
|
||||||
|
|
|
@ -257,6 +257,24 @@ fn foo() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn assign_coerce() {
|
||||||
|
check_no_mismatches(
|
||||||
|
r"
|
||||||
|
//- minicore: deref
|
||||||
|
struct String;
|
||||||
|
impl core::ops::Deref for String { type Target = str; }
|
||||||
|
fn g(_text: &str) {}
|
||||||
|
fn f(text: &str) {
|
||||||
|
let mut text = text;
|
||||||
|
let tmp = String;
|
||||||
|
text = &tmp;
|
||||||
|
g(text);
|
||||||
|
}
|
||||||
|
",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn coerce_fn_item_to_fn_ptr() {
|
fn coerce_fn_item_to_fn_ptr() {
|
||||||
check_no_mismatches(
|
check_no_mismatches(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue