Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Commit

Permalink
Allow clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann committed Nov 27, 2019
1 parent a3fa917 commit bcc633e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl<T, A: AllocRef> Box<T, A> {
/// # #[allow(unused_variables)]
/// let five = Box::new_in(5, Global);
/// ```
#[allow(clippy::inline_always)]
#[allow(clippy::inline_always, clippy::needless_pass_by_value)]
#[inline(always)]
pub fn new_in(x: T, a: A) -> Self {
unsafe { Self::try_new_in(x, a).unwrap_unchecked() }
Expand All @@ -201,6 +201,7 @@ impl<T, A: AllocRef> Box<T, A> {
/// let five = Box::try_new_in(5, Global)?;
/// # Ok::<_, alloc_wg::alloc::AllocErr>(())
/// ```
#[allow(clippy::needless_pass_by_value)]
pub fn try_new_in(x: T, a: A) -> Result<Self, A::Error> {
let ptr = if let Ok(layout) = NonZeroLayout::new::<T>() {
let ptr = a.alloc(layout)?.cast::<T>();
Expand Down Expand Up @@ -232,7 +233,7 @@ impl<T, A: AllocRef> Box<T, A> {
///
/// assert_eq!(*five, 5)
/// ```
#[allow(clippy::inline_always)]
#[allow(clippy::inline_always, clippy::needless_pass_by_value)]
#[inline(always)]
pub fn new_uninit_in(a: A) -> Box<mem::MaybeUninit<T>, A> {
unsafe { Self::try_new_uninit_in(a).unwrap_unchecked() }
Expand All @@ -257,6 +258,7 @@ impl<T, A: AllocRef> Box<T, A> {
/// assert_eq!(*five, 5);
/// # Ok::<_, alloc_wg::alloc::AllocErr>(())
/// ```
#[allow(clippy::needless_pass_by_value)]
pub fn try_new_uninit_in(a: A) -> Result<Box<mem::MaybeUninit<T>, A>, A::Error> {
let ptr = if let Ok(layout) = NonZeroLayout::new::<T>() {
let ptr: NonNull<mem::MaybeUninit<T>> = a.alloc(layout)?.cast();
Expand All @@ -269,14 +271,15 @@ impl<T, A: AllocRef> Box<T, A> {

/// Constructs a new `Pin<Box<T, A>>` with the specified allocator. If `T` does not implement
/// `Unpin`, then `x` will be pinned in memory and unable to be moved.
#[allow(clippy::inline_always)]
#[allow(clippy::inline_always, clippy::needless_pass_by_value)]
#[inline(always)]
pub fn pin_in(x: T, a: A) -> Pin<Self> {
unsafe { Self::try_pin_in(x, a).unwrap_unchecked() }
}

/// Constructs a new `Pin<Box<T, A>>` with the specified allocator. If `T` does not implement
/// `Unpin`, then `x` will be pinned in memory and unable to be moved.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn try_pin_in(x: T, a: A) -> Result<Pin<Self>, A::Error> {
Self::try_new_in(x, a).map(Pin::from)
Expand Down Expand Up @@ -335,7 +338,7 @@ impl<T, A: AllocRef> Box<[T], A> {
///
/// assert_eq!(*values, [1, 2, 3]);
/// ```
#[allow(clippy::inline_always)]
#[allow(clippy::inline_always, clippy::needless_pass_by_value)]
#[inline(always)]
pub fn new_uninit_slice_in(len: usize, a: A) -> Box<[mem::MaybeUninit<T>], A> {
unsafe { Self::try_new_uninit_slice_in(len, a).unwrap_unchecked() }
Expand Down Expand Up @@ -363,6 +366,7 @@ impl<T, A: AllocRef> Box<[T], A> {
/// assert_eq!(*values, [1, 2, 3]);
/// # Ok::<_, alloc_wg::collections::CollectionAllocErr<Global>>(())
/// ```
#[allow(clippy::needless_pass_by_value)]
pub fn try_new_uninit_slice_in(
len: usize,
a: A,
Expand Down
6 changes: 6 additions & 0 deletions src/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ impl<T> RawVec<T> {

impl<T, A: DeallocRef> RawVec<T, A> {
/// Like `new` but parameterized over the choice of allocator for the returned `RawVec`.
#[allow(clippy::needless_pass_by_value)]
pub fn new_in(a: A) -> Self {
let capacity = if mem::size_of::<T>() == 0 { !0 } else { 0 };
Self {
Expand All @@ -161,6 +162,7 @@ impl<T, A: DeallocRef> RawVec<T, A> {
///
/// * if the requested capacity exceeds `usize::MAX` bytes.
/// * on 32-bit platforms if the requested capacity exceeds `isize::MAX` bytes.
#[allow(clippy::needless_pass_by_value)]
pub fn with_capacity_in(capacity: usize, a: A) -> Self
where
A: AllocRef,
Expand All @@ -181,6 +183,7 @@ impl<T, A: DeallocRef> RawVec<T, A> {
/// * `CapacityOverflow` if the requested capacity exceeds `usize::MAX` bytes.
/// * `CapacityOverflow` on 32-bit platforms if the requested capacity exceeds `isize::MAX` bytes.
/// * `AllocError` on OOM
#[allow(clippy::needless_pass_by_value)]
pub fn try_with_capacity_in(capacity: usize, a: A) -> Result<Self, CollectionAllocErr<A>>
where
A: AllocRef,
Expand All @@ -196,6 +199,7 @@ impl<T, A: DeallocRef> RawVec<T, A> {
///
/// * if the requested capacity exceeds `usize::MAX` bytes.
/// * on 32-bit platforms if the requested capacity exceeds `isize::MAX` bytes.
#[allow(clippy::needless_pass_by_value)]
pub fn with_capacity_zeroed_in(capacity: usize, a: A) -> Self
where
A: AllocRef,
Expand All @@ -216,13 +220,15 @@ impl<T, A: DeallocRef> RawVec<T, A> {
/// * `CapacityOverflow` if the requested capacity exceeds `usize::MAX` bytes.
/// * `CapacityOverflow` on 32-bit platforms if the requested capacity exceeds `isize::MAX` bytes.
/// * `AllocError` on OOM
#[allow(clippy::needless_pass_by_value)]
pub fn try_with_capacity_zeroed_in(capacity: usize, a: A) -> Result<Self, CollectionAllocErr<A>>
where
A: AllocRef,
{
Self::allocate_in(capacity, true, a)
}

#[allow(clippy::needless_pass_by_value)]
fn allocate_in(capacity: usize, zeroed: bool, alloc: A) -> Result<Self, CollectionAllocErr<A>>
where
A: AllocRef,
Expand Down
8 changes: 8 additions & 0 deletions src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ impl String {

impl<A: DeallocRef> String<A> {
/// Like `new` but parameterized over the choice of allocator for the returned `String`.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn new_in(a: A) -> Self {
Self {
Expand All @@ -577,6 +578,7 @@ impl<A: DeallocRef> String<A> {
///
/// # Panics
/// Panics if the allocation fails.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn with_capacity_in(capacity: usize, a: A) -> Self
where
Expand All @@ -588,6 +590,7 @@ impl<A: DeallocRef> String<A> {
}

/// Like `with_capacity_in` but returns errors instead of panicking.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn try_with_capacity_in(capacity: usize, a: A) -> Result<Self, CollectionAllocErr<A>>
where
Expand All @@ -602,6 +605,7 @@ impl<A: DeallocRef> String<A> {
///
/// # Panics
/// Panics if the allocation fails.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn from_str_in(s: &str, a: A) -> Self
where
Expand All @@ -613,6 +617,7 @@ impl<A: DeallocRef> String<A> {
}

/// Like `from_str_in` but returns errors instead of panicking.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn try_from_str_in(s: &str, a: A) -> Result<Self, CollectionAllocErr<A>>
where
Expand Down Expand Up @@ -703,6 +708,7 @@ impl<A: DeallocRef> String<A> {
/// # Panics
///
/// Panics if allocation fails.
#[allow(clippy::needless_pass_by_value)]
pub fn from_utf8_lossy_in(v: &[u8], a: A) -> Self
where
A: ReallocRef,
Expand All @@ -715,6 +721,7 @@ impl<A: DeallocRef> String<A> {
}

/// Like `from_utf8_lossy_in` but returns errors instead of panicking.
#[allow(clippy::needless_pass_by_value)]
pub fn try_from_utf8_lossy_in(v: &[u8], a: A) -> Result<Self, CollectionAllocErr<A>>
where
A: ReallocRef,
Expand Down Expand Up @@ -751,6 +758,7 @@ impl<A: DeallocRef> String<A> {
}

/// Like `from_utf16` but parameterized over the choice of allocator for the returned `String`.
#[allow(clippy::needless_pass_by_value)]
pub fn from_utf16_in(v: &[u16], a: A) -> Result<Self, FromUtf16Error>
where
A: ReallocRef,
Expand Down
3 changes: 3 additions & 0 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ impl<T> Vec<T> {

impl<T, A: DeallocRef> Vec<T, A> {
/// Like `new` but parameterized over the choice of allocator for the returned `Vec`.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn new_in(a: A) -> Self {
Self {
Expand All @@ -487,6 +488,7 @@ impl<T, A: DeallocRef> Vec<T, A> {
///
/// * if the requested capacity exceeds `usize::MAX` bytes.
/// * on 32-bit platforms if the requested capacity exceeds `isize::MAX` bytes.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn with_capacity_in(capacity: usize, a: A) -> Self
where
Expand All @@ -506,6 +508,7 @@ impl<T, A: DeallocRef> Vec<T, A> {
/// * `CapacityOverflow` if the requested capacity exceeds `usize::MAX` bytes.
/// * `CapacityOverflow` on 32-bit platforms if the requested capacity exceeds `isize::MAX` bytes.
/// * `AllocError` on OOM
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn try_with_capacity_in(capacity: usize, a: A) -> Result<Self, CollectionAllocErr<A>>
where
Expand Down

0 comments on commit bcc633e

Please # to comment.