33
33
///
34
34
/// Unsafe because caller is responsible for ensuring all of the following:
35
35
///
36
- /// * `ptr` must be non-null and aligned , and it must be safe to
37
- /// [`.offset()`] `ptr` by zero.
36
+ /// * `ptr` must be non-null, and it must be safe to [`.offset()`] `ptr` by
37
+ /// zero.
38
38
///
39
39
/// * It must be safe to [`.offset()`] the pointer repeatedly along all
40
40
/// axes and calculate the `count`s for the `.offset()` calls without
70
70
let strides = shape. strides ;
71
71
if cfg ! ( debug_assertions) {
72
72
assert ! ( !ptr. is_null( ) , "The pointer must be non-null." ) ;
73
- assert ! ( is_aligned( ptr) , "The pointer must be aligned." ) ;
74
73
dimension:: max_abs_offset_check_overflow :: < A , _ > ( & dim, & strides) . unwrap ( ) ;
75
74
}
76
75
RawArrayView :: new_ ( ptr, dim, strides)
80
79
///
81
80
/// **Warning** from a safety standpoint, this is equivalent to
82
81
/// dereferencing a raw pointer for every element in the array. You must
83
- /// ensure that all of the data is valid and choose the correct lifetime.
82
+ /// ensure that all of the data is valid, ensure that the pointer is
83
+ /// aligned, and choose the correct lifetime.
84
84
#[ inline]
85
85
pub unsafe fn deref_into_view < ' a > ( self ) -> ArrayView < ' a , A , D > {
86
+ debug_assert ! ( is_aligned( self . ptr. as_ptr( ) ) , "The pointer must be aligned." ) ;
86
87
ArrayView :: new ( self . ptr , self . dim , self . strides )
87
88
}
88
89
@@ -130,12 +131,6 @@ where
130
131
"size mismatch in raw view cast"
131
132
) ;
132
133
let ptr = self . ptr . cast :: < B > ( ) ;
133
- debug_assert ! (
134
- is_aligned( ptr. as_ptr( ) ) ,
135
- "alignment mismatch in raw view cast"
136
- ) ;
137
- /* Alignment checked with debug assertion: alignment could be dynamically correct,
138
- * and we don't have a check that compiles out for that. */
139
134
unsafe { RawArrayView :: new ( ptr, self . dim , self . strides ) }
140
135
}
141
136
}
@@ -167,8 +162,8 @@ where
167
162
///
168
163
/// Unsafe because caller is responsible for ensuring all of the following:
169
164
///
170
- /// * `ptr` must be non-null and aligned , and it must be safe to
171
- /// [`.offset()`] `ptr` by zero.
165
+ /// * `ptr` must be non-null, and it must be safe to [`.offset()`] `ptr` by
166
+ /// zero.
172
167
///
173
168
/// * It must be safe to [`.offset()`] the pointer repeatedly along all
174
169
/// axes and calculate the `count`s for the `.offset()` calls without
@@ -204,7 +199,6 @@ where
204
199
let strides = shape. strides ;
205
200
if cfg ! ( debug_assertions) {
206
201
assert ! ( !ptr. is_null( ) , "The pointer must be non-null." ) ;
207
- assert ! ( is_aligned( ptr) , "The pointer must be aligned." ) ;
208
202
dimension:: max_abs_offset_check_overflow :: < A , _ > ( & dim, & strides) . unwrap ( ) ;
209
203
}
210
204
RawArrayViewMut :: new_ ( ptr, dim, strides)
@@ -220,19 +214,23 @@ where
220
214
///
221
215
/// **Warning** from a safety standpoint, this is equivalent to
222
216
/// dereferencing a raw pointer for every element in the array. You must
223
- /// ensure that all of the data is valid and choose the correct lifetime.
217
+ /// ensure that all of the data is valid, ensure that the pointer is
218
+ /// aligned, and choose the correct lifetime.
224
219
#[ inline]
225
220
pub unsafe fn deref_into_view < ' a > ( self ) -> ArrayView < ' a , A , D > {
221
+ debug_assert ! ( is_aligned( self . ptr. as_ptr( ) ) , "The pointer must be aligned." ) ;
226
222
ArrayView :: new ( self . ptr , self . dim , self . strides )
227
223
}
228
224
229
225
/// Converts to a mutable view of the array.
230
226
///
231
227
/// **Warning** from a safety standpoint, this is equivalent to
232
228
/// dereferencing a raw pointer for every element in the array. You must
233
- /// ensure that all of the data is valid and choose the correct lifetime.
229
+ /// ensure that all of the data is valid, ensure that the pointer is
230
+ /// aligned, and choose the correct lifetime.
234
231
#[ inline]
235
232
pub unsafe fn deref_into_view_mut < ' a > ( self ) -> ArrayViewMut < ' a , A , D > {
233
+ debug_assert ! ( is_aligned( self . ptr. as_ptr( ) ) , "The pointer must be aligned." ) ;
236
234
ArrayViewMut :: new ( self . ptr , self . dim , self . strides )
237
235
}
238
236
@@ -267,12 +265,6 @@ where
267
265
"size mismatch in raw view cast"
268
266
) ;
269
267
let ptr = self . ptr . cast :: < B > ( ) ;
270
- debug_assert ! (
271
- is_aligned( ptr. as_ptr( ) ) ,
272
- "alignment mismatch in raw view cast"
273
- ) ;
274
- /* Alignment checked with debug assertion: alignment could be dynamically correct,
275
- * and we don't have a check that compiles out for that. */
276
268
unsafe { RawArrayViewMut :: new ( ptr, self . dim , self . strides ) }
277
269
}
278
270
}
0 commit comments