Skip to content

Commit 0dfd875

Browse files
committed
rustfmt libcollections
1 parent 1f1a1e6 commit 0dfd875

File tree

14 files changed

+1426
-982
lines changed

14 files changed

+1426
-982
lines changed

src/libcollections/binary_heap.rs

+66-28
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
#![allow(missing_docs)]
152152
#![stable(feature = "rust1", since = "1.0.0")]
153153

154-
use core::iter::{FromIterator};
154+
use core::iter::FromIterator;
155155
use core::mem::swap;
156156
use core::ptr;
157157
use core::fmt;
@@ -186,7 +186,9 @@ impl<T: Clone> Clone for BinaryHeap<T> {
186186
#[stable(feature = "rust1", since = "1.0.0")]
187187
impl<T: Ord> Default for BinaryHeap<T> {
188188
#[inline]
189-
fn default() -> BinaryHeap<T> { BinaryHeap::new() }
189+
fn default() -> BinaryHeap<T> {
190+
BinaryHeap::new()
191+
}
190192
}
191193

192194
#[stable(feature = "binaryheap_debug", since = "1.4.0")]
@@ -207,7 +209,9 @@ impl<T: Ord> BinaryHeap<T> {
207209
/// heap.push(4);
208210
/// ```
209211
#[stable(feature = "rust1", since = "1.0.0")]
210-
pub fn new() -> BinaryHeap<T> { BinaryHeap { data: vec![] } }
212+
pub fn new() -> BinaryHeap<T> {
213+
BinaryHeap { data: vec![] }
214+
}
211215

212216
/// Creates an empty `BinaryHeap` with a specific capacity.
213217
/// This preallocates enough memory for `capacity` elements,
@@ -296,7 +300,9 @@ impl<T: Ord> BinaryHeap<T> {
296300
/// heap.push(4);
297301
/// ```
298302
#[stable(feature = "rust1", since = "1.0.0")]
299-
pub fn capacity(&self) -> usize { self.data.capacity() }
303+
pub fn capacity(&self) -> usize {
304+
self.data.capacity()
305+
}
300306

301307
/// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the
302308
/// given `BinaryHeap`. Does nothing if the capacity is already sufficient.
@@ -419,11 +425,13 @@ impl<T: Ord> BinaryHeap<T> {
419425
pub fn push_pop(&mut self, mut item: T) -> T {
420426
match self.data.get_mut(0) {
421427
None => return item,
422-
Some(top) => if *top > item {
423-
swap(&mut item, top);
424-
} else {
425-
return item;
426-
},
428+
Some(top) => {
429+
if *top > item {
430+
swap(&mut item, top);
431+
} else {
432+
return item;
433+
}
434+
}
427435
}
428436

429437
self.sift_down(0);
@@ -522,7 +530,9 @@ impl<T: Ord> BinaryHeap<T> {
522530

523531
while hole.pos() > start {
524532
let parent = (hole.pos() - 1) / 2;
525-
if hole.element() <= hole.get(parent) { break; }
533+
if hole.element() <= hole.get(parent) {
534+
break;
535+
}
526536
hole.move_to(parent);
527537
}
528538
}
@@ -541,7 +551,9 @@ impl<T: Ord> BinaryHeap<T> {
541551
child = right;
542552
}
543553
// if we are already in order, stop.
544-
if hole.element() >= hole.get(child) { break; }
554+
if hole.element() >= hole.get(child) {
555+
break;
556+
}
545557
hole.move_to(child);
546558
child = 2 * hole.pos() + 1;
547559
}
@@ -555,11 +567,15 @@ impl<T: Ord> BinaryHeap<T> {
555567

556568
/// Returns the length of the binary heap.
557569
#[stable(feature = "rust1", since = "1.0.0")]
558-
pub fn len(&self) -> usize { self.data.len() }
570+
pub fn len(&self) -> usize {
571+
self.data.len()
572+
}
559573

560574
/// Checks if the binary heap is empty.
561575
#[stable(feature = "rust1", since = "1.0.0")]
562-
pub fn is_empty(&self) -> bool { self.len() == 0 }
576+
pub fn is_empty(&self) -> bool {
577+
self.len() == 0
578+
}
563579

564580
/// Clears the binary heap, returning an iterator over the removed elements.
565581
///
@@ -575,7 +591,9 @@ impl<T: Ord> BinaryHeap<T> {
575591

576592
/// Drops all items from the binary heap.
577593
#[stable(feature = "rust1", since = "1.0.0")]
578-
pub fn clear(&mut self) { self.drain(); }
594+
pub fn clear(&mut self) {
595+
self.drain();
596+
}
579597
}
580598

581599
/// Hole represents a hole in a slice i.e. an index without valid value
@@ -603,7 +621,9 @@ impl<'a, T> Hole<'a, T> {
603621
}
604622

605623
#[inline(always)]
606-
fn pos(&self) -> usize { self.pos }
624+
fn pos(&self) -> usize {
625+
self.pos
626+
}
607627

608628
/// Return a reference to the element removed
609629
#[inline(always)]
@@ -647,7 +667,7 @@ impl<'a, T> Drop for Hole<'a, T> {
647667

648668
/// `BinaryHeap` iterator.
649669
#[stable(feature = "rust1", since = "1.0.0")]
650-
pub struct Iter <'a, T: 'a> {
670+
pub struct Iter<'a, T: 'a> {
651671
iter: slice::Iter<'a, T>,
652672
}
653673

@@ -664,16 +684,22 @@ impl<'a, T> Iterator for Iter<'a, T> {
664684
type Item = &'a T;
665685

666686
#[inline]
667-
fn next(&mut self) -> Option<&'a T> { self.iter.next() }
687+
fn next(&mut self) -> Option<&'a T> {
688+
self.iter.next()
689+
}
668690

669691
#[inline]
670-
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
692+
fn size_hint(&self) -> (usize, Option<usize>) {
693+
self.iter.size_hint()
694+
}
671695
}
672696

673697
#[stable(feature = "rust1", since = "1.0.0")]
674698
impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
675699
#[inline]
676-
fn next_back(&mut self) -> Option<&'a T> { self.iter.next_back() }
700+
fn next_back(&mut self) -> Option<&'a T> {
701+
self.iter.next_back()
702+
}
677703
}
678704

679705
#[stable(feature = "rust1", since = "1.0.0")]
@@ -690,16 +716,22 @@ impl<T> Iterator for IntoIter<T> {
690716
type Item = T;
691717

692718
#[inline]
693-
fn next(&mut self) -> Option<T> { self.iter.next() }
719+
fn next(&mut self) -> Option<T> {
720+
self.iter.next()
721+
}
694722

695723
#[inline]
696-
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
724+
fn size_hint(&self) -> (usize, Option<usize>) {
725+
self.iter.size_hint()
726+
}
697727
}
698728

699729
#[stable(feature = "rust1", since = "1.0.0")]
700730
impl<T> DoubleEndedIterator for IntoIter<T> {
701731
#[inline]
702-
fn next_back(&mut self) -> Option<T> { self.iter.next_back() }
732+
fn next_back(&mut self) -> Option<T> {
733+
self.iter.next_back()
734+
}
703735
}
704736

705737
#[stable(feature = "rust1", since = "1.0.0")]
@@ -716,16 +748,22 @@ impl<'a, T: 'a> Iterator for Drain<'a, T> {
716748
type Item = T;
717749

718750
#[inline]
719-
fn next(&mut self) -> Option<T> { self.iter.next() }
751+
fn next(&mut self) -> Option<T> {
752+
self.iter.next()
753+
}
720754

721755
#[inline]
722-
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
756+
fn size_hint(&self) -> (usize, Option<usize>) {
757+
self.iter.size_hint()
758+
}
723759
}
724760

725761
#[stable(feature = "rust1", since = "1.0.0")]
726762
impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> {
727763
#[inline]
728-
fn next_back(&mut self) -> Option<T> { self.iter.next_back() }
764+
fn next_back(&mut self) -> Option<T> {
765+
self.iter.next_back()
766+
}
729767
}
730768

731769
#[stable(feature = "rust1", since = "1.0.0")]
@@ -753,7 +791,7 @@ impl<T> From<BinaryHeap<T>> for Vec<T> {
753791

754792
#[stable(feature = "rust1", since = "1.0.0")]
755793
impl<T: Ord> FromIterator<T> for BinaryHeap<T> {
756-
fn from_iter<I: IntoIterator<Item=T>>(iter: I) -> BinaryHeap<T> {
794+
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> BinaryHeap<T> {
757795
BinaryHeap::from(iter.into_iter().collect::<Vec<_>>())
758796
}
759797
}
@@ -796,7 +834,7 @@ impl<'a, T> IntoIterator for &'a BinaryHeap<T> where T: Ord {
796834

797835
#[stable(feature = "rust1", since = "1.0.0")]
798836
impl<T: Ord> Extend<T> for BinaryHeap<T> {
799-
fn extend<I: IntoIterator<Item=T>>(&mut self, iterable: I) {
837+
fn extend<I: IntoIterator<Item = T>>(&mut self, iterable: I) {
800838
let iter = iterable.into_iter();
801839
let (lower, _) = iter.size_hint();
802840

@@ -810,7 +848,7 @@ impl<T: Ord> Extend<T> for BinaryHeap<T> {
810848

811849
#[stable(feature = "extend_ref", since = "1.2.0")]
812850
impl<'a, T: 'a + Ord + Copy> Extend<&'a T> for BinaryHeap<T> {
813-
fn extend<I: IntoIterator<Item=&'a T>>(&mut self, iter: I) {
851+
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
814852
self.extend(iter.into_iter().cloned());
815853
}
816854
}

src/libcollections/borrow.rs

+27-21
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ use self::Cow::*;
2828
pub use core::borrow::{Borrow, BorrowMut};
2929

3030
#[stable(feature = "rust1", since = "1.0.0")]
31-
impl<'a, B: ?Sized> Borrow<B> for Cow<'a, B> where B: ToOwned, <B as ToOwned>::Owned: 'a {
31+
impl<'a, B: ?Sized> Borrow<B> for Cow<'a, B>
32+
where B: ToOwned,
33+
<B as ToOwned>::Owned: 'a
34+
{
3235
fn borrow(&self) -> &B {
3336
&**self
3437
}
@@ -53,7 +56,9 @@ pub trait ToOwned {
5356
#[stable(feature = "rust1", since = "1.0.0")]
5457
impl<T> ToOwned for T where T: Clone {
5558
type Owned = T;
56-
fn to_owned(&self) -> T { self.clone() }
59+
fn to_owned(&self) -> T {
60+
self.clone()
61+
}
5762
}
5863

5964
/// A clone-on-write smart pointer.
@@ -85,14 +90,16 @@ impl<T> ToOwned for T where T: Clone {
8590
/// }
8691
/// ```
8792
#[stable(feature = "rust1", since = "1.0.0")]
88-
pub enum Cow<'a, B: ?Sized + 'a> where B: ToOwned {
93+
pub enum Cow<'a, B: ?Sized + 'a>
94+
where B: ToOwned
95+
{
8996
/// Borrowed data.
9097
#[stable(feature = "rust1", since = "1.0.0")]
9198
Borrowed(&'a B),
9299

93100
/// Owned data.
94101
#[stable(feature = "rust1", since = "1.0.0")]
95-
Owned(<B as ToOwned>::Owned)
102+
Owned(<B as ToOwned>::Owned),
96103
}
97104

98105
#[stable(feature = "rust1", since = "1.0.0")]
@@ -103,7 +110,7 @@ impl<'a, B: ?Sized> Clone for Cow<'a, B> where B: ToOwned {
103110
Owned(ref o) => {
104111
let b: &B = o.borrow();
105112
Owned(b.to_owned())
106-
},
113+
}
107114
}
108115
}
109116
}
@@ -131,7 +138,7 @@ impl<'a, B: ?Sized> Cow<'a, B> where B: ToOwned {
131138
*self = Owned(borrowed.to_owned());
132139
self.to_mut()
133140
}
134-
Owned(ref mut owned) => owned
141+
Owned(ref mut owned) => owned,
135142
}
136143
}
137144

@@ -154,7 +161,7 @@ impl<'a, B: ?Sized> Cow<'a, B> where B: ToOwned {
154161
pub fn into_owned(self) -> <B as ToOwned>::Owned {
155162
match self {
156163
Borrowed(borrowed) => borrowed.to_owned(),
157-
Owned(owned) => owned
164+
Owned(owned) => owned,
158165
}
159166
}
160167
}
@@ -166,7 +173,7 @@ impl<'a, B: ?Sized> Deref for Cow<'a, B> where B: ToOwned {
166173
fn deref(&self) -> &B {
167174
match *self {
168175
Borrowed(borrowed) => borrowed,
169-
Owned(ref owned) => owned.borrow()
176+
Owned(ref owned) => owned.borrow(),
170177
}
171178
}
172179
}
@@ -183,8 +190,9 @@ impl<'a, B: ?Sized> Ord for Cow<'a, B> where B: Ord + ToOwned {
183190
}
184191

185192
#[stable(feature = "rust1", since = "1.0.0")]
186-
impl<'a, 'b, B: ?Sized, C: ?Sized> PartialEq<Cow<'b, C>> for Cow<'a, B> where
187-
B: PartialEq<C> + ToOwned, C: ToOwned,
193+
impl<'a, 'b, B: ?Sized, C: ?Sized> PartialEq<Cow<'b, C>> for Cow<'a, B>
194+
where B: PartialEq<C> + ToOwned,
195+
C: ToOwned
188196
{
189197
#[inline]
190198
fn eq(&self, other: &Cow<'b, C>) -> bool {
@@ -193,18 +201,17 @@ impl<'a, 'b, B: ?Sized, C: ?Sized> PartialEq<Cow<'b, C>> for Cow<'a, B> where
193201
}
194202

195203
#[stable(feature = "rust1", since = "1.0.0")]
196-
impl<'a, B: ?Sized> PartialOrd for Cow<'a, B> where B: PartialOrd + ToOwned,
197-
{
204+
impl<'a, B: ?Sized> PartialOrd for Cow<'a, B> where B: PartialOrd + ToOwned {
198205
#[inline]
199206
fn partial_cmp(&self, other: &Cow<'a, B>) -> Option<Ordering> {
200207
PartialOrd::partial_cmp(&**self, &**other)
201208
}
202209
}
203210

204211
#[stable(feature = "rust1", since = "1.0.0")]
205-
impl<'a, B: ?Sized> fmt::Debug for Cow<'a, B> where
206-
B: fmt::Debug + ToOwned,
207-
<B as ToOwned>::Owned: fmt::Debug,
212+
impl<'a, B: ?Sized> fmt::Debug for Cow<'a, B>
213+
where B: fmt::Debug + ToOwned,
214+
<B as ToOwned>::Owned: fmt::Debug
208215
{
209216
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
210217
match *self {
@@ -215,9 +222,9 @@ impl<'a, B: ?Sized> fmt::Debug for Cow<'a, B> where
215222
}
216223

217224
#[stable(feature = "rust1", since = "1.0.0")]
218-
impl<'a, B: ?Sized> fmt::Display for Cow<'a, B> where
219-
B: fmt::Display + ToOwned,
220-
<B as ToOwned>::Owned: fmt::Display,
225+
impl<'a, B: ?Sized> fmt::Display for Cow<'a, B>
226+
where B: fmt::Display + ToOwned,
227+
<B as ToOwned>::Owned: fmt::Display
221228
{
222229
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
223230
match *self {
@@ -228,8 +235,7 @@ impl<'a, B: ?Sized> fmt::Display for Cow<'a, B> where
228235
}
229236

230237
#[stable(feature = "rust1", since = "1.0.0")]
231-
impl<'a, B: ?Sized> Hash for Cow<'a, B> where B: Hash + ToOwned
232-
{
238+
impl<'a, B: ?Sized> Hash for Cow<'a, B> where B: Hash + ToOwned {
233239
#[inline]
234240
fn hash<H: Hasher>(&self, state: &mut H) {
235241
Hash::hash(&**self, state)
@@ -245,7 +251,7 @@ pub trait IntoCow<'a, B: ?Sized> where B: ToOwned {
245251
}
246252

247253
#[stable(feature = "rust1", since = "1.0.0")]
248-
impl<'a, B: ?Sized> IntoCow<'a, B> for Cow<'a, B> where B: ToOwned {
254+
impl<'a, B: ?Sized> IntoCow<'a, B> for Cow<'a, B> where B: ToOwned {
249255
fn into_cow(self) -> Cow<'a, B> {
250256
self
251257
}

0 commit comments

Comments
 (0)