Skip to content

Added Self where possible in LinkedList (updated) #30893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/libcollections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub struct Iter<'a, T: 'a> {
// FIXME #19839: deriving is too aggressive on the bounds (T doesn't need to be Clone).
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Clone for Iter<'a, T> {
fn clone(&self) -> Iter<'a, T> {
fn clone(&self) -> Self {
Iter {
head: self.head.clone(),
tail: self.tail,
Expand Down Expand Up @@ -92,12 +92,12 @@ pub struct IntoIter<T> {
/// Rawlink is a type like Option<T> but for holding a raw pointer
impl<T> Rawlink<T> {
/// Like Option::None for Rawlink
fn none() -> Rawlink<T> {
fn none() -> Self {
Rawlink { p: None }
}

/// Like Option::Some for Rawlink
fn some(n: &mut T) -> Rawlink<T> {
fn some(n: &mut T) -> Self {
unsafe { Rawlink { p: Some(Shared::new(n)) } }
}

Expand All @@ -122,7 +122,7 @@ impl<T> Rawlink<T> {
}

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

impl<T> Clone for Rawlink<T> {
#[inline]
fn clone(&self) -> Rawlink<T> {
fn clone(&self) -> Self {
Rawlink { p: self.p }
}
}

impl<T> Node<T> {
fn new(v: T) -> Node<T> {
fn new(v: T) -> Self {
Node {
value: v,
next: None,
Expand Down Expand Up @@ -191,7 +191,7 @@ impl<T> LinkedList<T> {

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

/// Remove the last Node and return it, or None if the list is empty
#[inline]
fn pop_back_node(&mut self) -> Option<Box<Node<T>>> {
fn pop_back_node(&mut self) -> Link<T> {
unsafe {
self.list_tail.resolve_mut().and_then(|tail| {
self.length -= 1;
Expand All @@ -234,7 +234,7 @@ impl<T> LinkedList<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for LinkedList<T> {
#[inline]
fn default() -> LinkedList<T> {
fn default() -> Self {
LinkedList::new()
}
}
Expand All @@ -243,7 +243,7 @@ impl<T> LinkedList<T> {
/// Creates an empty `LinkedList`.
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> LinkedList<T> {
pub fn new() -> Self {
LinkedList {
list_head: None,
list_tail: Rawlink::none(),
Expand Down Expand Up @@ -682,7 +682,7 @@ impl<'a, A> Iterator for Iter<'a, A> {
type Item = &'a A;

#[inline]
fn next(&mut self) -> Option<&'a A> {
fn next(&mut self) -> Option<Self::Item> {
if self.nelem == 0 {
return None;
}
Expand Down Expand Up @@ -723,7 +723,7 @@ impl<'a, A> ExactSizeIterator for Iter<'a, A> {}
impl<'a, A> Iterator for IterMut<'a, A> {
type Item = &'a mut A;
#[inline]
fn next(&mut self) -> Option<&'a mut A> {
fn next(&mut self) -> Option<Self::Item> {
if self.nelem == 0 {
return None;
}
Expand Down Expand Up @@ -853,7 +853,7 @@ impl<A> Iterator for IntoIter<A> {
type Item = A;

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

Expand All @@ -876,7 +876,7 @@ impl<A> ExactSizeIterator for IntoIter<A> {}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A> FromIterator<A> for LinkedList<A> {
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> LinkedList<A> {
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self {
let mut ret = LinkedList::new();
ret.extend(iter);
ret
Expand All @@ -886,11 +886,11 @@ impl<A> FromIterator<A> for LinkedList<A> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> IntoIterator for LinkedList<T> {
type Item = T;
type IntoIter = IntoIter<T>;
type IntoIter = IntoIter<Self::Item>;

/// Consumes the list into an iterator yielding elements by value.
#[inline]
fn into_iter(self) -> IntoIter<T> {
fn into_iter(self) -> Self::IntoIter {
IntoIter { list: self }
}
}
Expand All @@ -900,7 +900,7 @@ impl<'a, T> IntoIterator for &'a LinkedList<T> {
type Item = &'a T;
type IntoIter = Iter<'a, T>;

fn into_iter(self) -> Iter<'a, T> {
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}
Expand Down Expand Up @@ -933,7 +933,7 @@ impl<'a, T: 'a + Copy> Extend<&'a T> for LinkedList<T> {

#[stable(feature = "rust1", since = "1.0.0")]
impl<A: PartialEq> PartialEq for LinkedList<A> {
fn eq(&self, other: &LinkedList<A>) -> bool {
fn eq(&self, other: &Self) -> bool {
self.len() == other.len() && self.iter().eq(other.iter())
}

Expand All @@ -947,7 +947,7 @@ impl<A: Eq> Eq for LinkedList<A> {}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A: PartialOrd> PartialOrd for LinkedList<A> {
fn partial_cmp(&self, other: &LinkedList<A>) -> Option<Ordering> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.iter().partial_cmp(other.iter())
}
}
Expand All @@ -962,7 +962,7 @@ impl<A: Ord> Ord for LinkedList<A> {

#[stable(feature = "rust1", since = "1.0.0")]
impl<A: Clone> Clone for LinkedList<A> {
fn clone(&self) -> LinkedList<A> {
fn clone(&self) -> Self {
self.iter().cloned().collect()
}
}
Expand Down