Skip to content

Commit

Permalink
style: applying Rust style
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperC286 committed Dec 29, 2020
1 parent 6002b28 commit 2de8356
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 80 deletions.
10 changes: 5 additions & 5 deletions library/alloc/src/vec/cow.rs
@@ -1,7 +1,7 @@
use crate::borrow::Cow;
use core::iter::{FromIterator};
use core::iter::FromIterator;

use super::{Vec};
use super::Vec;

#[stable(feature = "cow_from_vec", since = "1.8.0")]
impl<'a, T: Clone> From<&'a [T]> for Cow<'a, [T]> {
Expand All @@ -26,10 +26,10 @@ impl<'a, T: Clone> From<&'a Vec<T>> for Cow<'a, [T]> {

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> FromIterator<T> for Cow<'a, [T]>
where
T: Clone,
where
T: Clone,
{
fn from_iter<I: IntoIterator<Item = T>>(it: I) -> Cow<'a, [T]> {
Cow::Owned(FromIterator::from_iter(it))
}
}
}
8 changes: 3 additions & 5 deletions library/alloc/src/vec/drain.rs
@@ -1,13 +1,11 @@
use crate::alloc::{Allocator, Global};
use core::iter::{
FusedIterator, TrustedLen,
};
use core::fmt;
use core::iter::{FusedIterator, TrustedLen};
use core::mem::{self};
use core::ptr::{self, NonNull};
use core::slice::{self};
use core::fmt;

use super::{Vec};
use super::Vec;

/// A draining iterator for `Vec<T>`.
///
Expand Down
26 changes: 13 additions & 13 deletions library/alloc/src/vec/drain_filter.rs
@@ -1,8 +1,8 @@
use crate::alloc::{Allocator, Global};
use core::ptr::{self};
use core::slice::{self};
use crate::alloc::{Allocator, Global};

use super::{Vec};
use super::Vec;

/// An iterator which uses a closure to determine if an element should be removed.
///
Expand Down Expand Up @@ -45,8 +45,8 @@ pub struct DrainFilter<
}

impl<T, F, A: Allocator> DrainFilter<'_, T, F, A>
where
F: FnMut(&mut T) -> bool,
where
F: FnMut(&mut T) -> bool,
{
/// Returns a reference to the underlying allocator.
#[unstable(feature = "allocator_api", issue = "32838")]
Expand All @@ -58,8 +58,8 @@ impl<T, F, A: Allocator> DrainFilter<'_, T, F, A>

#[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")]
impl<T, F, A: Allocator> Iterator for DrainFilter<'_, T, F, A>
where
F: FnMut(&mut T) -> bool,
where
F: FnMut(&mut T) -> bool,
{
type Item = T;

Expand Down Expand Up @@ -96,20 +96,20 @@ impl<T, F, A: Allocator> Iterator for DrainFilter<'_, T, F, A>

#[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")]
impl<T, F, A: Allocator> Drop for DrainFilter<'_, T, F, A>
where
F: FnMut(&mut T) -> bool,
where
F: FnMut(&mut T) -> bool,
{
fn drop(&mut self) {
struct BackshiftOnDrop<'a, 'b, T, F, A: Allocator>
where
F: FnMut(&mut T) -> bool,
where
F: FnMut(&mut T) -> bool,
{
drain: &'b mut DrainFilter<'a, T, F, A>,
}

impl<'a, 'b, T, F, A: Allocator> Drop for BackshiftOnDrop<'a, 'b, T, F, A>
where
F: FnMut(&mut T) -> bool,
where
F: FnMut(&mut T) -> bool,
{
fn drop(&mut self) {
unsafe {
Expand Down Expand Up @@ -140,4 +140,4 @@ impl<T, F, A: Allocator> Drop for DrainFilter<'_, T, F, A>
backshift.drain.for_each(drop);
}
}
}
}
6 changes: 3 additions & 3 deletions library/alloc/src/vec/in_place_drop.rs
Expand Up @@ -3,9 +3,9 @@ use core::slice::{self};

// A helper struct for in-place iteration that drops the destination slice of iteration,
// i.e. the head. The source slice (the tail) is dropped by IntoIter.
pub (super) struct InPlaceDrop<T> {
pub (super) inner: *mut T,
pub (super) dst: *mut T,
pub(super) struct InPlaceDrop<T> {
pub(super) inner: *mut T,
pub(super) dst: *mut T,
}

impl<T> InPlaceDrop<T> {
Expand Down
16 changes: 7 additions & 9 deletions library/alloc/src/vec/into_iter.rs
@@ -1,14 +1,12 @@
use crate::alloc::{Allocator, Global};
use crate::raw_vec::RawVec;
use core::fmt;
use core::intrinsics::arith_offset;
use core::iter::{FusedIterator, InPlaceIterable, SourceIter, TrustedLen, TrustedRandomAccess};
use core::marker::PhantomData;
use core::intrinsics::{arith_offset};
use core::mem::{self};
use core::fmt;
use core::ptr::{self, NonNull};
use core::slice::{self};
use core::iter::{
FusedIterator, InPlaceIterable, SourceIter, TrustedLen, TrustedRandomAccess,
};

/// An iterator that moves out of a vector.
///
Expand Down Expand Up @@ -156,8 +154,8 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
}

unsafe fn __iterator_get_unchecked(&mut self, i: usize) -> Self::Item
where
Self: TrustedRandomAccess,
where
Self: TrustedRandomAccess,
{
// SAFETY: the caller must guarantee that `i` is in bounds of the
// `Vec<T>`, so `i` cannot overflow an `isize`, and the `self.ptr.add(i)`
Expand Down Expand Up @@ -211,8 +209,8 @@ unsafe impl<T, A: Allocator> TrustedLen for IntoIter<T, A> {}
// T: Copy as approximation for !Drop since get_unchecked does not advance self.ptr
// and thus we can't implement drop-handling
unsafe impl<T, A: Allocator> TrustedRandomAccess for IntoIter<T, A>
where
T: Copy,
where
T: Copy,
{
fn may_have_side_effect() -> bool {
false
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/vec/is_zero.rs
Expand Up @@ -68,4 +68,4 @@ unsafe impl<T: ?Sized> IsZero for Option<Box<T>> {
fn is_zero(&self) -> bool {
self.is_none()
}
}
}
4 changes: 2 additions & 2 deletions library/alloc/src/vec/mod.rs
Expand Up @@ -58,7 +58,7 @@ use core::convert::TryFrom;
use core::fmt;
use core::hash::{Hash, Hasher};
use core::intrinsics::{arith_offset, assume};
use core::iter::{FromIterator};
use core::iter::FromIterator;
use core::marker::PhantomData;
use core::mem::{self, ManuallyDrop, MaybeUninit};
use core::ops::{self, Index, IndexMut, Range, RangeBounds};
Expand Down Expand Up @@ -88,9 +88,9 @@ mod drain;

mod cow;

pub(crate) use self::into_iter::AsIntoIter;
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::into_iter::IntoIter;
pub (crate) use self::into_iter::AsIntoIter;

mod into_iter;

Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/vec/partial_eq.rs
@@ -1,7 +1,7 @@
use crate::alloc::{Allocator};
use crate::alloc::Allocator;
use crate::borrow::Cow;

use super::{Vec};
use super::Vec;

macro_rules! __impl_slice_eq1 {
([$($vars:tt)*] $lhs:ty, $rhs:ty $(where $ty:ty: $bound:ident)?, #[$stability:meta]) => {
Expand Down
16 changes: 7 additions & 9 deletions library/alloc/src/vec/source_iter_marker.rs
@@ -1,10 +1,8 @@
use core::iter::{
InPlaceIterable, SourceIter,
};
use core::iter::{InPlaceIterable, SourceIter};
use core::mem::{self, ManuallyDrop};
use core::ptr::{self};

use super::{Vec, InPlaceDrop, AsIntoIter, SpecFromIter, SpecFromIterNested};
use super::{AsIntoIter, InPlaceDrop, SpecFromIter, SpecFromIterNested, Vec};

/// Specialization marker for collecting an iterator pipeline into a Vec while reusing the
/// source allocation, i.e. executing the pipeline in place.
Expand All @@ -13,7 +11,7 @@ use super::{Vec, InPlaceDrop, AsIntoIter, SpecFromIter, SpecFromIterNested};
/// which is to be reused. But it is not sufficient for the specialization to be valid. See
/// additional bounds on the impl.
#[rustc_unsafe_specialization_marker]
pub (super) trait SourceIterMarker: SourceIter<Source: AsIntoIter> {}
pub(super) trait SourceIterMarker: SourceIter<Source: AsIntoIter> {}

// The std-internal SourceIter/InPlaceIterable traits are only implemented by chains of
// Adapter<Adapter<Adapter<IntoIter>>> (all owned by core/std). Additional bounds
Expand All @@ -24,8 +22,8 @@ pub (super) trait SourceIterMarker: SourceIter<Source: AsIntoIter> {}
impl<T> SourceIterMarker for T where T: SourceIter<Source: AsIntoIter> + InPlaceIterable {}

impl<T, I> SpecFromIter<T, I> for Vec<T>
where
I: Iterator<Item = T> + SourceIterMarker,
where
I: Iterator<Item = T> + SourceIterMarker,
{
default fn from_iter(mut iterator: I) -> Self {
// Additional requirements which cannot expressed via trait bounds. We rely on const eval
Expand All @@ -35,9 +33,9 @@ impl<T, I> SpecFromIter<T, I> for Vec<T>
// c) alignments match as required by Alloc contract
if mem::size_of::<T>() == 0
|| mem::size_of::<T>()
!= mem::size_of::<<<I as SourceIter>::Source as AsIntoIter>::Item>()
!= mem::size_of::<<<I as SourceIter>::Source as AsIntoIter>::Item>()
|| mem::align_of::<T>()
!= mem::align_of::<<<I as SourceIter>::Source as AsIntoIter>::Item>()
!= mem::align_of::<<<I as SourceIter>::Source as AsIntoIter>::Item>()
{
// fallback to more generic implementations
return SpecFromIterNested::from_iter(iterator);
Expand Down
26 changes: 13 additions & 13 deletions library/alloc/src/vec/spec_extend.rs
@@ -1,27 +1,27 @@
use crate::alloc::{Allocator};
use core::iter::{TrustedLen};
use core::slice::{self};
use crate::alloc::Allocator;
use core::iter::TrustedLen;
use core::ptr::{self};
use core::slice::{self};

use super::{Vec, IntoIter, SetLenOnDrop};
use super::{IntoIter, SetLenOnDrop, Vec};

// Specialization trait used for Vec::extend
pub(super) trait SpecExtend<T, I> {
fn spec_extend(&mut self, iter: I);
}

impl<T, I, A: Allocator> SpecExtend<T, I> for Vec<T, A>
where
I: Iterator<Item = T>,
where
I: Iterator<Item = T>,
{
default fn spec_extend(&mut self, iter: I) {
self.extend_desugared(iter)
}
}

impl<T, I, A: Allocator> SpecExtend<T, I> for Vec<T, A>
where
I: TrustedLen<Item = T>,
where
I: TrustedLen<Item = T>,
{
default fn spec_extend(&mut self, iterator: I) {
// This is the case for a TrustedLen iterator.
Expand Down Expand Up @@ -62,18 +62,18 @@ impl<T, A: Allocator> SpecExtend<T, IntoIter<T>> for Vec<T, A> {
}

impl<'a, T: 'a, I, A: Allocator + 'a> SpecExtend<&'a T, I> for Vec<T, A>
where
I: Iterator<Item = &'a T>,
T: Clone,
where
I: Iterator<Item = &'a T>,
T: Clone,
{
default fn spec_extend(&mut self, iterator: I) {
self.spec_extend(iterator.cloned())
}
}

impl<'a, T: 'a, A: Allocator + 'a> SpecExtend<&'a T, slice::Iter<'a, T>> for Vec<T, A>
where
T: Copy,
where
T: Copy,
{
fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) {
let slice = iterator.as_slice();
Expand Down
6 changes: 3 additions & 3 deletions library/alloc/src/vec/spec_from_elem.rs
@@ -1,8 +1,8 @@
use crate::alloc::{Allocator};
use crate::alloc::Allocator;
use crate::raw_vec::RawVec;
use core::ptr::{self};

use super::{Vec, IsZero, ExtendElement};
use super::{ExtendElement, IsZero, Vec};

// Specialization trait used for Vec::from_elem
pub(super) trait SpecFromElem: Sized {
Expand Down Expand Up @@ -57,4 +57,4 @@ impl<T: Clone + IsZero> SpecFromElem for T {
v.extend_with(n, ExtendElement(elem));
v
}
}
}
14 changes: 7 additions & 7 deletions library/alloc/src/vec/spec_from_iter.rs
@@ -1,9 +1,9 @@
use crate::alloc::Global;
use core::mem::{ManuallyDrop};
use core::mem::ManuallyDrop;
use core::ptr::{self};
use core::slice::{self};

use super::{Vec, IntoIter, SpecFromIterNested, SpecExtend};
use super::{IntoIter, SpecExtend, SpecFromIterNested, Vec};

/// Specialization trait used for Vec::from_iter
///
Expand All @@ -30,8 +30,8 @@ pub(super) trait SpecFromIter<T, I> {
}

impl<T, I> SpecFromIter<T, I> for Vec<T>
where
I: Iterator<Item = T>,
where
I: Iterator<Item = T>,
{
default fn from_iter(iterator: I) -> Self {
SpecFromIterNested::from_iter(iterator)
Expand Down Expand Up @@ -68,9 +68,9 @@ impl<T> SpecFromIter<T, IntoIter<T>> for Vec<T> {
}

impl<'a, T: 'a, I> SpecFromIter<&'a T, I> for Vec<T>
where
I: Iterator<Item = &'a T>,
T: Clone,
where
I: Iterator<Item = &'a T>,
T: Clone,
{
default fn from_iter(iterator: I) -> Self {
SpecFromIter::from_iter(iterator.cloned())
Expand Down
12 changes: 6 additions & 6 deletions library/alloc/src/vec/spec_from_iter_nested.rs
@@ -1,7 +1,7 @@
use core::iter::TrustedLen;
use core::ptr::{self};
use core::iter::{TrustedLen};

use super::{Vec, SpecExtend};
use super::{SpecExtend, Vec};

/// Another specialization trait for Vec::from_iter
/// necessary to manually prioritize overlapping specializations
Expand All @@ -11,8 +11,8 @@ pub(super) trait SpecFromIterNested<T, I> {
}

impl<T, I> SpecFromIterNested<T, I> for Vec<T>
where
I: Iterator<Item = T>,
where
I: Iterator<Item = T>,
{
default fn from_iter(mut iterator: I) -> Self {
// Unroll the first iteration, as the vector is going to be
Expand Down Expand Up @@ -40,8 +40,8 @@ impl<T, I> SpecFromIterNested<T, I> for Vec<T>
}

impl<T, I> SpecFromIterNested<T, I> for Vec<T>
where
I: TrustedLen<Item = T>,
where
I: TrustedLen<Item = T>,
{
fn from_iter(iterator: I) -> Self {
let mut vector = match iterator.size_hint() {
Expand Down

0 comments on commit 2de8356

Please sign in to comment.