@@ -749,14 +749,15 @@ pub fn trans_const(ccx: &CrateContext, r: &Repr, discr: Disr,
749749 let contents = build_const_struct ( ccx, st, vals) ;
750750 C_struct ( contents, st. packed )
751751 }
752- NullablePointer { nonnull : ref nonnull, nndiscr, ptrfield , .. } => {
752+ NullablePointer { nonnull : ref nonnull, nndiscr, .. } => {
753753 if discr == nndiscr {
754754 C_struct ( build_const_struct ( ccx, nonnull, vals) , false )
755755 } else {
756- let vals = nonnull. fields . iter ( ) . enumerate ( ) . map ( |( i, & ty) | {
757- let llty = type_of:: sizing_type_of ( ccx, ty) ;
758- if i == ptrfield { C_null ( llty) } else { C_undef ( llty) }
759- } ) . collect :: < ~[ ValueRef ] > ( ) ;
756+ let vals = nonnull. fields . map ( |& ty| {
757+ // Always use null even if it's not the `ptrfield`th
758+ // field; see #8506.
759+ C_null ( type_of:: sizing_type_of ( ccx, ty) )
760+ } ) ;
760761 C_struct ( build_const_struct ( ccx, nonnull, vals) , false )
761762 }
762763 }
@@ -791,14 +792,8 @@ fn build_const_struct(ccx: &CrateContext, st: &Struct, vals: &[ValueRef])
791792 cfields. push ( padding ( target_offset - offset) ) ;
792793 offset = target_offset;
793794 }
794- let val = if is_undef ( vals[ i] ) {
795- let wrapped = C_struct ( [ vals[ i] ] , false ) ;
796- assert ! ( !is_undef( wrapped) ) ;
797- wrapped
798- } else {
799- vals[ i]
800- } ;
801- cfields. push ( val) ;
795+ assert ! ( !is_undef( vals[ i] ) ) ;
796+ cfields. push ( vals[ i] ) ;
802797 offset += machine:: llsize_of_alloc ( ccx, llty) as u64
803798 }
804799
0 commit comments