Skip to content

Commit 44500c8

Browse files
committed
Added Self where possible
In this commit, I added `Self` as the return value for implementations that returned their own type as it seems much more readable IMO. Additionally for the implementations of Iterator and IntoIter, I used Self::Item and Self::IntoIter
1 parent 20cbba7 commit 44500c8

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/libcollections/linked_list.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub struct Iter<'a, T:'a> {
6464
// FIXME #19839: deriving is too aggressive on the bounds (T doesn't need to be Clone).
6565
#[stable(feature = "rust1", since = "1.0.0")]
6666
impl<'a, T> Clone for Iter<'a, T> {
67-
fn clone(&self) -> Iter<'a, T> {
67+
fn clone(&self) -> Self {
6868
Iter {
6969
head: self.head.clone(),
7070
tail: self.tail,
@@ -92,12 +92,12 @@ pub struct IntoIter<T> {
9292
/// Rawlink is a type like Option<T> but for holding a raw pointer
9393
impl<T> Rawlink<T> {
9494
/// Like Option::None for Rawlink
95-
fn none() -> Rawlink<T> {
95+
fn none() -> Self {
9696
Rawlink{p: ptr::null_mut()}
9797
}
9898

9999
/// Like Option::Some for Rawlink
100-
fn some(n: &mut T) -> Rawlink<T> {
100+
fn some(n: &mut T) -> Self {
101101
Rawlink{p: n}
102102
}
103103

@@ -122,7 +122,7 @@ impl<T> Rawlink<T> {
122122
}
123123

124124
/// Return the `Rawlink` and replace with `Rawlink::none()`
125-
fn take(&mut self) -> Rawlink<T> {
125+
fn take(&mut self) -> Self {
126126
mem::replace(self, Rawlink::none())
127127
}
128128
}
@@ -138,13 +138,13 @@ impl<'a, T> From<&'a mut Link<T>> for Rawlink<Node<T>> {
138138

139139
impl<T> Clone for Rawlink<T> {
140140
#[inline]
141-
fn clone(&self) -> Rawlink<T> {
141+
fn clone(&self) -> Self {
142142
Rawlink{p: self.p}
143143
}
144144
}
145145

146146
impl<T> Node<T> {
147-
fn new(v: T) -> Node<T> {
147+
fn new(v: T) -> Self {
148148
Node{value: v, next: None, prev: Rawlink::none()}
149149
}
150150

@@ -187,7 +187,7 @@ impl<T> LinkedList<T> {
187187

188188
/// Remove the first Node and return it, or None if the list is empty
189189
#[inline]
190-
fn pop_front_node(&mut self) -> Option<Box<Node<T>>> {
190+
fn pop_front_node(&mut self) -> Link<T> {
191191
self.list_head.take().map(|mut front_node| {
192192
self.length -= 1;
193193
match front_node.next.take() {
@@ -213,7 +213,7 @@ impl<T> LinkedList<T> {
213213

214214
/// Remove the last Node and return it, or None if the list is empty
215215
#[inline]
216-
fn pop_back_node(&mut self) -> Option<Box<Node<T>>> {
216+
fn pop_back_node(&mut self) -> Link<T> {
217217
unsafe {
218218
self.list_tail.resolve_mut().and_then(|tail| {
219219
self.length -= 1;
@@ -230,14 +230,14 @@ impl<T> LinkedList<T> {
230230
#[stable(feature = "rust1", since = "1.0.0")]
231231
impl<T> Default for LinkedList<T> {
232232
#[inline]
233-
fn default() -> LinkedList<T> { LinkedList::new() }
233+
fn default() -> Self { LinkedList::new() }
234234
}
235235

236236
impl<T> LinkedList<T> {
237237
/// Creates an empty `LinkedList`.
238238
#[inline]
239239
#[stable(feature = "rust1", since = "1.0.0")]
240-
pub fn new() -> LinkedList<T> {
240+
pub fn new() -> Self {
241241
LinkedList{list_head: None, list_tail: Rawlink::none(), length: 0}
242242
}
243243

@@ -268,7 +268,7 @@ impl<T> LinkedList<T> {
268268
/// println!("{}", b.len()); // prints 0
269269
/// ```
270270
#[stable(feature = "rust1", since = "1.0.0")]
271-
pub fn append(&mut self, other: &mut LinkedList<T>) {
271+
pub fn append(&mut self, other: &mut Self) {
272272
match unsafe { self.list_tail.resolve_mut() } {
273273
None => {
274274
self.length = other.length;
@@ -597,7 +597,7 @@ impl<T> LinkedList<T> {
597597
/// assert_eq!(splitted.pop_front(), None);
598598
/// ```
599599
#[stable(feature = "rust1", since = "1.0.0")]
600-
pub fn split_off(&mut self, at: usize) -> LinkedList<T> {
600+
pub fn split_off(&mut self, at: usize) -> Self {
601601
let len = self.len();
602602
assert!(at <= len, "Cannot split off at a nonexistent index");
603603
if at == 0 {
@@ -672,7 +672,7 @@ impl<'a, A> Iterator for Iter<'a, A> {
672672
type Item = &'a A;
673673

674674
#[inline]
675-
fn next(&mut self) -> Option<&'a A> {
675+
fn next(&mut self) -> Option<Self::Item> {
676676
if self.nelem == 0 {
677677
return None;
678678
}
@@ -713,7 +713,7 @@ impl<'a, A> ExactSizeIterator for Iter<'a, A> {}
713713
impl<'a, A> Iterator for IterMut<'a, A> {
714714
type Item = &'a mut A;
715715
#[inline]
716-
fn next(&mut self) -> Option<&'a mut A> {
716+
fn next(&mut self) -> Option<Self::Item> {
717717
if self.nelem == 0 {
718718
return None;
719719
}
@@ -843,7 +843,7 @@ impl<A> Iterator for IntoIter<A> {
843843
type Item = A;
844844

845845
#[inline]
846-
fn next(&mut self) -> Option<A> { self.list.pop_front() }
846+
fn next(&mut self) -> Option<Self::Item> { self.list.pop_front() }
847847

848848
#[inline]
849849
fn size_hint(&self) -> (usize, Option<usize>) {
@@ -862,7 +862,7 @@ impl<A> ExactSizeIterator for IntoIter<A> {}
862862

863863
#[stable(feature = "rust1", since = "1.0.0")]
864864
impl<A> FromIterator<A> for LinkedList<A> {
865-
fn from_iter<T: IntoIterator<Item=A>>(iter: T) -> LinkedList<A> {
865+
fn from_iter<T: IntoIterator<Item=A>>(iter: T) -> Self {
866866
let mut ret = LinkedList::new();
867867
ret.extend(iter);
868868
ret
@@ -872,11 +872,11 @@ impl<A> FromIterator<A> for LinkedList<A> {
872872
#[stable(feature = "rust1", since = "1.0.0")]
873873
impl<T> IntoIterator for LinkedList<T> {
874874
type Item = T;
875-
type IntoIter = IntoIter<T>;
875+
type IntoIter = IntoIter<Self::Item>;
876876

877877
/// Consumes the list into an iterator yielding elements by value.
878878
#[inline]
879-
fn into_iter(self) -> IntoIter<T> {
879+
fn into_iter(self) -> Self::IntoIter {
880880
IntoIter{list: self}
881881
}
882882
}
@@ -886,7 +886,7 @@ impl<'a, T> IntoIterator for &'a LinkedList<T> {
886886
type Item = &'a T;
887887
type IntoIter = Iter<'a, T>;
888888

889-
fn into_iter(self) -> Iter<'a, T> {
889+
fn into_iter(self) -> Self::IntoIter {
890890
self.iter()
891891
}
892892
}
@@ -896,7 +896,7 @@ impl<'a, T> IntoIterator for &'a mut LinkedList<T> {
896896
type Item = &'a mut T;
897897
type IntoIter = IterMut<'a, T>;
898898

899-
fn into_iter(mut self) -> IterMut<'a, T> {
899+
fn into_iter(mut self) -> Self::IntoIter {
900900
self.iter_mut()
901901
}
902902
}
@@ -917,7 +917,7 @@ impl<'a, T: 'a + Copy> Extend<&'a T> for LinkedList<T> {
917917

918918
#[stable(feature = "rust1", since = "1.0.0")]
919919
impl<A: PartialEq> PartialEq for LinkedList<A> {
920-
fn eq(&self, other: &LinkedList<A>) -> bool {
920+
fn eq(&self, other: &Self) -> bool {
921921
self.len() == other.len() &&
922922
self.iter().eq(other.iter())
923923
}
@@ -933,7 +933,7 @@ impl<A: Eq> Eq for LinkedList<A> {}
933933

934934
#[stable(feature = "rust1", since = "1.0.0")]
935935
impl<A: PartialOrd> PartialOrd for LinkedList<A> {
936-
fn partial_cmp(&self, other: &LinkedList<A>) -> Option<Ordering> {
936+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
937937
self.iter().partial_cmp(other.iter())
938938
}
939939
}
@@ -948,7 +948,7 @@ impl<A: Ord> Ord for LinkedList<A> {
948948

949949
#[stable(feature = "rust1", since = "1.0.0")]
950950
impl<A: Clone> Clone for LinkedList<A> {
951-
fn clone(&self) -> LinkedList<A> {
951+
fn clone(&self) -> Self {
952952
self.iter().cloned().collect()
953953
}
954954
}

0 commit comments

Comments
 (0)