@@ -62,16 +62,14 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
6262
6363pub ( crate ) fn codegen_get_discriminant < ' tcx > (
6464 fx : & mut FunctionCx < ' _ , ' _ , ' tcx > ,
65+ dest : CPlace < ' tcx > ,
6566 value : CValue < ' tcx > ,
6667 dest_layout : TyAndLayout < ' tcx > ,
67- ) -> CValue < ' tcx > {
68+ ) {
6869 let layout = value. layout ( ) ;
6970
70- if layout. abi == Abi :: Uninhabited {
71- let true_ = fx. bcx . ins ( ) . iconst ( types:: I32 , 1 ) ;
72- fx. bcx . ins ( ) . trapnz ( true_, TrapCode :: UnreachableCodeReached ) ;
73- // Return a dummy value
74- return CValue :: by_ref ( Pointer :: const_addr ( fx, 0 ) , dest_layout) ;
71+ if layout. abi . is_uninhabited ( ) {
72+ return ;
7573 }
7674
7775 let ( tag_scalar, tag_field, tag_encoding) = match & layout. variants {
@@ -89,7 +87,9 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
8987 } else {
9088 ty:: ScalarInt :: try_from_uint ( discr_val, dest_layout. size ) . unwrap ( )
9189 } ;
92- return CValue :: const_val ( fx, dest_layout, discr_val) ;
90+ let res = CValue :: const_val ( fx, dest_layout, discr_val) ;
91+ dest. write_cvalue ( fx, res) ;
92+ return ;
9393 }
9494 Variants :: Multiple { tag, tag_field, tag_encoding, variants : _ } => {
9595 ( tag, * tag_field, tag_encoding)
@@ -110,7 +110,8 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
110110 _ => false ,
111111 } ;
112112 let val = clif_intcast ( fx, tag, cast_to, signed) ;
113- CValue :: by_val ( val, dest_layout)
113+ let res = CValue :: by_val ( val, dest_layout) ;
114+ dest. write_cvalue ( fx, res) ;
114115 }
115116 TagEncoding :: Niche { dataful_variant, ref niche_variants, niche_start } => {
116117 // Rebase from niche values to discriminants, and check
@@ -170,7 +171,8 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
170171
171172 let dataful_variant = fx. bcx . ins ( ) . iconst ( cast_to, i64:: from ( dataful_variant. as_u32 ( ) ) ) ;
172173 let discr = fx. bcx . ins ( ) . select ( is_niche, niche_discr, dataful_variant) ;
173- CValue :: by_val ( discr, dest_layout)
174+ let res = CValue :: by_val ( discr, dest_layout) ;
175+ dest. write_cvalue ( fx, res) ;
174176 }
175177 }
176178}
0 commit comments