Skip to content

Commit 41f8ace

Browse files
authored
Merge pull request #762 from jturner314/fix-clippy-warnings
Fix clippy (beta version) warnings
2 parents 7f67fdf + c1032fc commit 41f8ace

File tree

6 files changed

+61
-21
lines changed

6 files changed

+61
-21
lines changed

src/impl_constructors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ where
425425
/// Creates an array from a vector and interpret it according to the
426426
/// provided shape and strides. (No cloning of elements needed.)
427427
///
428+
/// # Safety
429+
///
428430
/// The caller must ensure that the following conditions are met:
429431
///
430432
/// 1. The ndim of `dim` and `strides` must be the same.

src/impl_methods.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,10 @@ where
572572
/// Return a reference to the element at `index`.
573573
///
574574
/// **Note:** only unchecked for non-debug builds of ndarray.
575+
///
576+
/// # Safety
577+
///
578+
/// The caller must ensure that the index is in-bounds.
575579
#[inline]
576580
pub unsafe fn uget<I>(&self, index: I) -> &A
577581
where
@@ -587,8 +591,16 @@ where
587591
///
588592
/// Return a mutable reference to the element at `index`.
589593
///
590-
/// **Note:** Only unchecked for non-debug builds of ndarray.<br>
591-
/// **Note:** (For `ArcArray`) The array must be uniquely held when mutating it.
594+
/// **Note:** Only unchecked for non-debug builds of ndarray.
595+
///
596+
/// # Safety
597+
///
598+
/// The caller must ensure that:
599+
///
600+
/// 1. the index is in-bounds and
601+
///
602+
/// 2. the data is uniquely held by the array. (This property is guaranteed
603+
/// for `Array` and `ArrayViewMut`, but not for `ArcArray` or `CowArray`.)
592604
#[inline]
593605
pub unsafe fn uget_mut<I>(&mut self, index: I) -> &mut A
594606
where
@@ -622,8 +634,16 @@ where
622634
///
623635
/// Indices may be equal.
624636
///
625-
/// **Note:** only unchecked for non-debug builds of ndarray.<br>
626-
/// **Note:** (For `ArcArray`) The array must be uniquely held.
637+
/// **Note:** only unchecked for non-debug builds of ndarray.
638+
///
639+
/// # Safety
640+
///
641+
/// The caller must ensure that:
642+
///
643+
/// 1. both `index1 and `index2` are in-bounds and
644+
///
645+
/// 2. the data is uniquely held by the array. (This property is guaranteed
646+
/// for `Array` and `ArrayViewMut`, but not for `ArcArray` or `CowArray`.)
627647
pub unsafe fn uswap<I>(&mut self, index1: I, index2: I)
628648
where
629649
S: DataMut,

src/impl_raw_views.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ where
3131
/// Create an `RawArrayView<A, D>` from shape information and a raw pointer
3232
/// to the elements.
3333
///
34-
/// Unsafe because caller is responsible for ensuring all of the following:
34+
/// # Safety
35+
///
36+
/// The caller is responsible for ensuring all of the following:
3537
///
3638
/// * `ptr` must be non-null, and it must be safe to [`.offset()`] `ptr` by
3739
/// zero.
@@ -77,10 +79,12 @@ where
7779

7880
/// Converts to a read-only view of the array.
7981
///
80-
/// **Warning** from a safety standpoint, this is equivalent to
81-
/// dereferencing a raw pointer for every element in the array. You must
82-
/// ensure that all of the data is valid, ensure that the pointer is
83-
/// aligned, and choose the correct lifetime.
82+
/// # Safety
83+
///
84+
/// From a safety standpoint, this is equivalent to dereferencing a raw
85+
/// pointer for every element in the array. You must ensure that all of the
86+
/// data is valid, ensure that the pointer is aligned, and choose the
87+
/// correct lifetime.
8488
#[inline]
8589
pub unsafe fn deref_into_view<'a>(self) -> ArrayView<'a, A, D> {
8690
debug_assert!(
@@ -163,7 +167,9 @@ where
163167
/// Create an `RawArrayViewMut<A, D>` from shape information and a raw
164168
/// pointer to the elements.
165169
///
166-
/// Unsafe because caller is responsible for ensuring all of the following:
170+
/// # Safety
171+
///
172+
/// The caller is responsible for ensuring all of the following:
167173
///
168174
/// * `ptr` must be non-null, and it must be safe to [`.offset()`] `ptr` by
169175
/// zero.
@@ -215,10 +221,12 @@ where
215221

216222
/// Converts to a read-only view of the array.
217223
///
218-
/// **Warning** from a safety standpoint, this is equivalent to
219-
/// dereferencing a raw pointer for every element in the array. You must
220-
/// ensure that all of the data is valid, ensure that the pointer is
221-
/// aligned, and choose the correct lifetime.
224+
/// # Safety
225+
///
226+
/// From a safety standpoint, this is equivalent to dereferencing a raw
227+
/// pointer for every element in the array. You must ensure that all of the
228+
/// data is valid, ensure that the pointer is aligned, and choose the
229+
/// correct lifetime.
222230
#[inline]
223231
pub unsafe fn deref_into_view<'a>(self) -> ArrayView<'a, A, D> {
224232
debug_assert!(
@@ -230,10 +238,12 @@ where
230238

231239
/// Converts to a mutable view of the array.
232240
///
233-
/// **Warning** from a safety standpoint, this is equivalent to
234-
/// dereferencing a raw pointer for every element in the array. You must
235-
/// ensure that all of the data is valid, ensure that the pointer is
236-
/// aligned, and choose the correct lifetime.
241+
/// # Safety
242+
///
243+
/// From a safety standpoint, this is equivalent to dereferencing a raw
244+
/// pointer for every element in the array. You must ensure that all of the
245+
/// data is valid, ensure that the pointer is aligned, and choose the
246+
/// correct lifetime.
237247
#[inline]
238248
pub unsafe fn deref_into_view_mut<'a>(self) -> ArrayViewMut<'a, A, D> {
239249
debug_assert!(

src/impl_views/constructors.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ where
6565
/// Create an `ArrayView<A, D>` from shape information and a raw pointer to
6666
/// the elements.
6767
///
68-
/// Unsafe because caller is responsible for ensuring all of the following:
68+
/// # Safety
69+
///
70+
/// The caller is responsible for ensuring all of the following:
6971
///
7072
/// * The elements seen by moving `ptr` according to the shape and strides
7173
/// must live at least as long as `'a` and must not be not mutably
@@ -159,7 +161,9 @@ where
159161
/// Create an `ArrayViewMut<A, D>` from shape information and a
160162
/// raw pointer to the elements.
161163
///
162-
/// Unsafe because caller is responsible for ensuring all of the following:
164+
/// # Safety
165+
///
166+
/// The caller is responsible for ensuring all of the following:
163167
///
164168
/// * The elements seen by moving `ptr` according to the shape and strides
165169
/// must live at least as long as `'a` and must not be aliased for the

src/impl_views/indexing.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ pub trait IndexLonger<I> {
9090
/// [1]: struct.ArrayBase.html#method.uget
9191
///
9292
/// **Note:** only unchecked for non-debug builds of ndarray.
93+
///
94+
/// # Safety
95+
///
96+
/// The caller must ensure that the index is in-bounds.
9397
unsafe fn uget(self, index: I) -> Self::Output;
9498
}
9599

src/iterators/windows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'a, A, D: Dimension> Windows<'a, A, D> {
4141

4242
unsafe {
4343
Windows {
44-
base: ArrayView::from_shape_ptr(size.clone().strides(a.strides), a.ptr.as_ptr()),
44+
base: ArrayView::from_shape_ptr(size.strides(a.strides), a.ptr.as_ptr()),
4545
window,
4646
strides: window_strides,
4747
}

0 commit comments

Comments
 (0)