Skip to content

Commit 969d017

Browse files
Make sure to enforce ~const DerefMut on mutability
1 parent 148e7e0 commit 969d017

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
274274
Adjust::Pointer(_pointer_coercion) => {
275275
// FIXME(effects): We should probably enforce these.
276276
}
277-
Adjust::ReborrowPin(_region, _mutability) => {
277+
Adjust::ReborrowPin(_mutability) => {
278278
// FIXME(effects): We could enforce these; they correspond to
279279
// `&mut T: DerefMut` tho, so it's kinda moot.
280280
}

compiler/rustc_hir_typeck/src/place_op.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
289289
)
290290
{
291291
let method = self.register_infer_ok_obligations(ok);
292-
let ty::Ref(_, _, mutbl) = *method.sig.output().kind() else {
293-
span_bug!(
294-
self.tcx.def_span(method.def_id),
295-
"expected DerefMut to return a &mut"
296-
);
297-
};
298-
*deref = OverloadedDeref { mutbl, span: deref.span };
292+
if let ty::Ref(_, _, mutbl) = *method.sig.output().kind() {
293+
*deref = OverloadedDeref { mutbl, span: deref.span };
294+
}
295+
self.enforce_context_effects(expr.span, method.def_id, method.args);
299296
// If this is a union field, also throw an error for `DerefMut` of `ManuallyDrop` (see RFC 2514).
300297
// This helps avoid accidental drops.
301298
if inside_union

0 commit comments

Comments
 (0)