This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed
compiler/rustc_transmute/src/layout Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -404,7 +404,7 @@ pub(crate) mod rustc {
404404 . unwrap ( ) ;
405405 trace ! ( ?discr_layout, "computed discriminant layout" ) ;
406406 variant_layout = variant_layout. extend ( discr_layout) . unwrap ( ) . 0 ;
407- tree = tree. then ( Self :: from_disr ( discr, tcx, layout_summary. discriminant_size ) ) ;
407+ tree = tree. then ( Self :: from_discr ( discr, tcx, layout_summary. discriminant_size ) ) ;
408408 }
409409
410410 // Next come fields.
@@ -444,11 +444,21 @@ pub(crate) mod rustc {
444444 Ok ( tree)
445445 }
446446
447- pub fn from_disr ( discr : Discr < ' tcx > , tcx : TyCtxt < ' tcx > , size : usize ) -> Self {
448- // FIXME(@jswrenn): I'm certain this is missing needed endian nuance.
449- let bytes = discr. val . to_ne_bytes ( ) ;
450- let bytes = & bytes[ ..size] ;
451- Self :: Seq ( bytes. into_iter ( ) . copied ( ) . map ( |b| Self :: from_bits ( b) ) . collect ( ) )
447+ pub fn from_discr ( discr : Discr < ' tcx > , tcx : TyCtxt < ' tcx > , size : usize ) -> Self {
448+ use rustc_target:: abi:: Endian ;
449+
450+ let bytes: [ u8 ; 16 ] ;
451+ let bytes = match tcx. data_layout . endian {
452+ Endian :: Little => {
453+ bytes = discr. val . to_le_bytes ( ) ;
454+ & bytes[ ..size]
455+ }
456+ Endian :: Big => {
457+ bytes = discr. val . to_be_bytes ( ) ;
458+ & bytes[ bytes. len ( ) - size..]
459+ }
460+ } ;
461+ Self :: Seq ( bytes. iter ( ) . map ( |& b| Self :: from_bits ( b) ) . collect ( ) )
452462 }
453463 }
454464
You can’t perform that action at this time.
0 commit comments