/// Check if this enum can be safely exported based on the
/// "nullable pointer optimization". Currently restricted
/// to function pointers and references, but could be
/// expanded to cover NonZero raw pointers and newtypes.
/// FIXME: This duplicates code in trans.
Check if this enum can be safely exported based on the
"nullable pointer optimization". Currently restricted
to function pointers and references, but could be
expanded to cover NonZero raw pointers and newtypes.
FIXME: This duplicates code in trans.
Check if this enum can be safely exported based on the " nullable pointer optimization " . Currently restricted to function pointers and references but could be expanded to cover NonZero raw pointers and newtypes . FIXME : This duplicates code in trans .
fn is_repr_nullable_ptr<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                                  def: &'tcx ty::AdtDef,
                                  substs: &Substs<'tcx>)
                                  -> bool {
    if def.variants.len() == 2 {
        let data_idx;
        if def.variants[0].fields.is_empty() {
            data_idx = 1;
        } else if def.variants[1].fields.is_empty() {
            data_idx = 0;
        } else {
            return false;
        }
        if def.variants[data_idx].fields.len() == 1 {
            match def.variants[data_idx].fields[0].ty(tcx, substs).sty {
                ty::TyFnPtr(_) => {
                    return true;
                }
                ty::TyRef(..) => {
                    return true;
                }
                _ => {}
            }
        }
    }
    false
}
fn is_repr_nullable_ptr < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def : & ' tcx ty :: AdtDef , substs : & Substs < ' tcx > ) -> bool { if def . variants . len ( ) == 2 { let data_idx ; if def . variants [ 0 ] . fields . is_empty ( ) { data_idx = 1 ; } else if def . variants [ 1 ] . fields . is_empty ( ) { data_idx = 0 ; } else { return false ; } if def . variants [ data_idx ] . fields . len ( ) == 1 { match def . variants [ data_idx ] . fields [ 0 ] . ty ( tcx , substs ) . sty { ty :: TyFnPtr ( _ ) => { return true ; } ty :: TyRef ( .. ) => { return true ; } _ => { } } } } false }
Check if this enum can be safely exported based on the
"nullable pointer optimization".
Check if this enum can be safely exported based on the " nullable pointer optimization " .
tcx
TyCtxt<'a, 'tcx, 'tcx>
def
&'tcx ty::AdtDef
substs
&Substs<'tcx>