Merge pull request #21649 from Albab-Hasan/fix/assignment-rhs-never-coercion

fix: use `ExprIsRead::Yes` for rhs of ordinary assignments
This commit is contained in:
Chayim Refael Friedman 2026-02-15 14:16:24 +00:00 committed by GitHub
commit 5ad533b09c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View file

@ -751,7 +751,7 @@ impl<'db> InferenceContext<'_, 'db> {
if let Some(lhs_ty) = lhs_ty {
self.write_pat_ty(target, lhs_ty);
self.infer_expr_coerce(value, &Expectation::has_type(lhs_ty), ExprIsRead::No);
self.infer_expr_coerce(value, &Expectation::has_type(lhs_ty), ExprIsRead::Yes);
} else {
let rhs_ty = self.infer_expr(value, &Expectation::none(), ExprIsRead::Yes);
let resolver_guard =

View file

@ -786,6 +786,22 @@ fn coerce_ref_mut_binding() -> ! {
)
}
#[test]
fn assign_never_place_no_mismatch() {
check_no_mismatches(
r#"
//- minicore: sized
fn foo() {
unsafe {
let p: *mut ! = 0 as _;
let mut x: () = ();
x = *p;
}
}
"#,
);
}
#[test]
fn never_place_isnt_diverging() {
check_infer_with_mismatches(