Skip to content

Commit 337ccc7

Browse files
bors[bot]lnicola
andauthored
Merge #9973
9973: Handle coercion on binary operator RHS r=flodiebold a=lnicola Closes #9968 CC #8961 Co-authored-by: Laurențiu Nicola <[email protected]>
2 parents 19348bc + 104d612 commit 337ccc7

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

crates/hir_ty/src/infer/expr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,8 @@ impl<'a> InferenceContext<'a> {
679679
let lhs_ty = self.infer_expr(*lhs, &lhs_expectation);
680680
let lhs_ty = self.resolve_ty_shallow(&lhs_ty);
681681
let rhs_expectation = op::binary_op_rhs_expectation(*op, lhs_ty.clone());
682-
let rhs_ty = self.infer_expr(*rhs, &Expectation::has_type(rhs_expectation));
682+
let rhs_ty =
683+
self.infer_expr_coerce(*rhs, &Expectation::has_type(rhs_expectation));
683684
let rhs_ty = self.resolve_ty_shallow(&rhs_ty);
684685

685686
let ret = op::binary_op_return_ty(*op, lhs_ty.clone(), rhs_ty.clone());

crates/hir_ty/src/tests/coercion.rs

+18
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,24 @@ fn foo() {
257257
);
258258
}
259259

260+
#[test]
261+
fn assign_coerce() {
262+
check_no_mismatches(
263+
r"
264+
//- minicore: deref
265+
struct String;
266+
impl core::ops::Deref for String { type Target = str; }
267+
fn g(_text: &str) {}
268+
fn f(text: &str) {
269+
let mut text = text;
270+
let tmp = String;
271+
text = &tmp;
272+
g(text);
273+
}
274+
",
275+
);
276+
}
277+
260278
#[test]
261279
fn coerce_fn_item_to_fn_ptr() {
262280
check_no_mismatches(

0 commit comments

Comments
 (0)