@@ -165,13 +165,14 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
165
165
& self ,
166
166
ty : RevealedTy < ' tcx > ,
167
167
variant : & ' tcx VariantDef ,
168
- ) -> impl Iterator < Item = ( FieldIdx , RevealedTy < ' tcx > ) > + Captures < ' p > + Captures < ' _ > {
168
+ ) -> impl Iterator < Item = ( FieldIdx , RevealedTy < ' tcx > , bool ) > + Captures < ' p > + Captures < ' _ >
169
+ {
169
170
let cx = self ;
170
171
let ty:: Adt ( adt, args) = ty. kind ( ) else { bug ! ( ) } ;
171
- // Whether we must not match the fields of this variant exhaustively.
172
+ // Whether we must avoid matching the fields of this variant exhaustively.
172
173
let is_non_exhaustive = variant. is_field_list_non_exhaustive ( ) && !adt. did ( ) . is_local ( ) ;
173
174
174
- variant. fields . iter ( ) . enumerate ( ) . filter_map ( move |( i, field) | {
175
+ variant. fields . iter ( ) . enumerate ( ) . map ( move |( i, field) | {
175
176
let ty = field. ty ( cx. tcx , args) ;
176
177
// `field.ty()` doesn't normalize after instantiating.
177
178
let ty = cx. tcx . normalize_erasing_regions ( cx. param_env , ty) ;
@@ -180,12 +181,9 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
180
181
|| cx. tcx . features ( ) . min_exhaustive_patterns )
181
182
&& cx. is_uninhabited ( ty) ;
182
183
183
- if is_uninhabited && ( !is_visible || is_non_exhaustive) {
184
- None
185
- } else {
186
- let ty = cx. reveal_opaque_ty ( ty) ;
187
- Some ( ( FieldIdx :: new ( i) , ty) )
188
- }
184
+ let skip = is_uninhabited && ( !is_visible || is_non_exhaustive) ;
185
+ let ty = cx. reveal_opaque_ty ( ty) ;
186
+ ( FieldIdx :: new ( i) , ty, skip)
189
187
} )
190
188
}
191
189
@@ -229,7 +227,10 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
229
227
} else {
230
228
let variant =
231
229
& adt. variant ( RustcMatchCheckCtxt :: variant_index_for_adt ( & ctor, * adt) ) ;
232
- let tys = cx. list_variant_nonhidden_fields ( ty, variant) . map ( |( _, ty) | ty) ;
230
+ let tys = cx
231
+ . list_variant_nonhidden_fields ( ty, variant)
232
+ . filter ( |( _, _, skip) | !skip)
233
+ . map ( |( _, ty, _) | ty) ;
233
234
cx. dropless_arena . alloc_from_iter ( tys)
234
235
}
235
236
}
@@ -276,7 +277,9 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
276
277
} else {
277
278
let variant =
278
279
& adt. variant ( RustcMatchCheckCtxt :: variant_index_for_adt ( & ctor, * adt) ) ;
279
- self . list_variant_nonhidden_fields ( ty, variant) . count ( )
280
+ self . list_variant_nonhidden_fields ( ty, variant)
281
+ . filter ( |( _, _, skip) | !skip)
282
+ . count ( )
280
283
}
281
284
}
282
285
_ => bug ! ( "Unexpected type for constructor `{ctor:?}`: {ty:?}" ) ,
@@ -523,12 +526,14 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
523
526
// For each field in the variant, we store the relevant index into `self.fields` if any.
524
527
let mut field_id_to_id: Vec < Option < usize > > =
525
528
( 0 ..variant. fields . len ( ) ) . map ( |_| None ) . collect ( ) ;
526
- let tys = cx. list_variant_nonhidden_fields ( ty, variant) . enumerate ( ) . map (
527
- |( i, ( field, ty) ) | {
529
+ let tys = cx
530
+ . list_variant_nonhidden_fields ( ty, variant)
531
+ . filter ( |( _, _, skip) | !skip)
532
+ . enumerate ( )
533
+ . map ( |( i, ( field, ty, _) ) | {
528
534
field_id_to_id[ field. index ( ) ] = Some ( i) ;
529
535
ty
530
- } ,
531
- ) ;
536
+ } ) ;
532
537
fields = tys. map ( |ty| DeconstructedPat :: wildcard ( ty) ) . collect ( ) ;
533
538
for pat in subpatterns {
534
539
if let Some ( i) = field_id_to_id[ pat. field . index ( ) ] {
@@ -778,8 +783,9 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
778
783
let variant = & adt_def. variant ( variant_index) ;
779
784
let subpatterns = cx
780
785
. list_variant_nonhidden_fields ( * pat. ty ( ) , variant)
786
+ . filter ( |( _, _, skip) | !skip)
781
787
. zip ( subpatterns)
782
- . map ( |( ( field, _ty) , pattern) | FieldPat { field, pattern } )
788
+ . map ( |( ( field, _ty, _ ) , pattern) | FieldPat { field, pattern } )
783
789
. collect ( ) ;
784
790
785
791
if adt_def. is_enum ( ) {
0 commit comments