Skip to content

Commit 18ae4b2

Browse files
author
root
committed
array_ref: Evaluate the $offset expr only once in the macro.
1 parent 43b1808 commit 18ae4b2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ macro_rules! array_ref {
3131
unsafe fn as_array<T>(slice: &[T]) -> &[T; $len] {
3232
&*(slice.as_ptr() as *const [_; $len])
3333
}
34-
let slice = & $arr[$offset..$offset + $len];
34+
let offset = $offset;
35+
let slice = & $arr[offset..offset + $len];
3536
unsafe {
3637
as_array(slice)
3738
}
@@ -104,7 +105,8 @@ macro_rules! array_mut_ref {
104105
unsafe fn as_array<T>(slice: &mut [T]) -> &mut [T; $len] {
105106
&mut *(slice.as_mut_ptr() as *mut [_; $len])
106107
}
107-
let slice = &mut $arr[$offset..$offset + $len];
108+
let offset = $offset;
109+
let slice = &mut $arr[offset..offset + $len];
108110
unsafe {
109111
as_array(slice)
110112
}

0 commit comments

Comments
 (0)