@@ -21,6 +21,8 @@ extern crate quickcheck;
21
21
/// You can use `array_ref` to generate an array reference to a subset
22
22
/// of a sliceable bit of data (which could be an array, or a slice,
23
23
/// or a Vec).
24
+ ///
25
+ /// **Panics** if the slice is out of bounds.
24
26
#[ macro_export]
25
27
macro_rules! array_ref {
26
28
( $arr: expr, $offset: expr, $len: expr) => { {
@@ -29,7 +31,8 @@ macro_rules! array_ref {
29
31
unsafe fn as_array<T >( slice: & [ T ] ) -> & [ T ; $len] {
30
32
& * ( slice. as_ptr( ) as * const [ _; $len] )
31
33
}
32
- let slice = & $arr[ $offset..$offset+$len] ;
34
+ let offset = $offset;
35
+ let slice = & $arr[ offset..offset + $len] ;
33
36
unsafe {
34
37
as_array( slice)
35
38
}
@@ -47,7 +50,7 @@ macro_rules! array_refs {
47
50
#[ inline]
48
51
#[ allow( unused_assignments) ]
49
52
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( ) ;
51
54
( $( {
52
55
let aref = & * ( p as * const [ T ; $len] ) ;
53
56
p = p. offset( $len) ;
@@ -73,8 +76,8 @@ macro_rules! mut_array_refs {
73
76
{
74
77
#[ inline]
75
78
#[ 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 ( ) ;
78
81
( $( {
79
82
let aref = & mut * ( p as * mut [ T ; $len] ) ;
80
83
p = p. offset( $len) ;
@@ -92,15 +95,18 @@ macro_rules! mut_array_refs {
92
95
/// You can use `array_mut_ref` to generate a mutable array reference
93
96
/// to a subset of a sliceable bit of data (which could be an array,
94
97
/// or a slice, or a Vec).
98
+ ///
99
+ /// **Panics** if the slice is out of bounds.
95
100
#[ macro_export]
96
101
macro_rules! array_mut_ref {
97
102
( $arr: expr, $offset: expr, $len: expr) => { {
98
103
{
99
104
#[ 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] {
101
106
& mut * ( slice. as_mut_ptr( ) as * mut [ _; $len] )
102
107
}
103
- let slice = & mut $arr[ $offset..$offset+$len] ;
108
+ let offset = $offset;
109
+ let slice = & mut $arr[ offset..offset + $len] ;
104
110
unsafe {
105
111
as_array( slice)
106
112
}
0 commit comments