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