Skip to content
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

fixed some clippy warnings in libcollections #40541

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions src/libcollections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ impl<'a, T> Hole<'a, T> {
/// Unsafe because index must be within the data slice and not equal to pos.
#[inline]
unsafe fn get(&self, index: usize) -> &T {
debug_assert!(index != self.pos);
debug_assert_ne!(index, self.pos);
debug_assert!(index < self.data.len());
self.data.get_unchecked(index)
}
Expand All @@ -951,7 +951,7 @@ impl<'a, T> Hole<'a, T> {
/// Unsafe because index must be within the data slice and not equal to pos.
#[inline]
unsafe fn move_to(&mut self, index: usize) {
debug_assert!(index != self.pos);
debug_assert_ne!(index, self.pos);
debug_assert!(index < self.data.len());
let index_ptr: *const _ = self.data.get_unchecked(index);
let hole_ptr = self.data.get_unchecked_mut(self.pos);
Expand Down Expand Up @@ -1194,8 +1194,8 @@ impl<T: Ord, I: IntoIterator<Item = T>> SpecExtend<I> for BinaryHeap<T> {
}

impl<T: Ord> SpecExtend<BinaryHeap<T>> for BinaryHeap<T> {
fn spec_extend(&mut self, ref mut other: BinaryHeap<T>) {
self.append(other);
fn spec_extend(&mut self, mut other: BinaryHeap<T>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be &mut other: BinaryHeap<T>? I think you're forcing a copy here.

Copy link
Member

@bluss bluss Mar 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is purely a coding style issue and both versions are equivalent. Rust doesn't implicitly copy things unless they are Copy. (Besides, ref and mut are only applied to the parameter as a local variable, doesn't affect the function's signature.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can further clarify that yes, the BinaryHeap is consumed / moved into the method here. In the old code and new code. It's ultimately dictated by the Extend interface and not something that can be changed.

self.append(&mut other);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl<'a, B: ?Sized> fmt::Debug for Cow<'a, B>
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Borrowed(ref b) => fmt::Debug::fmt(b, f),
Borrowed(b) => fmt::Debug::fmt(b, f),
Owned(ref o) => fmt::Debug::fmt(o, f),
}
}
Expand All @@ -267,7 +267,7 @@ impl<'a, B: ?Sized> fmt::Display for Cow<'a, B>
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Borrowed(ref b) => fmt::Display::fmt(b, f),
Borrowed(b) => fmt::Display::fmt(b, f),
Owned(ref o) => fmt::Display::fmt(o, f),
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/libcollections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl<K, Q: ?Sized> super::Recover<Q> for BTreeMap<K, ()>
}
}

/// An iterator over a BTreeMap's entries.
/// An iterator over a `BTreeMap`'s entries.
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Iter<'a, K: 'a, V: 'a> {
range: Range<'a, K, V>,
Expand All @@ -276,15 +276,15 @@ impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Iter<'a, K, V> {
}
}

/// A mutable iterator over a BTreeMap's entries.
/// A mutable iterator over a `BTreeMap`'s entries.
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Debug)]
pub struct IterMut<'a, K: 'a, V: 'a> {
range: RangeMut<'a, K, V>,
length: usize,
}

/// An owning iterator over a BTreeMap's entries.
/// An owning iterator over a `BTreeMap`'s entries.
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<K, V> {
front: Handle<NodeRef<marker::Owned, K, V, marker::Leaf>, marker::Edge>,
Expand All @@ -303,7 +303,7 @@ impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for IntoIter<K, V> {
}
}

/// An iterator over a BTreeMap's keys.
/// An iterator over a `BTreeMap`'s keys.
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Keys<'a, K: 'a, V: 'a> {
inner: Iter<'a, K, V>,
Expand All @@ -316,7 +316,7 @@ impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Keys<'a, K, V> {
}
}

/// An iterator over a BTreeMap's values.
/// An iterator over a `BTreeMap`'s values.
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Values<'a, K: 'a, V: 'a> {
inner: Iter<'a, K, V>,
Expand All @@ -329,14 +329,14 @@ impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Values<'a, K, V>
}
}

/// A mutable iterator over a BTreeMap's values.
/// A mutable iterator over a `BTreeMap`'s values.
#[stable(feature = "map_values_mut", since = "1.10.0")]
#[derive(Debug)]
pub struct ValuesMut<'a, K: 'a, V: 'a> {
inner: IterMut<'a, K, V>,
}

/// An iterator over a sub-range of BTreeMap's entries.
/// An iterator over a sub-range of `BTreeMap`'s entries.
#[stable(feature = "btree_range", since = "1.17.0")]
pub struct Range<'a, K: 'a, V: 'a> {
front: Handle<NodeRef<marker::Immut<'a>, K, V, marker::Leaf>, marker::Edge>,
Expand All @@ -350,7 +350,7 @@ impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Range<'a, K, V>
}
}

/// A mutable iterator over a sub-range of BTreeMap's entries.
/// A mutable iterator over a sub-range of `BTreeMap`'s entries.
#[stable(feature = "btree_range", since = "1.17.0")]
pub struct RangeMut<'a, K: 'a, V: 'a> {
front: Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge>,
Expand Down Expand Up @@ -685,12 +685,12 @@ impl<K: Ord, V> BTreeMap<K, V> {
#[stable(feature = "btree_append", since = "1.11.0")]
pub fn append(&mut self, other: &mut Self) {
// Do we have to append anything at all?
if other.len() == 0 {
if other.is_empty() {
return;
}

// We can just swap `self` and `other` if `self` is empty.
if self.len() == 0 {
if self.is_empty() {
mem::swap(self, other);
return;
}
Expand Down Expand Up @@ -1894,7 +1894,7 @@ impl<K, V> BTreeMap<K, V> {
/// assert_eq!(keys, [1, 2]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn keys<'a>(&'a self) -> Keys<'a, K, V> {
pub fn keys(&self) -> Keys<K, V> {
Keys { inner: self.iter() }
}

Expand All @@ -1915,7 +1915,7 @@ impl<K, V> BTreeMap<K, V> {
/// assert_eq!(values, ["hello", "goodbye"]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn values<'a>(&'a self) -> Values<'a, K, V> {
pub fn values(&self) -> Values<K, V> {
Values { inner: self.iter() }
}

Expand Down Expand Up @@ -2354,8 +2354,8 @@ enum UnderflowResult<'a, K, V> {
Stole(NodeRef<marker::Mut<'a>, K, V, marker::Internal>),
}

fn handle_underfull_node<'a, K, V>(node: NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>)
-> UnderflowResult<'a, K, V> {
fn handle_underfull_node<K, V>(node: NodeRef<marker::Mut, K, V, marker::LeafOrInternal>)
-> UnderflowResult<K, V> {
let parent = if let Ok(parent) = node.ascend() {
parent
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/libcollections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
}

/// Temporarily takes out another, immutable reference to the same node.
fn reborrow<'a>(&'a self) -> NodeRef<marker::Immut<'a>, K, V, Type> {
fn reborrow(&self) -> NodeRef<marker::Immut, K, V, Type> {
NodeRef {
height: self.height,
node: self.node,
Expand Down Expand Up @@ -964,7 +964,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
fn insert_fit(&mut self, key: K, val: V, edge: Root<K, V>) {
// Necessary for correctness, but in an internal module
debug_assert!(self.node.len() < CAPACITY);
debug_assert!(edge.height == self.node.height - 1);
debug_assert_eq!(edge.height, self.node.height - 1);

unsafe {
// This cast is a lie, but it allows us to reuse the key/value insertion logic.
Expand Down Expand Up @@ -992,7 +992,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
-> InsertResult<'a, K, V, marker::Internal> {

// Necessary for correctness, but this is an internal module
debug_assert!(edge.height == self.node.height - 1);
debug_assert_eq!(edge.height, self.node.height - 1);

if self.node.len() < CAPACITY {
self.insert_fit(key, val, edge);
Expand Down Expand Up @@ -1488,8 +1488,8 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>, ma
let right_new_len = left_node.len() - left_new_len;
let mut right_node = right.reborrow_mut();

debug_assert!(right_node.len() == 0);
debug_assert!(left_node.height == right_node.height);
debug_assert_eq!(right_node.len(), 0);
debug_assert_eq!(left_node.height, right_node.height);

let left_kv = left_node.reborrow_mut().into_kv_pointers_mut();
let right_kv = right_node.reborrow_mut().into_kv_pointers_mut();
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> {
fn next(&mut self) -> Option<&'a T> {
loop {
let o_cmp = match (self.a.peek(), self.b.peek()) {
(None, _) => None,
(None, _) |
(_, None) => None,
(Some(a1), Some(b1)) => Some(a1.cmp(b1)),
};
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/enum_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl<E: CLike> BitXor for EnumSet<E> {
}
}

/// An iterator over an EnumSet
/// An iterator over an `EnumSet`
pub struct Iter<E> {
index: usize,
bits: usize,
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

//! Collection types.
//!
//! See [std::collections](../std/collections/index.html) for a detailed discussion of
//! See [`std::collections`](../std/collections/index.html) for a detailed discussion of
//! collections in Rust.

#![crate_name = "collections"]
Expand Down
12 changes: 6 additions & 6 deletions src/libcollections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub struct IterMut<'a, T: 'a> {
impl<'a, T: 'a + fmt::Debug> fmt::Debug for IterMut<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("IterMut")
.field(self.clone())
.field(self)
.finish()
}
}
Expand All @@ -111,7 +111,7 @@ pub struct IntoIter<T> {
impl<T: fmt::Debug> fmt::Debug for IntoIter<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("IntoIter")
.field(self.clone())
.field(self)
.finish()
}
}
Expand Down Expand Up @@ -1020,8 +1020,8 @@ impl<I: IntoIterator> SpecExtend<I> for LinkedList<I::Item> {
}

impl<T> SpecExtend<LinkedList<T>> for LinkedList<T> {
fn spec_extend(&mut self, ref mut other: LinkedList<T>) {
self.append(other);
fn spec_extend(&mut self, mut other: LinkedList<T>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Member

@bluss bluss Mar 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust doesn't implicitly copy things unless they are Copy, and heap-allocating collections are never Copy. Typical types that implement Copy are i32 and &str. Besides, ref and mut are only applied to the parameter as a local variable, doesn't affect the function's signature.

self.append(&mut other);
}
}

Expand Down Expand Up @@ -1110,7 +1110,7 @@ pub struct FrontPlace<'a, T: 'a> {
impl<'a, T: 'a + fmt::Debug> fmt::Debug for FrontPlace<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("FrontPlace")
.field(self.clone())
.field(self)
.finish()
}
}
Expand Down Expand Up @@ -1165,7 +1165,7 @@ pub struct BackPlace<'a, T: 'a> {
impl<'a, T: 'a + fmt::Debug> fmt::Debug for BackPlace<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("BackPlace")
.field(self.clone())
.field(self)
.finish()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use core::ops::{RangeFull, Range, RangeTo, RangeFrom, RangeInclusive, RangeToInclusive};
use Bound::{self, Excluded, Included, Unbounded};

/// **RangeArgument** is implemented by Rust's built-in range types, produced
/// **`RangeArgument`** is implemented by Rust's built-in range types, produced
/// by range syntax like `..`, `a..`, `..b` or `c..d`.
pub trait RangeArgument<T: ?Sized> {
/// Start index bound.
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ unsafe fn merge<T, F>(v: &mut [T], mid: usize, buf: *mut T, is_less: &mut F)
}
}

/// This merge sort borrows some (but not all) ideas from TimSort, which is described in detail
/// This merge sort borrows some (but not all) ideas from `TimSort`, which is described in detail
/// [here](http://svn.python.org/projects/python/trunk/Objects/listsort.txt).
///
/// The algorithm identifies strictly descending and non-descending subsequences, which are called
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1702,7 +1702,7 @@ impl str {
fn map_uppercase_sigma(from: &str, i: usize, to: &mut String) {
// See http://www.unicode.org/versions/Unicode7.0.0/ch03.pdf#G33992
// for the definition of `Final_Sigma`.
debug_assert!('Σ'.len_utf8() == 2);
debug_assert_eq!('Σ'.len_utf8(), 2);
let is_word_final = case_ignoreable_then_cased(from[..i].chars().rev()) &&
!case_ignoreable_then_cased(from[i + 2..].chars());
to.push_str(if is_word_final { "ς" } else { "σ" });
Expand Down Expand Up @@ -1749,7 +1749,7 @@ impl str {
pub fn to_uppercase(&self) -> String {
let mut s = String::with_capacity(self.len());
s.extend(self.chars().flat_map(|c| c.to_uppercase()));
return s;
s
}

/// Escapes each char in `s` with `char::escape_debug`.
Expand Down
12 changes: 6 additions & 6 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ impl String {
/// assert_eq!("Hello �World", output);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> Cow<'a, str> {
pub fn from_utf8_lossy(v: &[u8]) -> Cow<str> {
let mut i;
match str::from_utf8(v) {
Ok(s) => return Cow::Borrowed(s),
Expand Down Expand Up @@ -591,9 +591,9 @@ impl String {
}
3 => {
match (byte, safe_get(v, i, total)) {
(0xE0, 0xA0...0xBF) => (),
(0xE1...0xEC, 0x80...0xBF) => (),
(0xED, 0x80...0x9F) => (),
(0xE0, 0xA0...0xBF) |
(0xE1...0xEC, 0x80...0xBF) |
(0xED, 0x80...0x9F) |
(0xEE...0xEF, 0x80...0xBF) => (),
_ => {
error!();
Expand All @@ -609,8 +609,8 @@ impl String {
}
4 => {
match (byte, safe_get(v, i, total)) {
(0xF0, 0x90...0xBF) => (),
(0xF1...0xF3, 0x80...0xBF) => (),
(0xF0, 0x90...0xBF) |
(0xF1...0xF3, 0x80...0xBF) |
(0xF4, 0x80...0x8F) => (),
_ => {
error!();
Expand Down
Loading