Skip to content

Commit 70deac1

Browse files
committed
fixed some clippy warnings in libcollections
1 parent 6f10e2f commit 70deac1

File tree

14 files changed

+119
-126
lines changed

14 files changed

+119
-126
lines changed

src/libcollections/binary_heap.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ impl<'a, T> Hole<'a, T> {
941941
/// Unsafe because index must be within the data slice and not equal to pos.
942942
#[inline]
943943
unsafe fn get(&self, index: usize) -> &T {
944-
debug_assert!(index != self.pos);
944+
debug_assert_ne!(index, self.pos);
945945
debug_assert!(index < self.data.len());
946946
self.data.get_unchecked(index)
947947
}
@@ -951,7 +951,7 @@ impl<'a, T> Hole<'a, T> {
951951
/// Unsafe because index must be within the data slice and not equal to pos.
952952
#[inline]
953953
unsafe fn move_to(&mut self, index: usize) {
954-
debug_assert!(index != self.pos);
954+
debug_assert_ne!(index, self.pos);
955955
debug_assert!(index < self.data.len());
956956
let index_ptr: *const _ = self.data.get_unchecked(index);
957957
let hole_ptr = self.data.get_unchecked_mut(self.pos);
@@ -1194,8 +1194,8 @@ impl<T: Ord, I: IntoIterator<Item = T>> SpecExtend<I> for BinaryHeap<T> {
11941194
}
11951195

11961196
impl<T: Ord> SpecExtend<BinaryHeap<T>> for BinaryHeap<T> {
1197-
fn spec_extend(&mut self, ref mut other: BinaryHeap<T>) {
1198-
self.append(other);
1197+
fn spec_extend(&mut self, mut other: BinaryHeap<T>) {
1198+
self.append(&mut other);
11991199
}
12001200
}
12011201

src/libcollections/borrow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl<'a, B: ?Sized> fmt::Debug for Cow<'a, B>
254254
{
255255
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
256256
match *self {
257-
Borrowed(ref b) => fmt::Debug::fmt(b, f),
257+
Borrowed(b) => fmt::Debug::fmt(b, f),
258258
Owned(ref o) => fmt::Debug::fmt(o, f),
259259
}
260260
}
@@ -267,7 +267,7 @@ impl<'a, B: ?Sized> fmt::Display for Cow<'a, B>
267267
{
268268
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
269269
match *self {
270-
Borrowed(ref b) => fmt::Display::fmt(b, f),
270+
Borrowed(b) => fmt::Display::fmt(b, f),
271271
Owned(ref o) => fmt::Display::fmt(o, f),
272272
}
273273
}

src/libcollections/btree/map.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub struct BTreeMap<K, V> {
141141
unsafe impl<#[may_dangle] K, #[may_dangle] V> Drop for BTreeMap<K, V> {
142142
fn drop(&mut self) {
143143
unsafe {
144-
for _ in ptr::read(self).into_iter() {
144+
for _ in ptr::read(self) {
145145
}
146146
}
147147
}
@@ -263,7 +263,7 @@ impl<K, Q: ?Sized> super::Recover<Q> for BTreeMap<K, ()>
263263
}
264264
}
265265

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

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

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

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

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

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

340-
/// An iterator over a sub-range of BTreeMap's entries.
340+
/// An iterator over a sub-range of `BTreeMap`'s entries.
341341
pub struct Range<'a, K: 'a, V: 'a> {
342342
front: Handle<NodeRef<marker::Immut<'a>, K, V, marker::Leaf>, marker::Edge>,
343343
back: Handle<NodeRef<marker::Immut<'a>, K, V, marker::Leaf>, marker::Edge>,
@@ -350,7 +350,7 @@ impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Range<'a, K, V>
350350
}
351351
}
352352

353-
/// A mutable iterator over a sub-range of BTreeMap's entries.
353+
/// A mutable iterator over a sub-range of `BTreeMap`'s entries.
354354
pub struct RangeMut<'a, K: 'a, V: 'a> {
355355
front: Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge>,
356356
back: Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge>,
@@ -684,12 +684,12 @@ impl<K: Ord, V> BTreeMap<K, V> {
684684
#[stable(feature = "btree_append", since = "1.11.0")]
685685
pub fn append(&mut self, other: &mut Self) {
686686
// Do we have to append anything at all?
687-
if other.len() == 0 {
687+
if other.is_empty() {
688688
return;
689689
}
690690

691691
// We can just swap `self` and `other` if `self` is empty.
692-
if self.len() == 0 {
692+
if self.is_empty() {
693693
mem::swap(self, other);
694694
return;
695695
}
@@ -1901,7 +1901,7 @@ impl<K, V> BTreeMap<K, V> {
19011901
/// assert_eq!(keys, [1, 2]);
19021902
/// ```
19031903
#[stable(feature = "rust1", since = "1.0.0")]
1904-
pub fn keys<'a>(&'a self) -> Keys<'a, K, V> {
1904+
pub fn keys(&self) -> Keys<K, V> {
19051905
Keys { inner: self.iter() }
19061906
}
19071907

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

@@ -2361,8 +2361,8 @@ enum UnderflowResult<'a, K, V> {
23612361
Stole(NodeRef<marker::Mut<'a>, K, V, marker::Internal>),
23622362
}
23632363

2364-
fn handle_underfull_node<'a, K, V>(node: NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>)
2365-
-> UnderflowResult<'a, K, V> {
2364+
fn handle_underfull_node<K, V>(node: NodeRef<marker::Mut, K, V, marker::LeafOrInternal>)
2365+
-> UnderflowResult<K, V> {
23662366
let parent = if let Ok(parent) = node.ascend() {
23672367
parent
23682368
} else {

src/libcollections/btree/node.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
347347
}
348348

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

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

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

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

1491-
debug_assert!(right_node.len() == 0);
1492-
debug_assert!(left_node.height == right_node.height);
1491+
debug_assert_eq!(right_node.len(), 0);
1492+
debug_assert_eq!(left_node.height, right_node.height);
14931493

14941494
let left_kv = left_node.reborrow_mut().into_kv_pointers_mut();
14951495
let right_kv = right_node.reborrow_mut().into_kv_pointers_mut();

src/libcollections/btree/set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> {
10561056
fn next(&mut self) -> Option<&'a T> {
10571057
loop {
10581058
let o_cmp = match (self.a.peek(), self.b.peek()) {
1059-
(None, _) => None,
1059+
(None, _) |
10601060
(_, None) => None,
10611061
(Some(a1), Some(b1)) => Some(a1.cmp(b1)),
10621062
};

src/libcollections/enum_set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl<E: CLike> BitXor for EnumSet<E> {
215215
}
216216
}
217217

218-
/// An iterator over an EnumSet
218+
/// An iterator over an `EnumSet`
219219
pub struct Iter<E> {
220220
index: usize,
221221
bits: usize,

src/libcollections/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
//! Collection types.
1212
//!
13-
//! See [std::collections](../std/collections/index.html) for a detailed discussion of
13+
//! See [`std::collections`](../std/collections/index.html) for a detailed discussion of
1414
//! collections in Rust.
1515
1616
#![crate_name = "collections"]

src/libcollections/linked_list.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub struct IterMut<'a, T: 'a> {
9595
impl<'a, T: 'a + fmt::Debug> fmt::Debug for IterMut<'a, T> {
9696
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9797
f.debug_tuple("IterMut")
98-
.field(self.clone())
98+
.field(self)
9999
.finish()
100100
}
101101
}
@@ -111,7 +111,7 @@ pub struct IntoIter<T> {
111111
impl<T: fmt::Debug> fmt::Debug for IntoIter<T> {
112112
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
113113
f.debug_tuple("IntoIter")
114-
.field(self.clone())
114+
.field(self)
115115
.finish()
116116
}
117117
}
@@ -1020,8 +1020,8 @@ impl<I: IntoIterator> SpecExtend<I> for LinkedList<I::Item> {
10201020
}
10211021

10221022
impl<T> SpecExtend<LinkedList<T>> for LinkedList<T> {
1023-
fn spec_extend(&mut self, ref mut other: LinkedList<T>) {
1024-
self.append(other);
1023+
fn spec_extend(&mut self, mut other: LinkedList<T>) {
1024+
self.append(&mut other);
10251025
}
10261026
}
10271027

@@ -1110,7 +1110,7 @@ pub struct FrontPlace<'a, T: 'a> {
11101110
impl<'a, T: 'a + fmt::Debug> fmt::Debug for FrontPlace<'a, T> {
11111111
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11121112
f.debug_tuple("FrontPlace")
1113-
.field(self.clone())
1113+
.field(self)
11141114
.finish()
11151115
}
11161116
}
@@ -1165,7 +1165,7 @@ pub struct BackPlace<'a, T: 'a> {
11651165
impl<'a, T: 'a + fmt::Debug> fmt::Debug for BackPlace<'a, T> {
11661166
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11671167
f.debug_tuple("BackPlace")
1168-
.field(self.clone())
1168+
.field(self)
11691169
.finish()
11701170
}
11711171
}

src/libcollections/range.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use core::ops::{RangeFull, Range, RangeTo, RangeFrom, RangeInclusive, RangeToInclusive};
1818
use Bound::{self, Excluded, Included, Unbounded};
1919

20-
/// **RangeArgument** is implemented by Rust's built-in range types, produced
20+
/// **`RangeArgument`** is implemented by Rust's built-in range types, produced
2121
/// by range syntax like `..`, `a..`, `..b` or `c..d`.
2222
pub trait RangeArgument<T: ?Sized> {
2323
/// Start index bound

src/libcollections/slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,7 @@ unsafe fn merge<T, F>(v: &mut [T], mid: usize, buf: *mut T, is_less: &mut F)
15381538
}
15391539
}
15401540

1541-
/// This merge sort borrows some (but not all) ideas from TimSort, which is described in detail
1541+
/// This merge sort borrows some (but not all) ideas from `TimSort`, which is described in detail
15421542
/// [here](http://svn.python.org/projects/python/trunk/Objects/listsort.txt).
15431543
///
15441544
/// The algorithm identifies strictly descending and non-descending subsequences, which are called

src/libcollections/str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,7 @@ impl str {
17021702
fn map_uppercase_sigma(from: &str, i: usize, to: &mut String) {
17031703
// See http://www.unicode.org/versions/Unicode7.0.0/ch03.pdf#G33992
17041704
// for the definition of `Final_Sigma`.
1705-
debug_assert!('Σ'.len_utf8() == 2);
1705+
debug_assert_eq!('Σ'.len_utf8(), 2);
17061706
let is_word_final = case_ignoreable_then_cased(from[..i].chars().rev()) &&
17071707
!case_ignoreable_then_cased(from[i + 2..].chars());
17081708
to.push_str(if is_word_final { "ς" } else { "σ" });
@@ -1749,7 +1749,7 @@ impl str {
17491749
pub fn to_uppercase(&self) -> String {
17501750
let mut s = String::with_capacity(self.len());
17511751
s.extend(self.chars().flat_map(|c| c.to_uppercase()));
1752-
return s;
1752+
s
17531753
}
17541754

17551755
/// Escapes each char in `s` with `char::escape_debug`.

src/libcollections/string.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ impl String {
533533
/// assert_eq!("Hello �World", output);
534534
/// ```
535535
#[stable(feature = "rust1", since = "1.0.0")]
536-
pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> Cow<'a, str> {
536+
pub fn from_utf8_lossy(v: &[u8]) -> Cow<str> {
537537
let mut i;
538538
match str::from_utf8(v) {
539539
Ok(s) => return Cow::Borrowed(s),
@@ -591,9 +591,9 @@ impl String {
591591
}
592592
3 => {
593593
match (byte, safe_get(v, i, total)) {
594-
(0xE0, 0xA0...0xBF) => (),
595-
(0xE1...0xEC, 0x80...0xBF) => (),
596-
(0xED, 0x80...0x9F) => (),
594+
(0xE0, 0xA0...0xBF) |
595+
(0xE1...0xEC, 0x80...0xBF) |
596+
(0xED, 0x80...0x9F) |
597597
(0xEE...0xEF, 0x80...0xBF) => (),
598598
_ => {
599599
error!();
@@ -609,8 +609,8 @@ impl String {
609609
}
610610
4 => {
611611
match (byte, safe_get(v, i, total)) {
612-
(0xF0, 0x90...0xBF) => (),
613-
(0xF1...0xF3, 0x80...0xBF) => (),
612+
(0xF0, 0x90...0xBF) |
613+
(0xF1...0xF3, 0x80...0xBF) |
614614
(0xF4, 0x80...0x8F) => (),
615615
_ => {
616616
error!();

0 commit comments

Comments
 (0)