style: applying Rust style

This commit is contained in:
C 2020-12-05 01:44:07 +00:00
parent 6002b280f1
commit 2de8356f60
14 changed files with 75 additions and 81 deletions

View File

@ -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]> {
@ -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))
}
}
}

View File

@ -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>`.
///

View File

@ -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.
///
@ -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")]
@ -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;
@ -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 {
@ -140,4 +140,4 @@ impl<T, F, A: Allocator> Drop for DrainFilter<'_, T, F, A>
backshift.drain.for_each(drop);
}
}
}
}

View File

@ -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> {

View File

@ -1,14 +1,12 @@
use crate::alloc::{Allocator, Global};
use crate::raw_vec::RawVec;
use core::marker::PhantomData;
use core::intrinsics::{arith_offset};
use core::mem::{self};
use core::fmt;
use core::intrinsics::arith_offset;
use core::iter::{FusedIterator, InPlaceIterable, SourceIter, TrustedLen, TrustedRandomAccess};
use core::marker::PhantomData;
use core::mem::{self};
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.
///
@ -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)`
@ -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

View File

@ -68,4 +68,4 @@ unsafe impl<T: ?Sized> IsZero for Option<Box<T>> {
fn is_zero(&self) -> bool {
self.is_none()
}
}
}

View File

@ -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};
@ -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;

View File

@ -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]) => {

View File

@ -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.
@ -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
@ -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
@ -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);

View File

@ -1,9 +1,9 @@
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> {
@ -11,8 +11,8 @@ pub(super) trait SpecExtend<T, 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)
@ -20,8 +20,8 @@ impl<T, I, A: Allocator> SpecExtend<T, I> for Vec<T, A>
}
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.
@ -62,9 +62,9 @@ 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())
@ -72,8 +72,8 @@ impl<'a, T: 'a, I, A: Allocator + 'a> SpecExtend<&'a T, I> for Vec<T, A>
}
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();

View File

@ -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 {
@ -57,4 +57,4 @@ impl<T: Clone + IsZero> SpecFromElem for T {
v.extend_with(n, ExtendElement(elem));
v
}
}
}

View File

@ -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
///
@ -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)
@ -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())

View File

@ -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
@ -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
@ -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() {

View File

@ -2,7 +2,7 @@ use crate::alloc::{Allocator, Global};
use core::ptr::{self};
use core::slice::{self};
use super::{Vec, Drain};
use super::{Drain, Vec};
/// A splicing iterator for `Vec`.
///
@ -130,4 +130,4 @@ impl<T, A: Allocator> Drain<'_, T, A> {
}
self.tail_start = new_tail_start;
}
}
}