@@ -833,6 +833,11 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
833833 let kind = match pat. ctor ( ) {
834834 Bool ( b) => PatKind :: Constant { value : mir:: Const :: from_bool ( cx. tcx , * b) } ,
835835 IntRange ( range) => return self . hoist_pat_range ( range, * pat. ty ( ) ) ,
836+ Struct if pat. ty ( ) . is_box ( ) => {
837+ // Outside of the `alloc` crate, the only way to create a struct pattern
838+ // of type `Box` is to use a `box` pattern via #[feature(box_patterns)].
839+ PatKind :: Box { subpattern : hoist ( & pat. fields [ 0 ] ) }
840+ }
836841 Struct | Variant ( _) | UnionField => match pat. ty ( ) . kind ( ) {
837842 ty:: Tuple ( ..) => PatKind :: StructLike {
838843 enum_info : EnumInfo :: NotEnum ,
@@ -841,12 +846,6 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
841846 . map ( |( i, pattern) | FieldPat { field : FieldIdx :: new ( i) , pattern } )
842847 . collect ( ) ,
843848 } ,
844- ty:: Adt ( adt_def, _) if adt_def. is_box ( ) => {
845- // Without `box_patterns`, the only legal pattern of type `Box` is `_` (outside
846- // of `std`). So this branch is only reachable when the feature is enabled and
847- // the pattern is a box pattern.
848- PatKind :: Deref { subpattern : subpatterns. next ( ) . unwrap ( ) }
849- }
850849 & ty:: Adt ( adt_def, _) => {
851850 let variant_index = RustcPatCtxt :: variant_index_for_adt ( & pat. ctor ( ) , adt_def) ;
852851 let subpatterns = subpatterns
0 commit comments