Skip to content

Commit 5711b94

Browse files
committed
Merge pull request #4 from bluss/picks
Minor fixes
2 parents dab508a + 18ae4b2 commit 5711b94

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/lib.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ extern crate quickcheck;
2121
/// You can use `array_ref` to generate an array reference to a subset
2222
/// of a sliceable bit of data (which could be an array, or a slice,
2323
/// or a Vec).
24+
///
25+
/// **Panics** if the slice is out of bounds.
2426
#[macro_export]
2527
macro_rules! array_ref {
2628
($arr:expr, $offset:expr, $len:expr) => {{
@@ -29,7 +31,8 @@ macro_rules! array_ref {
2931
unsafe fn as_array<T>(slice: &[T]) -> &[T; $len] {
3032
&*(slice.as_ptr() as *const [_; $len])
3133
}
32-
let slice = & $arr[$offset..$offset+$len];
34+
let offset = $offset;
35+
let slice = & $arr[offset..offset + $len];
3336
unsafe {
3437
as_array(slice)
3538
}
@@ -47,7 +50,7 @@ macro_rules! array_refs {
4750
#[inline]
4851
#[allow(unused_assignments)]
4952
unsafe fn as_arrays<T>(a: &[T; $( $len + )* 0 ]) -> ( $( &[T; $len], )* ) {
50-
let mut p = a.as_ptr() as *const T;
53+
let mut p = a.as_ptr();
5154
( $( {
5255
let aref = &*(p as *const [T; $len]);
5356
p = p.offset($len);
@@ -73,8 +76,8 @@ macro_rules! mut_array_refs {
7376
{
7477
#[inline]
7578
#[allow(unused_assignments)]
76-
unsafe fn as_arrays<T>(a: &mut[T; $( $len + )* 0 ]) -> ( $( &mut[T; $len], )* ) {
77-
let mut p = a.as_ptr() as *mut T;
79+
unsafe fn as_arrays<T>(a: &mut [T; $( $len + )* 0 ]) -> ( $( &mut [T; $len], )* ) {
80+
let mut p = a.as_mut_ptr();
7881
( $( {
7982
let aref = &mut *(p as *mut [T; $len]);
8083
p = p.offset($len);
@@ -92,15 +95,18 @@ macro_rules! mut_array_refs {
9295
/// You can use `array_mut_ref` to generate a mutable array reference
9396
/// to a subset of a sliceable bit of data (which could be an array,
9497
/// or a slice, or a Vec).
98+
///
99+
/// **Panics** if the slice is out of bounds.
95100
#[macro_export]
96101
macro_rules! array_mut_ref {
97102
($arr:expr, $offset:expr, $len:expr) => {{
98103
{
99104
#[inline]
100-
unsafe fn as_array<T>(slice: &mut[T]) -> &mut[T; $len] {
105+
unsafe fn as_array<T>(slice: &mut [T]) -> &mut [T; $len] {
101106
&mut *(slice.as_mut_ptr() as *mut [_; $len])
102107
}
103-
let slice = &mut $arr[$offset..$offset+$len];
108+
let offset = $offset;
109+
let slice = &mut $arr[offset..offset + $len];
104110
unsafe {
105111
as_array(slice)
106112
}

0 commit comments

Comments
 (0)