@@ -58,13 +58,19 @@ pub fn bytes_in_context<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, bytes: &[u8]) ->
5858 // or is it using a more efficient representation?
5959 match bytes. len ( ) % 8 {
6060 0 => {
61+ debug_assert_eq ! (
62+ bytes. len( ) % 8 ,
63+ 0 ,
64+ "bytes length is not a multiple of 8, so bytes.as_chunks will have a remainder"
65+ ) ;
6166 let context = & cx. context ;
6267 let byte_type = context. new_type :: < u64 > ( ) ;
6368 let typ = new_array_type ( context, None , byte_type, bytes. len ( ) as u64 / 8 ) ;
6469 let elements: Vec < _ > = bytes
65- . chunks_exact ( 8 )
66- . map ( |arr| {
67- let arr: [ u8 ; 8 ] = arr. try_into ( ) . unwrap ( ) ;
70+ . as_chunks :: < 8 > ( )
71+ . 0
72+ . iter ( )
73+ . map ( |& arr| {
6874 context. new_rvalue_from_long (
6975 byte_type,
7076 // Since we are representing arbitrary byte runs as integers, we need to follow the target
@@ -79,13 +85,19 @@ pub fn bytes_in_context<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, bytes: &[u8]) ->
7985 context. new_array_constructor ( None , typ, & elements)
8086 }
8187 4 => {
88+ debug_assert_eq ! (
89+ bytes. len( ) % 4 ,
90+ 0 ,
91+ "bytes length is not a multiple of 4, so bytes.as_chunks will have a remainder"
92+ ) ;
8293 let context = & cx. context ;
8394 let byte_type = context. new_type :: < u32 > ( ) ;
8495 let typ = new_array_type ( context, None , byte_type, bytes. len ( ) as u64 / 4 ) ;
8596 let elements: Vec < _ > = bytes
86- . chunks_exact ( 4 )
87- . map ( |arr| {
88- let arr: [ u8 ; 4 ] = arr. try_into ( ) . unwrap ( ) ;
97+ . as_chunks :: < 4 > ( )
98+ . 0
99+ . iter ( )
100+ . map ( |& arr| {
89101 context. new_rvalue_from_int (
90102 byte_type,
91103 match cx. sess ( ) . target . options . endian {
0 commit comments