From 2de8356f60a7a9800809ab60e813fcfd4a7accf2 Mon Sep 17 00:00:00 2001 From: C Date: Sat, 5 Dec 2020 01:44:07 +0000 Subject: [PATCH] style: applying Rust style --- library/alloc/src/vec/cow.rs | 10 +++---- library/alloc/src/vec/drain.rs | 8 +++--- library/alloc/src/vec/drain_filter.rs | 26 +++++++++---------- library/alloc/src/vec/in_place_drop.rs | 6 ++--- library/alloc/src/vec/into_iter.rs | 18 ++++++------- library/alloc/src/vec/is_zero.rs | 2 +- library/alloc/src/vec/mod.rs | 4 +-- library/alloc/src/vec/partial_eq.rs | 4 +-- library/alloc/src/vec/source_iter_marker.rs | 16 +++++------- library/alloc/src/vec/spec_extend.rs | 26 +++++++++---------- library/alloc/src/vec/spec_from_elem.rs | 6 ++--- library/alloc/src/vec/spec_from_iter.rs | 14 +++++----- .../alloc/src/vec/spec_from_iter_nested.rs | 12 ++++----- library/alloc/src/vec/splice.rs | 4 +-- 14 files changed, 75 insertions(+), 81 deletions(-) diff --git a/library/alloc/src/vec/cow.rs b/library/alloc/src/vec/cow.rs index 15942f9892d..73d15d30647 100644 --- a/library/alloc/src/vec/cow.rs +++ b/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]> { @@ -26,10 +26,10 @@ impl<'a, T: Clone> From<&'a Vec> for Cow<'a, [T]> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> FromIterator for Cow<'a, [T]> - where - T: Clone, +where + T: Clone, { fn from_iter>(it: I) -> Cow<'a, [T]> { Cow::Owned(FromIterator::from_iter(it)) } -} \ No newline at end of file +} diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs index e61f17a1c30..fb32d144f87 100644 --- a/library/alloc/src/vec/drain.rs +++ b/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`. /// diff --git a/library/alloc/src/vec/drain_filter.rs b/library/alloc/src/vec/drain_filter.rs index 9d898c7c756..3c37c92ae44 100644 --- a/library/alloc/src/vec/drain_filter.rs +++ b/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. /// @@ -45,8 +45,8 @@ pub struct DrainFilter< } impl 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 DrainFilter<'_, T, F, A> #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] impl 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 Iterator for DrainFilter<'_, T, F, A> #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] impl 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 Drop for DrainFilter<'_, T, F, A> backshift.drain.for_each(drop); } } -} \ No newline at end of file +} diff --git a/library/alloc/src/vec/in_place_drop.rs b/library/alloc/src/vec/in_place_drop.rs index 3a0ecc529c0..354d25c2389 100644 --- a/library/alloc/src/vec/in_place_drop.rs +++ b/library/alloc/src/vec/in_place_drop.rs @@ -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 { - pub (super) inner: *mut T, - pub (super) dst: *mut T, +pub(super) struct InPlaceDrop { + pub(super) inner: *mut T, + pub(super) dst: *mut T, } impl InPlaceDrop { diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index c4330df4ad9..1788690d96b 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -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 Iterator for IntoIter { } 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`, so `i` cannot overflow an `isize`, and the `self.ptr.add(i)` @@ -211,8 +209,8 @@ unsafe impl TrustedLen for IntoIter {} // T: Copy as approximation for !Drop since get_unchecked does not advance self.ptr // and thus we can't implement drop-handling unsafe impl TrustedRandomAccess for IntoIter - where - T: Copy, +where + T: Copy, { fn may_have_side_effect() -> bool { false diff --git a/library/alloc/src/vec/is_zero.rs b/library/alloc/src/vec/is_zero.rs index 961f6ca171b..b5739970b6e 100644 --- a/library/alloc/src/vec/is_zero.rs +++ b/library/alloc/src/vec/is_zero.rs @@ -68,4 +68,4 @@ unsafe impl IsZero for Option> { fn is_zero(&self) -> bool { self.is_none() } -} \ No newline at end of file +} diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 2947c6a299f..2a83eb33fe3 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -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; diff --git a/library/alloc/src/vec/partial_eq.rs b/library/alloc/src/vec/partial_eq.rs index 617f0404439..ff90b6caf46 100644 --- a/library/alloc/src/vec/partial_eq.rs +++ b/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]) => { diff --git a/library/alloc/src/vec/source_iter_marker.rs b/library/alloc/src/vec/source_iter_marker.rs index eb3ae01a47e..8c0e95559fa 100644 --- a/library/alloc/src/vec/source_iter_marker.rs +++ b/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. @@ -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 {} +pub(super) trait SourceIterMarker: SourceIter {} // The std-internal SourceIter/InPlaceIterable traits are only implemented by chains of // Adapter>> (all owned by core/std). Additional bounds @@ -24,8 +22,8 @@ pub (super) trait SourceIterMarker: SourceIter {} impl SourceIterMarker for T where T: SourceIter + InPlaceIterable {} impl SpecFromIter for Vec - where - I: Iterator + SourceIterMarker, +where + I: Iterator + 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 SpecFromIter for Vec // c) alignments match as required by Alloc contract if mem::size_of::() == 0 || mem::size_of::() - != mem::size_of::<<::Source as AsIntoIter>::Item>() + != mem::size_of::<<::Source as AsIntoIter>::Item>() || mem::align_of::() - != mem::align_of::<<::Source as AsIntoIter>::Item>() + != mem::align_of::<<::Source as AsIntoIter>::Item>() { // fallback to more generic implementations return SpecFromIterNested::from_iter(iterator); diff --git a/library/alloc/src/vec/spec_extend.rs b/library/alloc/src/vec/spec_extend.rs index 6959733d074..b6186a7ebaf 100644 --- a/library/alloc/src/vec/spec_extend.rs +++ b/library/alloc/src/vec/spec_extend.rs @@ -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 { @@ -11,8 +11,8 @@ pub(super) trait SpecExtend { } impl SpecExtend for Vec - where - I: Iterator, +where + I: Iterator, { default fn spec_extend(&mut self, iter: I) { self.extend_desugared(iter) @@ -20,8 +20,8 @@ impl SpecExtend for Vec } impl SpecExtend for Vec - where - I: TrustedLen, +where + I: TrustedLen, { default fn spec_extend(&mut self, iterator: I) { // This is the case for a TrustedLen iterator. @@ -62,9 +62,9 @@ impl SpecExtend> for Vec { } impl<'a, T: 'a, I, A: Allocator + 'a> SpecExtend<&'a T, I> for Vec - where - I: Iterator, - T: Clone, +where + I: Iterator, + 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 } impl<'a, T: 'a, A: Allocator + 'a> SpecExtend<&'a T, slice::Iter<'a, T>> for Vec - where - T: Copy, +where + T: Copy, { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/vec/spec_from_elem.rs b/library/alloc/src/vec/spec_from_elem.rs index ef89054ea13..de610174783 100644 --- a/library/alloc/src/vec/spec_from_elem.rs +++ b/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 { @@ -57,4 +57,4 @@ impl SpecFromElem for T { v.extend_with(n, ExtendElement(elem)); v } -} \ No newline at end of file +} diff --git a/library/alloc/src/vec/spec_from_iter.rs b/library/alloc/src/vec/spec_from_iter.rs index bf07fc97f89..4349d158210 100644 --- a/library/alloc/src/vec/spec_from_iter.rs +++ b/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 /// @@ -30,8 +30,8 @@ pub(super) trait SpecFromIter { } impl SpecFromIter for Vec - where - I: Iterator, +where + I: Iterator, { default fn from_iter(iterator: I) -> Self { SpecFromIterNested::from_iter(iterator) @@ -68,9 +68,9 @@ impl SpecFromIter> for Vec { } impl<'a, T: 'a, I> SpecFromIter<&'a T, I> for Vec - where - I: Iterator, - T: Clone, +where + I: Iterator, + T: Clone, { default fn from_iter(iterator: I) -> Self { SpecFromIter::from_iter(iterator.cloned()) diff --git a/library/alloc/src/vec/spec_from_iter_nested.rs b/library/alloc/src/vec/spec_from_iter_nested.rs index 0da42844c96..6abd4ff2a3f 100644 --- a/library/alloc/src/vec/spec_from_iter_nested.rs +++ b/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 @@ -11,8 +11,8 @@ pub(super) trait SpecFromIterNested { } impl SpecFromIterNested for Vec - where - I: Iterator, +where + I: Iterator, { default fn from_iter(mut iterator: I) -> Self { // Unroll the first iteration, as the vector is going to be @@ -40,8 +40,8 @@ impl SpecFromIterNested for Vec } impl SpecFromIterNested for Vec - where - I: TrustedLen, +where + I: TrustedLen, { fn from_iter(iterator: I) -> Self { let mut vector = match iterator.size_hint() { diff --git a/library/alloc/src/vec/splice.rs b/library/alloc/src/vec/splice.rs index 86b2fa0968e..0a27b5b62ec 100644 --- a/library/alloc/src/vec/splice.rs +++ b/library/alloc/src/vec/splice.rs @@ -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 Drain<'_, T, A> { } self.tail_start = new_tail_start; } -} \ No newline at end of file +}