Merge pull request #21647 from Albab-Hasan/fix/contains-explicit-ref-binding-missing-refmut

fix: handle `ref mut` bindings in `contains_explicit_ref_binding`
This commit is contained in:
Chayim Refael Friedman 2026-02-15 11:36:30 +00:00 committed by GitHub
commit b03c8420d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 1 deletions

View File

@ -673,7 +673,7 @@ impl<'db> InferenceContext<'_, 'db> {
pub(super) fn contains_explicit_ref_binding(body: &Body, pat_id: PatId) -> bool {
let mut res = false;
body.walk_pats(pat_id, &mut |pat| {
res |= matches!(body[pat], Pat::Bind { id, .. } if body[id].mode == BindingAnnotation::Ref);
res |= matches!(body[pat], Pat::Bind { id, .. } if matches!(body[id].mode, BindingAnnotation::Ref | BindingAnnotation::RefMut));
});
res
}

View File

@ -760,6 +760,32 @@ fn coerce_ref_binding() -> ! {
)
}
#[test]
fn diverging_place_match_ref_mut() {
check_infer_with_mismatches(
r#"
//- minicore: sized
fn coerce_ref_mut_binding() -> ! {
unsafe {
let x: *mut ! = 0 as _;
let ref mut _x: () = *x;
}
}
"#,
expect![[r#"
33..120 '{ ... } }': !
39..118 'unsafe... }': !
60..61 'x': *mut !
72..73 '0': i32
72..78 '0 as _': *mut !
92..102 'ref mut _x': &'? mut ()
109..111 '*x': !
110..111 'x': *mut !
109..111: expected (), got !
"#]],
)
}
#[test]
fn never_place_isnt_diverging() {
check_infer_with_mismatches(