summary refs log tree commit diff
path: root/compiler/rustc_pattern_analysis/src/rustc.rs
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2024-08-01 20:29:06 +1000
committerZalathar <Zalathar@users.noreply.github.com>2024-08-07 20:52:47 +1000
commita5ed6fb646f554a3e2071dfdd3a3de2f83b759ec (patch)
treef945f67c2de8d5362ad711795e9c13d7de13685b /compiler/rustc_pattern_analysis/src/rustc.rs
parent7f48851416c0faf0333a23ba37904f4a407c723b (diff)
downloadrust-a5ed6fb646f554a3e2071dfdd3a3de2f83b759ec.tar.gz
rust-a5ed6fb646f554a3e2071dfdd3a3de2f83b759ec.zip
Split out hoisting/printing of `box` patterns
Diffstat (limited to 'compiler/rustc_pattern_analysis/src/rustc.rs')
-rw-r--r--compiler/rustc_pattern_analysis/src/rustc.rs11
1 files changed, 5 insertions, 6 deletions
diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs
index 9fa5222452e..7eee5220ce4 100644
--- a/compiler/rustc_pattern_analysis/src/rustc.rs
+++ b/compiler/rustc_pattern_analysis/src/rustc.rs
@@ -833,6 +833,11 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
         let kind = match pat.ctor() {
             Bool(b) => PatKind::Constant { value: mir::Const::from_bool(cx.tcx, *b) },
             IntRange(range) => return self.hoist_pat_range(range, *pat.ty()),
+            Struct if pat.ty().is_box() => {
+                // Outside of the `alloc` crate, the only way to create a struct pattern
+                // of type `Box` is to use a `box` pattern via #[feature(box_patterns)].
+                PatKind::Box { subpattern: hoist(&pat.fields[0]) }
+            }
             Struct | Variant(_) | UnionField => match pat.ty().kind() {
                 ty::Tuple(..) => PatKind::StructLike {
                     enum_info: EnumInfo::NotEnum,
@@ -841,12 +846,6 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
                         .map(|(i, pattern)| FieldPat { field: FieldIdx::new(i), pattern })
                         .collect(),
                 },
-                ty::Adt(adt_def, _) if adt_def.is_box() => {
-                    // Without `box_patterns`, the only legal pattern of type `Box` is `_` (outside
-                    // of `std`). So this branch is only reachable when the feature is enabled and
-                    // the pattern is a box pattern.
-                    PatKind::Deref { subpattern: subpatterns.next().unwrap() }
-                }
                 &ty::Adt(adt_def, _) => {
                     let variant_index = RustcPatCtxt::variant_index_for_adt(&pat.ctor(), adt_def);
                     let subpatterns = subpatterns