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 ! (
87
+ is_aligned( self . ptr. as_ptr( ) ) ,
88
+ "The pointer must be aligned."
89
+ ) ;
86
90
ArrayView :: new ( self . ptr , self . dim , self . strides )
87
91
}
88
92
@@ -130,12 +134,6 @@ where
130
134
"size mismatch in raw view cast"
131
135
) ;
132
136
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
137
unsafe { RawArrayView :: new ( ptr, self . dim , self . strides ) }
140
138
}
141
139
}
@@ -167,8 +165,8 @@ where
167
165
///
168
166
/// Unsafe because caller is responsible for ensuring all of the following:
169
167
///
170
- /// * `ptr` must be non-null and aligned , and it must be safe to
171
- /// [`.offset()`] `ptr` by zero.
168
+ /// * `ptr` must be non-null, and it must be safe to [`.offset()`] `ptr` by
169
+ /// zero.
172
170
///
173
171
/// * It must be safe to [`.offset()`] the pointer repeatedly along all
174
172
/// axes and calculate the `count`s for the `.offset()` calls without
@@ -204,7 +202,6 @@ where
204
202
let strides = shape. strides ;
205
203
if cfg ! ( debug_assertions) {
206
204
assert ! ( !ptr. is_null( ) , "The pointer must be non-null." ) ;
207
- assert ! ( is_aligned( ptr) , "The pointer must be aligned." ) ;
208
205
dimension:: max_abs_offset_check_overflow :: < A , _ > ( & dim, & strides) . unwrap ( ) ;
209
206
}
210
207
RawArrayViewMut :: new_ ( ptr, dim, strides)
@@ -220,19 +217,29 @@ where
220
217
///
221
218
/// **Warning** from a safety standpoint, this is equivalent to
222
219
/// 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.
220
+ /// ensure that all of the data is valid, ensure that the pointer is
221
+ /// aligned, and choose the correct lifetime.
224
222
#[ inline]
225
223
pub unsafe fn deref_into_view < ' a > ( self ) -> ArrayView < ' a , A , D > {
224
+ debug_assert ! (
225
+ is_aligned( self . ptr. as_ptr( ) ) ,
226
+ "The pointer must be aligned."
227
+ ) ;
226
228
ArrayView :: new ( self . ptr , self . dim , self . strides )
227
229
}
228
230
229
231
/// Converts to a mutable view of the array.
230
232
///
231
233
/// **Warning** from a safety standpoint, this is equivalent to
232
234
/// 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.
235
+ /// ensure that all of the data is valid, ensure that the pointer is
236
+ /// aligned, and choose the correct lifetime.
234
237
#[ inline]
235
238
pub unsafe fn deref_into_view_mut < ' a > ( self ) -> ArrayViewMut < ' a , A , D > {
239
+ debug_assert ! (
240
+ is_aligned( self . ptr. as_ptr( ) ) ,
241
+ "The pointer must be aligned."
242
+ ) ;
236
243
ArrayViewMut :: new ( self . ptr , self . dim , self . strides )
237
244
}
238
245
@@ -267,12 +274,6 @@ where
267
274
"size mismatch in raw view cast"
268
275
) ;
269
276
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
277
unsafe { RawArrayViewMut :: new ( ptr, self . dim , self . strides ) }
277
278
}
278
279
}
0 commit comments