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

Commit b02223d

Browse files
committed
Fix clippy issues
1 parent f5a4274 commit b02223d

File tree

2 files changed

+35
-26
lines changed

2 files changed

+35
-26
lines changed

src/string.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl String {
451451
#[inline]
452452
#[must_use]
453453
pub fn with_capacity(capacity: usize) -> Self {
454-
Self::with_capacity_in(capacity, Global)
454+
Self::with_capacity_in(capacity, &Global)
455455
}
456456

457457
/// Decode a UTF-16 encoded vector `v` into a `String`, returning [`Err`]
@@ -475,7 +475,7 @@ impl String {
475475
/// assert!(String::from_utf16(v).is_err());
476476
/// ```
477477
pub fn from_utf16(v: &[u16]) -> Result<Self, FromUtf16Error> {
478-
Self::from_utf16_in(v, Global)
478+
Self::from_utf16_in(v, &Global)
479479
}
480480

481481
/// Decode a UTF-16 encoded slice `v` into a `String`, replacing
@@ -578,7 +578,7 @@ impl<A: DeallocRef> String<A> {
578578
/// # Panics
579579
/// Panics if the allocation fails.
580580
#[inline]
581-
pub fn with_capacity_in(capacity: usize, a: A) -> Self
581+
pub fn with_capacity_in(capacity: usize, a: &A) -> Self
582582
where
583583
A: AllocRef,
584584
{
@@ -589,12 +589,12 @@ impl<A: DeallocRef> String<A> {
589589

590590
/// Like `with_capacity_in` but returns errors instead of panicking.
591591
#[inline]
592-
pub fn try_with_capacity_in(capacity: usize, a: A) -> Result<Self, CollectionAllocErr<A>>
592+
pub fn try_with_capacity_in(capacity: usize, a: &A) -> Result<Self, CollectionAllocErr<A>>
593593
where
594594
A: AllocRef,
595595
{
596596
Ok(Self {
597-
vec: Vec::try_with_capacity_in(capacity, &a)?,
597+
vec: Vec::try_with_capacity_in(capacity, a)?,
598598
})
599599
}
600600

@@ -603,7 +603,7 @@ impl<A: DeallocRef> String<A> {
603603
/// # Panics
604604
/// Panics if the allocation fails.
605605
#[inline]
606-
pub fn from_str_in(s: &str, a: A) -> Self
606+
pub fn from_str_in(s: &str, a: &A) -> Self
607607
where
608608
A: ReallocRef,
609609
{
@@ -614,7 +614,7 @@ impl<A: DeallocRef> String<A> {
614614

615615
/// Like `from_str_in` but returns errors instead of panicking.
616616
#[inline]
617-
pub fn try_from_str_in(s: &str, a: A) -> Result<Self, CollectionAllocErr<A>>
617+
pub fn try_from_str_in(s: &str, a: &A) -> Result<Self, CollectionAllocErr<A>>
618618
where
619619
A: ReallocRef,
620620
{
@@ -703,7 +703,7 @@ impl<A: DeallocRef> String<A> {
703703
/// # Panics
704704
///
705705
/// Panics if allocation fails.
706-
pub fn from_utf8_lossy_in(v: &[u8], a: A) -> Self
706+
pub fn from_utf8_lossy_in(v: &[u8], a: &A) -> Self
707707
where
708708
A: ReallocRef,
709709
{
@@ -715,7 +715,7 @@ impl<A: DeallocRef> String<A> {
715715
}
716716

717717
/// Like `from_utf8_lossy_in` but returns errors instead of panicking.
718-
pub fn try_from_utf8_lossy_in(v: &[u8], a: A) -> Result<Self, CollectionAllocErr<A>>
718+
pub fn try_from_utf8_lossy_in(v: &[u8], a: &A) -> Result<Self, CollectionAllocErr<A>>
719719
where
720720
A: ReallocRef,
721721
{
@@ -751,7 +751,7 @@ impl<A: DeallocRef> String<A> {
751751
}
752752

753753
/// Like `from_utf16` but parameterized over the choice of allocator for the returned `String`.
754-
pub fn from_utf16_in(v: &[u16], a: A) -> Result<Self, FromUtf16Error>
754+
pub fn from_utf16_in(v: &[u16], a: &A) -> Result<Self, FromUtf16Error>
755755
where
756756
A: ReallocRef,
757757
{

src/vec.rs

+25-16
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ impl<T> Vec<T> {
401401
#[inline]
402402
#[must_use]
403403
pub fn with_capacity(capacity: usize) -> Self {
404-
Self::with_capacity_in(capacity, Global)
404+
Self::with_capacity_in(capacity, &Global)
405405
}
406406

407407
/// Creates a `Vec<T>` directly from the raw components of another vector.
@@ -488,12 +488,12 @@ impl<T, A: DeallocRef> Vec<T, A> {
488488
/// * if the requested capacity exceeds `usize::MAX` bytes.
489489
/// * on 32-bit platforms if the requested capacity exceeds `isize::MAX` bytes.
490490
#[inline]
491-
pub fn with_capacity_in(capacity: usize, a: A) -> Self
491+
pub fn with_capacity_in(capacity: usize, a: &A) -> Self
492492
where
493493
A: AllocRef,
494494
{
495495
Self {
496-
buf: RawVec::with_capacity_in(capacity, &a),
496+
buf: RawVec::with_capacity_in(capacity, a),
497497
len: 0,
498498
}
499499
}
@@ -2024,11 +2024,11 @@ impl<T: PartialEq, A: DeallocRef> Vec<T, A> {
20242024

20252025
#[doc(hidden)]
20262026
pub fn from_elem<T: Clone>(elem: T, n: usize) -> Vec<T> {
2027-
from_elem_in(elem, n, Global)
2027+
from_elem_in(elem, n, &Global)
20282028
}
20292029

20302030
#[doc(hidden)]
2031-
pub fn from_elem_in<T: Clone, A>(elem: T, n: usize, a: A) -> Vec<T, A>
2031+
pub fn from_elem_in<T: Clone, A>(elem: T, n: usize, a: &A) -> Vec<T, A>
20322032
where
20332033
A: ReallocRef,
20342034
{
@@ -2043,23 +2043,24 @@ where
20432043
pub fn try_from_elem_in<T: Clone, A: ReallocRef>(
20442044
elem: T,
20452045
n: usize,
2046-
a: A,
2046+
a: &A,
20472047
) -> Result<Vec<T, A>, CollectionAllocErr<A>> {
20482048
<T as SpecFromElem<A>>::try_from_elem_in(elem, n, a)
20492049
}
20502050

20512051
// Specialization trait used for Vec::from_elem
20522052
trait SpecFromElem<A: AllocRef>: Sized {
2053-
fn try_from_elem_in(elem: Self, n: usize, a: A) -> Result<Vec<Self, A>, CollectionAllocErr<A>>;
2053+
fn try_from_elem_in(elem: Self, n: usize, a: &A)
2054+
-> Result<Vec<Self, A>, CollectionAllocErr<A>>;
20542055
}
20552056

20562057
impl<T: Clone, A: ReallocRef> SpecFromElem<A> for T {
20572058
default fn try_from_elem_in(
20582059
elem: Self,
20592060
n: usize,
2060-
a: A,
2061+
a: &A,
20612062
) -> Result<Vec<Self, A>, CollectionAllocErr<A>> {
2062-
let mut v = Vec::try_with_capacity_in(n, &a)?;
2063+
let mut v = Vec::try_with_capacity_in(n, a)?;
20632064
v.try_extend_with(n, ExtendElement(elem))?;
20642065
Ok(v)
20652066
}
@@ -2068,15 +2069,19 @@ impl<T: Clone, A: ReallocRef> SpecFromElem<A> for T {
20682069
#[allow(clippy::use_self)]
20692070
impl<A: ReallocRef> SpecFromElem<A> for u8 {
20702071
#[inline]
2071-
fn try_from_elem_in(elem: Self, n: usize, a: A) -> Result<Vec<Self, A>, CollectionAllocErr<A>> {
2072+
fn try_from_elem_in(
2073+
elem: Self,
2074+
n: usize,
2075+
a: &A,
2076+
) -> Result<Vec<Self, A>, CollectionAllocErr<A>> {
20722077
if elem == 0 {
20732078
return Ok(Vec {
2074-
buf: RawVec::try_with_capacity_zeroed_in(n, &a)?,
2079+
buf: RawVec::try_with_capacity_zeroed_in(n, a)?,
20752080
len: n,
20762081
});
20772082
}
20782083
unsafe {
2079-
let mut v = Vec::try_with_capacity_in(n, &a)?;
2084+
let mut v = Vec::try_with_capacity_in(n, a)?;
20802085
ptr::write_bytes(v.as_mut_ptr(), elem, n);
20812086
v.set_len(n);
20822087
Ok(v)
@@ -2086,14 +2091,18 @@ impl<A: ReallocRef> SpecFromElem<A> for u8 {
20862091

20872092
impl<T: Clone + IsZero, A: ReallocRef> SpecFromElem<A> for T {
20882093
#[inline]
2089-
fn try_from_elem_in(elem: Self, n: usize, a: A) -> Result<Vec<Self, A>, CollectionAllocErr<A>> {
2094+
fn try_from_elem_in(
2095+
elem: Self,
2096+
n: usize,
2097+
a: &A,
2098+
) -> Result<Vec<Self, A>, CollectionAllocErr<A>> {
20902099
if elem.is_zero() {
20912100
return Ok(Vec {
2092-
buf: RawVec::try_with_capacity_zeroed_in(n, &a)?,
2101+
buf: RawVec::try_with_capacity_zeroed_in(n, a)?,
20932102
len: n,
20942103
});
20952104
}
2096-
let mut v = Vec::try_with_capacity_in(n, &a)?;
2105+
let mut v = Vec::try_with_capacity_in(n, a)?;
20972106
v.try_extend_with(n, ExtendElement(elem))?;
20982107
Ok(v)
20992108
}
@@ -2201,7 +2210,7 @@ impl<T: Clone, A: AllocRef, B: AllocRef> CloneIn<B> for Vec<T, A> {
22012210
type Cloned = Vec<T, B>;
22022211

22032212
fn clone_in(&self, a: B) -> Self::Cloned {
2204-
let mut v = Vec::with_capacity_in(self.len(), a);
2213+
let mut v = Vec::with_capacity_in(self.len(), &a);
22052214

22062215
self.iter()
22072216
.cloned()

0 commit comments

Comments
 (0)