pub(super) fn wildcards(pcx: PatCtxt<'_, 'p, 'tcx>, constructor: &Constructor<'tcx>) -> Self {
        let ty = pcx.ty;
        let cx = pcx.cx;
        let wildcard_from_ty = |ty| &*cx.pattern_arena.alloc(Pat::wildcard_from_ty(ty));

        let ret = match constructor {
            Single | Variant(_) => match ty.kind() {
                ty::Tuple(ref fs) => {
                    Fields::wildcards_from_tys(cx, fs.into_iter().map(|ty| ty.expect_ty()))
                }
                ty::Ref(_, rty, _) => Fields::from_single_pattern(wildcard_from_ty(rty)),
                ty::Adt(adt, substs) => {
                    if adt.is_box() {
                        // Use T as the sub pattern type of Box<T>.
                        Fields::from_single_pattern(wildcard_from_ty(substs.type_at(0)))
                    } else {
                        let variant = &adt.variants[constructor.variant_index_for_adt(adt)];
                        // Whether we must not match the fields of this variant exhaustively.
                        let is_non_exhaustive =
                            variant.is_field_list_non_exhaustive() && !adt.did.is_local();
                        let field_tys = variant.fields.iter().map(|field| field.ty(cx.tcx, substs));
                        // In the following cases, we don't need to filter out any fields. This is
                        // the vast majority of real cases, since uninhabited fields are uncommon.
                        let has_no_hidden_fields = (adt.is_enum() && !is_non_exhaustive)
                            || !field_tys.clone().any(|ty| cx.is_uninhabited(ty));

                        if has_no_hidden_fields {
                            Fields::wildcards_from_tys(cx, field_tys)
                        } else {
                            let mut kept_count = 0;
                            let fields = variant
                                .fields
                                .iter()
                                .map(|field| {
                                    let ty = field.ty(cx.tcx, substs);
                                    let is_visible = adt.is_enum()
                                        || field.vis.is_accessible_from(cx.module, cx.tcx);
                                    let is_uninhabited = cx.is_uninhabited(ty);

                                    // In the cases of either a `#[non_exhaustive]` field list
                                    // or a non-public field, we hide uninhabited fields in
                                    // order not to reveal the uninhabitedness of the whole
                                    // variant.
                                    if is_uninhabited && (!is_visible || is_non_exhaustive) {
                                        FilteredField::Hidden(ty)
                                    } else {
                                        kept_count += 1;
                                        FilteredField::Kept(wildcard_from_ty(ty))
                                    }
                                })
                                .collect();
                            Fields::Filtered { fields, kept_count }
                        }
                    }
                }
                _ => bug!("Unexpected type for `Single` constructor: {:?}", ty),
            },
            Slice(slice) => match *ty.kind() {
                ty::Slice(ty) | ty::Array(ty, _) => {
                    let arity = slice.arity();
                    Fields::wildcards_from_tys(cx, (0..arity).map(|_| ty))
                }
                _ => bug!("bad slice pattern {:?} {:?}", constructor, ty),
            },
            Str(..) | FloatRange(..) | IntRange(..) | NonExhaustive | Opaque | Wildcard => {
                Fields::empty()
            }
        };
        debug!("Fields::wildcards({:?}, {:?}) = {:#?}", constructor, ty, ret);
        ret
    }
/// Creates a new list of wildcard fields for a given constructor.
Creates a new list of wildcard fields for a given constructor.
Creates a new list of wildcard fields for a given constructor .
pub(super) fn wildcards(pcx: PatCtxt<'_, 'p, 'tcx>, constructor: &Constructor<'tcx>) -> Self {
        let ty = pcx.ty;
        let cx = pcx.cx;
        let wildcard_from_ty = |ty| &*cx.pattern_arena.alloc(Pat::wildcard_from_ty(ty));
        let ret = match constructor {
            Single | Variant(_) => match ty.kind() {
                ty::Tuple(ref fs) => {
                    Fields::wildcards_from_tys(cx, fs.into_iter().map(|ty| ty.expect_ty()))
                }
                ty::Ref(_, rty, _) => Fields::from_single_pattern(wildcard_from_ty(rty)),
                ty::Adt(adt, substs) => {
                    if adt.is_box() {
                        // Use T as the sub pattern type of Box<T>.
                        Fields::from_single_pattern(wildcard_from_ty(substs.type_at(0)))
                    } else {
                        let variant = &adt.variants[constructor.variant_index_for_adt(adt)];
                        // Whether we must not match the fields of this variant exhaustively.
                        let is_non_exhaustive =
                            variant.is_field_list_non_exhaustive() && !adt.did.is_local();
                        let field_tys = variant.fields.iter().map(|field| field.ty(cx.tcx, substs));
                        // In the following cases, we don't need to filter out any fields. This is
                        // the vast majority of real cases, since uninhabited fields are uncommon.
                        let has_no_hidden_fields = (adt.is_enum() && !is_non_exhaustive)
                            || !field_tys.clone().any(|ty| cx.is_uninhabited(ty));
                        if has_no_hidden_fields {
                            Fields::wildcards_from_tys(cx, field_tys)
                        } else {
                            let mut kept_count = 0;
                            let fields = variant
                                .fields
                                .iter()
                                .map(|field| {
                                    let ty = field.ty(cx.tcx, substs);
                                    let is_visible = adt.is_enum()
                                        || field.vis.is_accessible_from(cx.module, cx.tcx);
                                    let is_uninhabited = cx.is_uninhabited(ty);
                                    // In the cases of either a `#[non_exhaustive]` field list
                                    // or a non-public field, we hide uninhabited fields in
                                    // order not to reveal the uninhabitedness of the whole
                                    // variant.
                                    if is_uninhabited && (!is_visible || is_non_exhaustive) {
                                        FilteredField::Hidden(ty)
                                    } else {
                                        kept_count += 1;
                                        FilteredField::Kept(wildcard_from_ty(ty))
                                    }
                                })
                                .collect();
                            Fields::Filtered { fields, kept_count }
                        }
                    }
                }
                _ => bug!("Unexpected type for `Single` constructor: {:?}", ty),
            },
            Slice(slice) => match *ty.kind() {
                ty::Slice(ty) | ty::Array(ty, _) => {
                    let arity = slice.arity();
                    Fields::wildcards_from_tys(cx, (0..arity).map(|_| ty))
                }
                _ => bug!("bad slice pattern {:?} {:?}", constructor, ty),
            },
            Str(..) | FloatRange(..) | IntRange(..) | NonExhaustive | Opaque | Wildcard => {
                Fields::empty()
            }
        };
        debug!("Fields::wildcards({:?}, {:?}) = {:#?}", constructor, ty, ret);
        ret
    }
pub ( super ) fn wildcards ( pcx : PatCtxt < ' _ , ' p , ' tcx > , constructor : & Constructor < ' tcx > ) -> Self { let ty = pcx . ty ; let cx = pcx . cx ; let wildcard_from_ty = | ty | & * cx . pattern_arena . alloc ( Pat :: wildcard_from_ty ( ty ) ) ; let ret = match constructor { Single | Variant ( _ ) => match ty . kind ( ) { ty :: Tuple ( ref fs ) => { Fields :: wildcards_from_tys ( cx , fs . into_iter ( ) . map ( | ty | ty . expect_ty ( ) ) ) } ty :: Ref ( _ , rty , _ ) => Fields :: from_single_pattern ( wildcard_from_ty ( rty ) ) , ty :: Adt ( adt , substs ) => { if adt . is_box ( ) { // Use T as the sub pattern type of Box<T>. Fields :: from_single_pattern ( wildcard_from_ty ( substs . type_at ( 0 ) ) ) } else { let variant = & adt . variants [ constructor . variant_index_for_adt ( adt ) ] ; // Whether we must not match the fields of this variant exhaustively. let is_non_exhaustive = variant . is_field_list_non_exhaustive ( ) && ! adt . did . is_local ( ) ; let field_tys = variant . fields . iter ( ) . map ( | field | field . ty ( cx . tcx , substs ) ) ; // In the following cases, we don't need to filter out any fields. This is // the vast majority of real cases, since uninhabited fields are uncommon. let has_no_hidden_fields = ( adt . is_enum ( ) && ! is_non_exhaustive ) || ! field_tys . clone ( ) . any ( | ty | cx . is_uninhabited ( ty ) ) ; if has_no_hidden_fields { Fields :: wildcards_from_tys ( cx , field_tys ) } else { let mut kept_count = 0 ; let fields = variant . fields . iter ( ) . map ( | field | { let ty = field . ty ( cx . tcx , substs ) ; let is_visible = adt . is_enum ( ) || field . vis . is_accessible_from ( cx . module , cx . tcx ) ; let is_uninhabited = cx . is_uninhabited ( ty ) ; // In the cases of either a `#[non_exhaustive]` field list // or a non-public field, we hide uninhabited fields in // order not to reveal the uninhabitedness of the whole // variant. if is_uninhabited && ( ! is_visible || is_non_exhaustive ) { FilteredField :: Hidden ( ty ) } else { kept_count += 1 ; FilteredField :: Kept ( wildcard_from_ty ( ty ) ) } } ) . collect ( ) ; Fields :: Filtered { fields , kept_count } } } } _ => bug ! ( " " ty ) , } , Slice ( slice ) => match * ty . kind ( ) { ty :: Slice ( ty ) | ty :: Array ( ty , _ ) => { let arity = slice . arity ( ) ; Fields :: wildcards_from_tys ( cx , ( 0 .. arity ) . map ( | _ | ty ) ) } _ => bug ! ( " " constructor ty ) , } , Str ( .. ) | FloatRange ( .. ) | IntRange ( .. ) | NonExhaustive | Opaque | Wildcard => { Fields :: empty ( ) } } ; debug ! ( " " constructor ty ret ) ; ret }
Creates a new list of wildcard fields for a given constructor.
Creates a new list of wildcard fields for a given constructor .
pcx
PatCtxt<'_, 'p, 'tcx>
constructor
&Constructor<'tcx>
pcx
PatCtxt<'_, 'p, 'tcx>
constructor
&Constructor<'tcx>