Skip to content

Commit

Permalink
warnings cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Lokathor committed Mar 19, 2024
1 parent 549e114 commit a79d8e4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/arrayvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ where
}

impl<A: Array> Default for ArrayVec<A> {
#[inline]
fn default() -> Self {
Self { len: 0, data: A::default() }
}
Expand Down Expand Up @@ -1219,6 +1220,7 @@ where
impl<'p, A: Array, I: Iterator<Item = A::Item>> Drop
for ArrayVecSplice<'p, A, I>
{
#[inline]
fn drop(&mut self) {
for _ in self.by_ref() {}

Expand Down Expand Up @@ -1295,6 +1297,7 @@ impl<A: Array> From<A> for ArrayVec<A> {
pub struct TryFromSliceError(());

impl core::fmt::Display for TryFromSliceError {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.write_str("could not convert slice to ArrayVec")
}
Expand All @@ -1311,7 +1314,6 @@ where
type Error = TryFromSliceError;

#[inline]
#[must_use]
/// The output has a length equal to that of the slice, with the same capacity
/// as `A`.
fn try_from(slice: &[T]) -> Result<Self, Self::Error> {
Expand Down
7 changes: 7 additions & 0 deletions src/arrayvec_drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,36 @@ impl<'a, T: 'a + Default> ArrayVecDrain<'a, T> {
}

impl<'a, T: 'a + Default> DoubleEndedIterator for ArrayVecDrain<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> {
self.iter.next_back().map(core::mem::take)
}

#[inline]
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
self.iter.nth_back(n).map(core::mem::take)
}
}

impl<'a, T: 'a + Default> Iterator for ArrayVecDrain<'a, T> {
type Item = T;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(core::mem::take)
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
#[inline]
fn nth(&mut self, n: usize) -> Option<Self::Item> {
self.iter.nth(n).map(core::mem::take)
}
#[inline]
fn last(self) -> Option<Self::Item> {
self.iter.last().map(core::mem::take)
}
#[inline]
fn for_each<F>(self, f: F)
where
F: FnMut(Self::Item),
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#![warn(clippy::missing_inline_in_public_items)]
#![warn(clippy::must_use_candidate)]
#![warn(missing_docs)]
#![allow(clippy::borrow_deref_ref)]
#![allow(unused_imports)]
#![allow(clippy::write_with_newline)]
#![allow(clippy::needless_return)]

//! `tinyvec` provides 100% safe vec-like data structures.
//!
Expand Down
4 changes: 3 additions & 1 deletion src/slicevec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ impl<'s, T> SliceVec<'s, T> {
#[inline]
pub fn split_off<'a>(&'a mut self, at: usize) -> SliceVec<'s, T> {
let mut new = Self::default();
let backing: &'s mut [T] = replace(&mut self.data, &mut []);
let backing: &'s mut [T] = core::mem::take(&mut self.data);
let (me, other) = backing.split_at_mut(at);
new.len = self.len - at;
new.data = other;
Expand Down Expand Up @@ -686,6 +686,7 @@ impl<'s, T> From<&'s mut [T]> for SliceVec<'s, T> {
/// let mut arr = [0_i32; 2];
/// let mut sv = SliceVec::from(&mut arr[..]);
/// ```
#[inline]
fn from(data: &'s mut [T]) -> Self {
let len = data.len();
Self { data, len }
Expand All @@ -703,6 +704,7 @@ where
/// let mut arr = [0, 0];
/// let mut sv = SliceVec::from(&mut arr);
/// ```
#[inline]
fn from(a: &'s mut A) -> Self {
let data = a.as_mut();
let len = data.len();
Expand Down
7 changes: 4 additions & 3 deletions tests/arrayvec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(bad_style)]
#![allow(clippy::clone_on_copy)]

#[cfg(feature = "serde")]
use serde_test::{assert_tokens, Token};
Expand Down Expand Up @@ -383,7 +384,7 @@ fn iter_last_nth() {
av.push(2);
av.push(3);

assert_eq!(av.into_iter().nth(0), Some(1));
assert_eq!(av.into_iter().next(), Some(1));
}

#[test]
Expand Down Expand Up @@ -460,9 +461,9 @@ fn ArrayVec_try_from_slice() {
assert!(fits.is_ok());
assert_eq!(fits.unwrap().as_slice(), &[1, 2]);

let doesnt_fit: Result<ArrayVec<[i32; 2]>, _> =
let does_not_fit: Result<ArrayVec<[i32; 2]>, _> =
ArrayVec::try_from(&nums[..4]);
assert!(doesnt_fit.is_err());
assert!(does_not_fit.is_err());
}

#[test]
Expand Down

0 comments on commit a79d8e4

Please sign in to comment.