pub fn with_field_tys<'tcx, R, F>(tcx: &ty::ctxt<'tcx>,
                                  ty: Ty<'tcx>,
                                  node_id_opt: Option<ast::NodeId>,
                                  op: F)
                                  -> R where
    F: FnOnce(ty::Disr, &[ty::field<'tcx>]) -> R,
{
    match ty.sty {
        ty::TyStruct(did, substs) => {
            let fields = tcx.struct_fields(did, substs);
            let fields = monomorphize::normalize_associated_type(tcx, &fields);
            op(0, &fields[..])
        }

        ty::TyTuple(ref v) => {
            let fields: Vec<_> = v.iter().enumerate().map(|(i, &f)| {
                ty::field {
                    name: token::intern(&i.to_string()),
                    mt: ty::mt {
                        ty: f,
                        mutbl: ast::MutImmutable
                    }
                }
            }).collect();
            op(0, &fields)
        }

        ty::TyEnum(_, substs) => {
            // We want the *variant* ID here, not the enum ID.
            match node_id_opt {
                None => {
                    tcx.sess.bug(&format!(
                        "cannot get field types from the enum type {:?} \
                         without a node ID",
                        ty));
                }
                Some(node_id) => {
                    let def = tcx.def_map.borrow().get(&node_id).unwrap().full_def();
                    match def {
                        def::DefVariant(enum_id, variant_id, _) => {
                            let variant_info = tcx.enum_variant_with_id(enum_id, variant_id);
                            let fields = tcx.struct_fields(variant_id, substs);
                            let fields = monomorphize::normalize_associated_type(tcx, &fields);
                            op(variant_info.disr_val, &fields[..])
                        }
                        _ => {
                            tcx.sess.bug("resolve didn't map this expr to a \
                                          variant ID")
                        }
                    }
                }
            }
        }

        _ => {
            tcx.sess.bug(&format!(
                "cannot get field types from the type {:?}",
                ty));
        }
    }
}
/// Helper for enumerating the field types of structs, enums, or records. The optional node ID here
/// is the node ID of the path identifying the enum variant in use. If none, this cannot possibly
/// an enum variant (so, if it is and `node_id_opt` is none, this function panics).
Helper for enumerating the field types of structs, enums, or records. The optional node ID here
is the node ID of the path identifying the enum variant in use. If none, this cannot possibly
an enum variant (so, if it is and `node_id_opt` is none, this function panics).
Helper for enumerating the field types of structs enums or records . The optional node ID here is the node ID of the path identifying the enum variant in use . If none this cannot possibly an enum variant ( so if it is and ` node_id_opt ` is none this function panics ) .
pub fn with_field_tys<'tcx, R, F>(tcx: &ty::ctxt<'tcx>,
                                  ty: Ty<'tcx>,
                                  node_id_opt: Option<ast::NodeId>,
                                  op: F)
                                  -> R where
    F: FnOnce(ty::Disr, &[ty::field<'tcx>]) -> R,
{
    match ty.sty {
        ty::TyStruct(did, substs) => {
            let fields = tcx.struct_fields(did, substs);
            let fields = monomorphize::normalize_associated_type(tcx, &fields);
            op(0, &fields[..])
        }
        ty::TyTuple(ref v) => {
            let fields: Vec<_> = v.iter().enumerate().map(|(i, &f)| {
                ty::field {
                    name: token::intern(&i.to_string()),
                    mt: ty::mt {
                        ty: f,
                        mutbl: ast::MutImmutable
                    }
                }
            }).collect();
            op(0, &fields)
        }
        ty::TyEnum(_, substs) => {
            // We want the *variant* ID here, not the enum ID.
            match node_id_opt {
                None => {
                    tcx.sess.bug(&format!(
                        "cannot get field types from the enum type {:?} \
                         without a node ID",
                        ty));
                }
                Some(node_id) => {
                    let def = tcx.def_map.borrow().get(&node_id).unwrap().full_def();
                    match def {
                        def::DefVariant(enum_id, variant_id, _) => {
                            let variant_info = tcx.enum_variant_with_id(enum_id, variant_id);
                            let fields = tcx.struct_fields(variant_id, substs);
                            let fields = monomorphize::normalize_associated_type(tcx, &fields);
                            op(variant_info.disr_val, &fields[..])
                        }
                        _ => {
                            tcx.sess.bug("resolve didn't map this expr to a \
                                          variant ID")
                        }
                    }
                }
            }
        }
        _ => {
            tcx.sess.bug(&format!(
                "cannot get field types from the type {:?}",
                ty));
        }
    }
}
pub fn with_field_tys < ' tcx , R , F > ( tcx : & ty :: ctxt < ' tcx > , ty : Ty < ' tcx > , node_id_opt : Option < ast :: NodeId > , op : F ) -> R where F : FnOnce ( ty :: Disr , & [ ty :: field < ' tcx > ] ) -> R , { match ty . sty { ty :: TyStruct ( did , substs ) => { let fields = tcx . struct_fields ( did , substs ) ; let fields = monomorphize :: normalize_associated_type ( tcx , & fields ) ; op ( 0 , & fields [ .. ] ) } ty :: TyTuple ( ref v ) => { let fields : Vec < _ > = v . iter ( ) . enumerate ( ) . map ( | ( i , & f ) | { ty :: field { name : token :: intern ( & i . to_string ( ) ) , mt : ty :: mt { ty : f , mutbl : ast :: MutImmutable } } } ) . collect ( ) ; op ( 0 , & fields ) } ty :: TyEnum ( _ , substs ) => { // We want the *variant* ID here, not the enum ID. match node_id_opt { None => { tcx . sess . bug ( & format ! ( " \
 " ty ) ) ; } Some ( node_id ) => { let def = tcx . def_map . borrow ( ) . get ( & node_id ) . unwrap ( ) . full_def ( ) ; match def { def :: DefVariant ( enum_id , variant_id , _ ) => { let variant_info = tcx . enum_variant_with_id ( enum_id , variant_id ) ; let fields = tcx . struct_fields ( variant_id , substs ) ; let fields = monomorphize :: normalize_associated_type ( tcx , & fields ) ; op ( variant_info . disr_val , & fields [ .. ] ) } _ => { tcx . sess . bug ( " \
 " ) } } } } } _ => { tcx . sess . bug ( & format ! ( " " ty ) ) ; } } }
Helper for enumerating the field types of structs, enums, or records.
Helper for enumerating the field types of structs enums or records .
tcx
&ty::ctxt<'tcx>
ty
Ty<'tcx>
node_id_opt
Option<ast::NodeId>
op
F
tcx
&ty::ctxt<'tcx>
ty
Ty<'tcx>
node_id_opt
Option<ast::NodeId>
op
F