rust/compiler/rustc_mir_build
Chris Denton 8dd26cb195
Rollup merge of #140022 - dianne:box-deref-pats, r=Nadrieril
allow deref patterns to move out of boxes

This adds a case to lower deref patterns on boxes using a built-in deref instead of a `Deref::deref` or `DerefMut::deref_mut` call: if `deref!(inner): Box<T>` is matching on place `place`, the inner pattern `inner` now matches on `*place` rather than a temporary. No longer needing to call a method also means it won't borrow the scrutinee in match arms. This allows for bindings in `inner` to move out of `*place`.

For comparison with box patterns, this uses the same MIR lowering but different THIR. Consequently, deref patterns on boxes are treated the same as any other deref patterns in match exhaustiveness analysis. Box patterns can't quite be implemented in terms of deref patterns until exhaustiveness checking for deref patterns is implemented (I'll open a PR for exhaustiveness soon!).

Tracking issue: #87121

r? ``@Nadrieril``
2025-04-28 23:29:15 +00:00
..
src Rollup merge of #140022 - dianne:box-deref-pats, r=Nadrieril 2025-04-28 23:29:15 +00:00
Cargo.toml Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
messages.ftl reword pattern migration diagnostic to make sense in all editions 2025-02-03 01:50:14 -08:00