@@ -774,21 +774,26 @@ fn constructor_sub_pattern_tys<'a, 'tcx: 'a>(cx: &MatchCheckCtxt<'a, 'tcx>,
774
774
} ,
775
775
ty:: TyRef ( _, ref ty_and_mut) => vec ! [ ty_and_mut. ty] ,
776
776
ty:: TyAdt ( adt, substs) => {
777
- adt. variants [ ctor. variant_index_for_adt ( adt) ] . fields . iter ( ) . map ( |field| {
778
- let is_visible = adt. is_enum ( )
779
- || field. vis . is_accessible_from ( cx. module , cx. tcx ) ;
780
- if is_visible {
781
- field. ty ( cx. tcx , substs)
782
- } else {
783
- // Treat all non-visible fields as nil. They
784
- // can't appear in any other pattern from
785
- // this match (because they are private),
786
- // so their type does not matter - but
787
- // we don't want to know they are
788
- // uninhabited.
789
- cx. tcx . mk_nil ( )
790
- }
791
- } ) . collect ( )
777
+ if adt. is_box ( ) {
778
+ // Use T as the sub pattern type of Box<T>.
779
+ vec ! [ substs[ 0 ] . as_type( ) . unwrap( ) ]
780
+ } else {
781
+ adt. variants [ ctor. variant_index_for_adt ( adt) ] . fields . iter ( ) . map ( |field| {
782
+ let is_visible = adt. is_enum ( )
783
+ || field. vis . is_accessible_from ( cx. module , cx. tcx ) ;
784
+ if is_visible {
785
+ field. ty ( cx. tcx , substs)
786
+ } else {
787
+ // Treat all non-visible fields as nil. They
788
+ // can't appear in any other pattern from
789
+ // this match (because they are private),
790
+ // so their type does not matter - but
791
+ // we don't want to know they are
792
+ // uninhabited.
793
+ cx. tcx . mk_nil ( )
794
+ }
795
+ } ) . collect ( )
796
+ }
792
797
}
793
798
_ => vec ! [ ] ,
794
799
}
0 commit comments