From 70deac1e0084011c8b908193bf5109872fe4990b Mon Sep 17 00:00:00 2001 From: Andre Bogus Date: Wed, 15 Mar 2017 07:24:43 +0100 Subject: [PATCH 01/19] fixed some clippy warnings in libcollections --- src/libcollections/binary_heap.rs | 8 +-- src/libcollections/borrow.rs | 4 +- src/libcollections/btree/map.rs | 30 ++++---- src/libcollections/btree/node.rs | 10 +-- src/libcollections/btree/set.rs | 2 +- src/libcollections/enum_set.rs | 2 +- src/libcollections/lib.rs | 2 +- src/libcollections/linked_list.rs | 12 ++-- src/libcollections/range.rs | 2 +- src/libcollections/slice.rs | 2 +- src/libcollections/str.rs | 4 +- src/libcollections/string.rs | 12 ++-- src/libcollections/vec.rs | 44 ++++++------ src/libcollections/vec_deque.rs | 111 +++++++++++++++--------------- 14 files changed, 119 insertions(+), 126 deletions(-) diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index a5a2f70492dc9..92f6374d1b67d 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -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) } @@ -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); @@ -1194,8 +1194,8 @@ impl> SpecExtend for BinaryHeap { } impl SpecExtend> for BinaryHeap { - fn spec_extend(&mut self, ref mut other: BinaryHeap) { - self.append(other); + fn spec_extend(&mut self, mut other: BinaryHeap) { + self.append(&mut other); } } diff --git a/src/libcollections/borrow.rs b/src/libcollections/borrow.rs index 65056121f05a0..d625a94fe072d 100644 --- a/src/libcollections/borrow.rs +++ b/src/libcollections/borrow.rs @@ -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), } } @@ -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), } } diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 7218d15ded5f8..b2dbe8ba17b61 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -141,7 +141,7 @@ pub struct BTreeMap { unsafe impl<#[may_dangle] K, #[may_dangle] V> Drop for BTreeMap { fn drop(&mut self) { unsafe { - for _ in ptr::read(self).into_iter() { + for _ in ptr::read(self) { } } } @@ -263,7 +263,7 @@ impl super::Recover for BTreeMap } } -/// 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>, @@ -277,7 +277,7 @@ 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> { @@ -285,7 +285,7 @@ pub struct IterMut<'a, K: 'a, V: 'a> { 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 { front: Handle, marker::Edge>, @@ -304,7 +304,7 @@ impl fmt::Debug for IntoIter { } } -/// 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>, @@ -317,7 +317,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>, @@ -330,14 +330,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. pub struct Range<'a, K: 'a, V: 'a> { front: Handle, K, V, marker::Leaf>, marker::Edge>, back: Handle, 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> } } -/// A mutable iterator over a sub-range of BTreeMap's entries. +/// A mutable iterator over a sub-range of `BTreeMap`'s entries. pub struct RangeMut<'a, K: 'a, V: 'a> { front: Handle, K, V, marker::Leaf>, marker::Edge>, back: Handle, K, V, marker::Leaf>, marker::Edge>, @@ -684,12 +684,12 @@ impl BTreeMap { #[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; } @@ -1901,7 +1901,7 @@ impl BTreeMap { /// 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 { Keys { inner: self.iter() } } @@ -1922,7 +1922,7 @@ impl BTreeMap { /// 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 { Values { inner: self.iter() } } @@ -2361,8 +2361,8 @@ enum UnderflowResult<'a, K, V> { Stole(NodeRef, K, V, marker::Internal>), } -fn handle_underfull_node<'a, K, V>(node: NodeRef, K, V, marker::LeafOrInternal>) - -> UnderflowResult<'a, K, V> { +fn handle_underfull_node(node: NodeRef) + -> UnderflowResult { let parent = if let Ok(parent) = node.ascend() { parent } else { diff --git a/src/libcollections/btree/node.rs b/src/libcollections/btree/node.rs index e9bc29118d508..e4cee815315fc 100644 --- a/src/libcollections/btree/node.rs +++ b/src/libcollections/btree/node.rs @@ -347,7 +347,7 @@ impl NodeRef { } /// Temporarily takes out another, immutable reference to the same node. - fn reborrow<'a>(&'a self) -> NodeRef, K, V, Type> { + fn reborrow(&self) -> NodeRef { NodeRef { height: self.height, node: self.node, @@ -964,7 +964,7 @@ impl<'a, K, V> Handle, K, V, marker::Internal>, marker:: fn insert_fit(&mut self, key: K, val: V, edge: Root) { // 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. @@ -992,7 +992,7 @@ impl<'a, K, V> Handle, 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); @@ -1488,8 +1488,8 @@ impl<'a, K, V> Handle, 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(); diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index e3c990c80decf..3d1f6c4dd1398 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -1056,7 +1056,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)), }; diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index 602e874aaeec0..18df904c0f6b3 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -215,7 +215,7 @@ impl BitXor for EnumSet { } } -/// An iterator over an EnumSet +/// An iterator over an `EnumSet` pub struct Iter { index: usize, bits: usize, diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index f88bdd0ecf382..f0cc60f565fbb 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -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"] diff --git a/src/libcollections/linked_list.rs b/src/libcollections/linked_list.rs index d4f77d625b361..0ac27cc33b4a4 100644 --- a/src/libcollections/linked_list.rs +++ b/src/libcollections/linked_list.rs @@ -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() } } @@ -111,7 +111,7 @@ pub struct IntoIter { impl fmt::Debug for IntoIter { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_tuple("IntoIter") - .field(self.clone()) + .field(self) .finish() } } @@ -1020,8 +1020,8 @@ impl SpecExtend for LinkedList { } impl SpecExtend> for LinkedList { - fn spec_extend(&mut self, ref mut other: LinkedList) { - self.append(other); + fn spec_extend(&mut self, mut other: LinkedList) { + self.append(&mut other); } } @@ -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() } } @@ -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() } } diff --git a/src/libcollections/range.rs b/src/libcollections/range.rs index e4b94a1d70ee4..2e367d1c54cbc 100644 --- a/src/libcollections/range.rs +++ b/src/libcollections/range.rs @@ -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 { /// Start index bound diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 2ea953df87357..31fbf36862799 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -1538,7 +1538,7 @@ unsafe fn merge(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 diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index e27c45773441a..d6295a13ac861 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -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 { "σ" }); @@ -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`. diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 43323676ab459..972b9720282c4 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -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 { let mut i; match str::from_utf8(v) { Ok(s) => return Cow::Borrowed(s), @@ -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!(); @@ -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!(); diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index d38c9f6e1cf80..aba37d30e1459 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -2011,21 +2011,19 @@ impl Iterator for IntoIter { unsafe { if self.ptr as *const _ == self.end { None + } else if mem::size_of::() == 0 { + // purposefully don't use 'ptr.offset' because for + // vectors with 0-size elements this would return the + // same pointer. + self.ptr = arith_offset(self.ptr as *const i8, 1) as *mut T; + + // Use a non-null pointer value + Some(ptr::read(EMPTY as *mut T)) } else { - if mem::size_of::() == 0 { - // purposefully don't use 'ptr.offset' because for - // vectors with 0-size elements this would return the - // same pointer. - self.ptr = arith_offset(self.ptr as *const i8, 1) as *mut T; - - // Use a non-null pointer value - Some(ptr::read(EMPTY as *mut T)) - } else { - let old = self.ptr; - self.ptr = self.ptr.offset(1); - - Some(ptr::read(old)) - } + let old = self.ptr; + self.ptr = self.ptr.offset(1); + + Some(ptr::read(old)) } } } @@ -2056,18 +2054,16 @@ impl DoubleEndedIterator for IntoIter { unsafe { if self.end == self.ptr { None - } else { - if mem::size_of::() == 0 { - // See above for why 'ptr.offset' isn't used - self.end = arith_offset(self.end as *const i8, -1) as *mut T; + } else if mem::size_of::() == 0 { + // See above for why 'ptr.offset' isn't used + self.end = arith_offset(self.end as *const i8, -1) as *mut T; - // Use a non-null pointer value - Some(ptr::read(EMPTY as *mut T)) - } else { - self.end = self.end.offset(-1); + // Use a non-null pointer value + Some(ptr::read(EMPTY as *mut T)) + } else { + self.end = self.end.offset(-1); - Some(ptr::read(self.end)) - } + Some(ptr::read(self.end)) } } } diff --git a/src/libcollections/vec_deque.rs b/src/libcollections/vec_deque.rs index 1985be7f901c6..074fdcfb9bd51 100644 --- a/src/libcollections/vec_deque.rs +++ b/src/libcollections/vec_deque.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! VecDeque is a double-ended queue, which is implemented with the help of a +//! `VecDeque` is a double-ended queue, which is implemented with the help of a //! growing ring buffer. //! //! This queue has `O(1)` amortized inserts and removals from both ends of the @@ -357,7 +357,7 @@ impl VecDeque { } debug_assert!(self.head < self.cap()); debug_assert!(self.tail < self.cap()); - debug_assert!(self.cap().count_ones() == 1); + debug_assert_eq!(self.cap().count_ones(), 1); } } @@ -631,7 +631,7 @@ impl VecDeque { debug_assert!(self.head < self.cap()); debug_assert!(self.tail < self.cap()); - debug_assert!(self.cap().count_ones() == 1); + debug_assert_eq!(self.cap().count_ones(), 1); } } @@ -1614,7 +1614,7 @@ impl VecDeque { } } - return elem; + elem } /// Splits the collection into two at the given index. @@ -1847,7 +1847,7 @@ fn wrap_index(index: usize, size: usize) -> usize { index & (size - 1) } -/// Returns the two slices that cover the VecDeque's valid range +/// Returns the two slices that cover the `VecDeque`'s valid range trait RingSlices: Sized { fn slice(self, from: usize, to: usize) -> Self; fn split_at(self, i: usize) -> (Self, Self); @@ -1983,7 +1983,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() } } @@ -2047,7 +2047,7 @@ impl<'a, T> ExactSizeIterator for IterMut<'a, T> { #[unstable(feature = "fused", issue = "35602")] impl<'a, T> FusedIterator for IterMut<'a, T> {} -/// A by-value VecDeque iterator +/// A by-value `VecDeque` iterator #[derive(Clone)] #[stable(feature = "rust1", since = "1.0.0")] pub struct IntoIter { @@ -2058,7 +2058,7 @@ pub struct IntoIter { impl fmt::Debug for IntoIter { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_tuple("IntoIter") - .field(&self.clone()) + .field(&self) .finish() } } @@ -2097,7 +2097,7 @@ impl ExactSizeIterator for IntoIter { #[unstable(feature = "fused", issue = "35602")] impl FusedIterator for IntoIter {} -/// A draining VecDeque iterator +/// A draining `VecDeque` iterator #[stable(feature = "drain", since = "1.6.0")] pub struct Drain<'a, T: 'a> { after_tail: usize, @@ -2110,7 +2110,7 @@ pub struct Drain<'a, T: 'a> { impl<'a, T: 'a + fmt::Debug> fmt::Debug for Drain<'a, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_tuple("Drain") - .field(&self.clone()) + .field(&self) .finish() } } @@ -2426,57 +2426,54 @@ impl From> for Vec { // Need to move the ring to the front of the buffer, as vec will expect this. if other.is_contiguous() { ptr::copy(buf.offset(tail as isize), buf, len); - } else { - if (tail - head) >= cmp::min((cap - tail), head) { - // There is enough free space in the centre for the shortest block so we can - // do this in at most three copy moves. - if (cap - tail) > head { - // right hand block is the long one; move that enough for the left - ptr::copy(buf.offset(tail as isize), - buf.offset((tail - head) as isize), - cap - tail); - // copy left in the end - ptr::copy(buf, buf.offset((cap - head) as isize), head); - // shift the new thing to the start - ptr::copy(buf.offset((tail - head) as isize), buf, len); - } else { - // left hand block is the long one, we can do it in two! - ptr::copy(buf, buf.offset((cap - tail) as isize), head); - ptr::copy(buf.offset(tail as isize), buf, cap - tail); - } + } else if (tail - head) >= cmp::min((cap - tail), head) { + // There is enough free space in the centre for the shortest block so we can + // do this in at most three copy moves. + if (cap - tail) > head { + // right hand block is the long one; move that enough for the left + ptr::copy(buf.offset(tail as isize), + buf.offset((tail - head) as isize), + cap - tail); + // copy left in the end + ptr::copy(buf, buf.offset((cap - head) as isize), head); + // shift the new thing to the start + ptr::copy(buf.offset((tail - head) as isize), buf, len); } else { - // Need to use N swaps to move the ring - // We can use the space at the end of the ring as a temp store - - let mut left_edge: usize = 0; - let mut right_edge: usize = tail; - - // The general problem looks like this - // GHIJKLM...ABCDEF - before any swaps - // ABCDEFM...GHIJKL - after 1 pass of swaps - // ABCDEFGHIJM...KL - swap until the left edge reaches the temp store - // - then restart the algorithm with a new (smaller) store - // Sometimes the temp store is reached when the right edge is at the end - // of the buffer - this means we've hit the right order with fewer swaps! - // E.g - // EF..ABCD - // ABCDEF.. - after four only swaps we've finished - - while left_edge < len && right_edge != cap { - let mut right_offset = 0; - for i in left_edge..right_edge { - right_offset = (i - left_edge) % (cap - right_edge); - let src: isize = (right_edge + right_offset) as isize; - ptr::swap(buf.offset(i as isize), buf.offset(src)); - } - let n_ops = right_edge - left_edge; - left_edge += n_ops; - right_edge += right_offset + 1; - + // left hand block is the long one, we can do it in two! + ptr::copy(buf, buf.offset((cap - tail) as isize), head); + ptr::copy(buf.offset(tail as isize), buf, cap - tail); + } + } else { + // Need to use N swaps to move the ring + // We can use the space at the end of the ring as a temp store + + let mut left_edge: usize = 0; + let mut right_edge: usize = tail; + + // The general problem looks like this + // GHIJKLM...ABCDEF - before any swaps + // ABCDEFM...GHIJKL - after 1 pass of swaps + // ABCDEFGHIJM...KL - swap until the left edge reaches the temp store + // - then restart the algorithm with a new (smaller) store + // Sometimes the temp store is reached when the right edge is at the end + // of the buffer - this means we've hit the right order with fewer swaps! + // E.g + // EF..ABCD + // ABCDEF.. - after four only swaps we've finished + + while left_edge < len && right_edge != cap { + let mut right_offset = 0; + for i in left_edge..right_edge { + right_offset = (i - left_edge) % (cap - right_edge); + let src: isize = (right_edge + right_offset) as isize; + ptr::swap(buf.offset(i as isize), buf.offset(src)); } + let n_ops = right_edge - left_edge; + left_edge += n_ops; + right_edge += right_offset + 1; } - } + let out = Vec::from_raw_parts(buf, len, cap); mem::forget(other); out From 27151017e987044a35ae45f8c9bd8530af9e5f47 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 21 Mar 2017 16:23:27 +0100 Subject: [PATCH 02/19] Add missing urls in ptr docs --- src/libstd/primitive_docs.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libstd/primitive_docs.rs b/src/libstd/primitive_docs.rs index 7d6d16f474845..ba14a3d6b47e7 100644 --- a/src/libstd/primitive_docs.rs +++ b/src/libstd/primitive_docs.rs @@ -183,9 +183,9 @@ mod prim_unit { } /// Working with raw pointers in Rust is uncommon, /// typically limited to a few patterns. /// -/// Use the `null` function to create null pointers, and the `is_null` method +/// Use the [`null`] function to create null pointers, and the [`is_null`] method /// of the `*const T` type to check for null. The `*const T` type also defines -/// the `offset` method, for pointer math. +/// the [`offset`] method, for pointer math. /// /// # Common ways to create raw pointers /// @@ -213,7 +213,7 @@ mod prim_unit { } /// /// ## 2. Consume a box (`Box`). /// -/// The `into_raw` function consumes a box and returns +/// The [`into_raw`] function consumes a box and returns /// the raw pointer. It doesn't destroy `T` or deallocate any memory. /// /// ``` @@ -227,7 +227,7 @@ mod prim_unit { } /// } /// ``` /// -/// Note that here the call to `drop` is for clarity - it indicates +/// Note that here the call to [`drop`] is for clarity - it indicates /// that we are done with the given value and it should be destroyed. /// /// ## 3. Get it from C. @@ -255,6 +255,11 @@ mod prim_unit { } /// /// *[See also the `std::ptr` module](ptr/index.html).* /// +/// [`null`]: ../std/ptr/fn.null.html +/// [`is_null`]: ../std/primitive.pointer.html#method.is_null +/// [`offset`]: ../std/primitive.pointer.html#method.offset +/// [`into_raw`]: ../std/boxed/struct.Box.html#method.into_raw +/// [`drop`]: ../std/mem/fn.drop.html #[stable(feature = "rust1", since = "1.0.0")] mod prim_pointer { } From 4dc122580714a5f8859e993bf56a7228b0bcd7c1 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Thu, 23 Mar 2017 13:17:21 -0400 Subject: [PATCH 03/19] Add helpful hint on io function for beginners --- src/libstd/io/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 850885a8c0f3a..dda9d6bca7977 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -144,6 +144,16 @@ //! # Ok(()) //! # } //! ``` +//! Note that you cannot use the `?` operator in functions that do not return a `Result` (e.g. `main()`). +//! Instead, you can `match` on the return value to catch any possible errors: +//! +//! ``` +//! let mut input = String::new(); +//! match io::stdin().read_line(&mut input) { +//! Err(why) => panic!("Failed to read input: {}", why.description()), +//! Ok(_) => println!("You typed: {}", input.trim()), +//! } +//! ``` //! //! And a very common source of output is standard output: //! From 53d5082a2d08060ebca869cb8ee97c3ed3cf4ce9 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Thu, 23 Mar 2017 13:42:39 -0400 Subject: [PATCH 04/19] requested changes --- src/libstd/io/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index dda9d6bca7977..60b211a746ff1 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -144,7 +144,8 @@ //! # Ok(()) //! # } //! ``` -//! Note that you cannot use the `?` operator in functions that do not return a `Result` (e.g. `main()`). +//! +//! Note that you cannot use the `?` operator in functions that do not return a `Result` (e.g. `main`). //! Instead, you can `match` on the return value to catch any possible errors: //! //! ``` From 04fbec1a0cb7467834bd264b80350b1cade8b4ca Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Thu, 23 Mar 2017 13:43:09 -0400 Subject: [PATCH 05/19] newline for breathing room --- src/libstd/io/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 60b211a746ff1..773b0964b4269 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -150,6 +150,7 @@ //! //! ``` //! let mut input = String::new(); +//! //! match io::stdin().read_line(&mut input) { //! Err(why) => panic!("Failed to read input: {}", why.description()), //! Ok(_) => println!("You typed: {}", input.trim()), From 4806f01d7c1f35a1b6f675ff099b86ec6e6c1540 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Mon, 27 Mar 2017 16:34:13 -0400 Subject: [PATCH 06/19] Fix tidy errors and simplify example --- src/libstd/io/mod.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 773b0964b4269..1b0c992ba0976 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -145,16 +145,14 @@ //! # } //! ``` //! -//! Note that you cannot use the `?` operator in functions that do not return a `Result` (e.g. `main`). -//! Instead, you can `match` on the return value to catch any possible errors: -//! +//! Note that you cannot use the `?` operator in functions that do not return +//! a `Result` (e.g. `main`). Instead, you can call `.unwrap()` or `match` +//! on the return value to catch any possible errors: +//! //! ``` //! let mut input = String::new(); -//! -//! match io::stdin().read_line(&mut input) { -//! Err(why) => panic!("Failed to read input: {}", why.description()), -//! Ok(_) => println!("You typed: {}", input.trim()), -//! } +//! +//! io::stdin().read_line(&mut input).unwrap(); //! ``` //! //! And a very common source of output is standard output: From 756f2248f73d2ea2703a65855c52086a1262a290 Mon Sep 17 00:00:00 2001 From: projektir Date: Mon, 27 Mar 2017 23:55:03 -0400 Subject: [PATCH 07/19] Adding links for Atomics docs #29377 --- src/libcore/sync/atomic.rs | 104 +++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 38 deletions(-) diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index 743e3c41170a3..c3e7c9b7c989c 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -15,27 +15,37 @@ //! types. //! //! This module defines atomic versions of a select number of primitive -//! types, including `AtomicBool`, `AtomicIsize`, and `AtomicUsize`. +//! types, including [`AtomicBool`], [`AtomicIsize`], and [`AtomicUsize`]. //! Atomic types present operations that, when used correctly, synchronize //! updates between threads. //! -//! Each method takes an `Ordering` which represents the strength of +//! [`AtomicBool`]: struct.AtomicBool.html +//! [`AtomicIsize`]: struct.AtomicIsize.html +//! [`AtomicUsize`]: struct.AtomicUsize.html +//! +//! Each method takes an [`Ordering`] which represents the strength of //! the memory barrier for that operation. These orderings are the //! same as [LLVM atomic orderings][1]. For more information see the [nomicon][2]. //! +//! [`Ordering`]: enum.Ordering.html +//! //! [1]: http://llvm.org/docs/LangRef.html#memory-model-for-concurrent-operations //! [2]: ../../../nomicon/atomics.html //! -//! Atomic variables are safe to share between threads (they implement `Sync`) +//! Atomic variables are safe to share between threads (they implement [`Sync`]) //! but they do not themselves provide the mechanism for sharing and follow the //! [threading model](../../../std/thread/index.html#the-threading-model) of rust. -//! The most common way to share an atomic variable is to put it into an `Arc` (an +//! The most common way to share an atomic variable is to put it into an [`Arc`][arc] (an //! atomically-reference-counted shared pointer). //! +//! [`Sync`]: ../../marker/trait.Sync.html +//! [arc]: ../struct.Arc.html +//! //! Most atomic types may be stored in static variables, initialized using -//! the provided static initializers like `ATOMIC_BOOL_INIT`. Atomic statics +//! the provided static initializers like [`ATOMIC_BOOL_INIT`]. Atomic statics //! are often used for lazy global initialization. //! +//! [`ATOMIC_BOOL_INIT`]: constant.ATOMIC_BOOL_INIT.html //! //! # Examples //! @@ -149,21 +159,26 @@ unsafe impl Sync for AtomicPtr {} #[derive(Copy, Clone, Debug)] pub enum Ordering { /// No ordering constraints, only atomic operations. Corresponds to LLVM's - /// `Monotonic` ordering. + /// [`Monotonic`][1] ordering. + /// [1]: http://llvm.org/docs/Atomics.html#monotonic #[stable(feature = "rust1", since = "1.0.0")] Relaxed, /// When coupled with a store, all previous writes become visible - /// to the other threads that perform a load with `Acquire` ordering + /// to the other threads that perform a load with [`Acquire`][1] ordering /// on the same value. + /// [1]: http://llvm.org/docs/Atomics.html#acquire #[stable(feature = "rust1", since = "1.0.0")] Release, /// When coupled with a load, all subsequent loads will see data - /// written before a store with `Release` ordering on the same value + /// written before a store with [`Release`][1] ordering on the same value /// in other threads. + /// [1]: http://llvm.org/docs/Atomics.html#release #[stable(feature = "rust1", since = "1.0.0")] Acquire, - /// When coupled with a load, uses `Acquire` ordering, and with a store - /// `Release` ordering. + /// When coupled with a load, uses [`Acquire`][1] ordering, and with a store + /// [`Release`][2] ordering. + /// [1]: http://llvm.org/docs/Atomics.html#acquire + /// [2]: http://llvm.org/docs/Atomics.html#release #[stable(feature = "rust1", since = "1.0.0")] AcqRel, /// Like `AcqRel` with the additional guarantee that all threads see all @@ -176,7 +191,8 @@ pub enum Ordering { __Nonexhaustive, } -/// An `AtomicBool` initialized to `false`. +/// An [`AtomicBool`] initialized to `false`. +/// [`AtomicBool`]: struct.AtomicBool.html #[cfg(target_has_atomic = "8")] #[stable(feature = "rust1", since = "1.0.0")] pub const ATOMIC_BOOL_INIT: AtomicBool = AtomicBool::new(false); @@ -241,7 +257,7 @@ impl AtomicBool { /// Loads a value from the bool. /// - /// `load` takes an [`Ordering`] argument which describes the memory ordering + /// `load()` takes an [`Ordering`] argument which describes the memory ordering /// of this operation. /// /// # Panics @@ -250,7 +266,7 @@ impl AtomicBool { /// /// [`Ordering`]: enum.Ordering.html /// [`Release`]: enum.Ordering.html#variant.Release - /// [`AcqRel`]: enum.Ordering.html#variant.Release + /// [`AcqRel`]: enum.Ordering.html#variant.AcqRel /// /// # Examples /// @@ -269,7 +285,7 @@ impl AtomicBool { /// Stores a value into the bool. /// - /// `store` takes an [`Ordering`] argument which describes the memory ordering + /// `store()` takes an [`Ordering`] argument which describes the memory ordering /// of this operation. /// /// [`Ordering`]: enum.Ordering.html @@ -287,7 +303,10 @@ impl AtomicBool { /// /// # Panics /// - /// Panics if `order` is `Acquire` or `AcqRel`. + /// Panics if `order` is [`Acquire`] or [`AcqRel`]. + /// + /// [`Acquire`]: enum.Ordering.html#variant.Acquire + /// [`AcqRel`]: enum.Ordering.html#variant.AcqRel #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn store(&self, val: bool, order: Ordering) { @@ -298,7 +317,7 @@ impl AtomicBool { /// Stores a value into the bool, returning the old value. /// - /// `swap` takes an [`Ordering`] argument which describes the memory ordering + /// `swap()` takes an [`Ordering`] argument which describes the memory ordering /// of this operation. /// /// [`Ordering`]: enum.Ordering.html @@ -324,7 +343,7 @@ impl AtomicBool { /// The return value is always the previous value. If it is equal to `current`, then the value /// was updated. /// - /// `compare_and_swap` also takes an [`Ordering`] argument which describes the memory + /// `compare_and_swap()` also takes an [`Ordering`] argument which describes the memory /// ordering of this operation. /// /// [`Ordering`]: enum.Ordering.html @@ -356,7 +375,7 @@ impl AtomicBool { /// The return value is a result indicating whether the new value was written and containing /// the previous value. On success this value is guaranteed to be equal to `current`. /// - /// `compare_exchange` takes two [`Ordering`] arguments to describe the memory + /// `compare_exchange()` takes two [`Ordering`] arguments to describe the memory /// ordering of this operation. The first describes the required ordering if the /// operation succeeds while the second describes the required ordering when the /// operation fails. The failure ordering can't be [`Release`] or [`AcqRel`] and must @@ -404,17 +423,18 @@ impl AtomicBool { /// Stores a value into the `bool` if the current value is the same as the `current` value. /// - /// Unlike `compare_exchange`, this function is allowed to spuriously fail even when the + /// Unlike [`compare_exchange()`], this function is allowed to spuriously fail even when the /// comparison succeeds, which can result in more efficient code on some platforms. The /// return value is a result indicating whether the new value was written and containing the /// previous value. /// - /// `compare_exchange_weak` takes two [`Ordering`] arguments to describe the memory + /// `compare_exchange_weak()` takes two [`Ordering`] arguments to describe the memory /// ordering of this operation. The first describes the required ordering if the operation /// succeeds while the second describes the required ordering when the operation fails. The /// failure ordering can't be [`Release`] or [`AcqRel`] and must be equivalent or /// weaker than the success ordering. /// + /// [`compare_exchange()`]: #method.compare_exchange /// [`Ordering`]: enum.Ordering.html /// [`Release`]: enum.Ordering.html#variant.Release /// [`AcqRel`]: enum.Ordering.html#variant.Release @@ -645,7 +665,7 @@ impl AtomicPtr { /// Loads a value from the pointer. /// - /// `load` takes an [`Ordering`] argument which describes the memory ordering + /// `load()` takes an [`Ordering`] argument which describes the memory ordering /// of this operation. /// /// # Panics @@ -674,7 +694,7 @@ impl AtomicPtr { /// Stores a value into the pointer. /// - /// `store` takes an [`Ordering`] argument which describes the memory ordering + /// `store()` takes an [`Ordering`] argument which describes the memory ordering /// of this operation. /// /// [`Ordering`]: enum.Ordering.html @@ -694,7 +714,11 @@ impl AtomicPtr { /// /// # Panics /// - /// Panics if `order` is `Acquire` or `AcqRel`. + /// Panics if `order` is [`Acquire`] or [`AcqRel`]. + /// + /// [`Acquire`]: enum.Ordering.html#variant.Acquire + /// [`AcqRel`]: enum.Ordering.html#variant.AcqRel + /// #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn store(&self, ptr: *mut T, order: Ordering) { @@ -705,7 +729,7 @@ impl AtomicPtr { /// Stores a value into the pointer, returning the old value. /// - /// `swap` takes an [`Ordering`] argument which describes the memory ordering + /// `swap()` takes an [`Ordering`] argument which describes the memory ordering /// of this operation. /// /// [`Ordering`]: enum.Ordering.html @@ -733,7 +757,7 @@ impl AtomicPtr { /// The return value is always the previous value. If it is equal to `current`, then the value /// was updated. /// - /// `compare_and_swap` also takes an [`Ordering`] argument which describes the memory + /// `compare_and_swap()` also takes an [`Ordering`] argument which describes the memory /// ordering of this operation. /// /// [`Ordering`]: enum.Ordering.html @@ -765,7 +789,7 @@ impl AtomicPtr { /// The return value is a result indicating whether the new value was written and containing /// the previous value. On success this value is guaranteed to be equal to `current`. /// - /// `compare_exchange` takes two [`Ordering`] arguments to describe the memory + /// `compare_exchange()` takes two [`Ordering`] arguments to describe the memory /// ordering of this operation. The first describes the required ordering if /// the operation succeeds while the second describes the required ordering when /// the operation fails. The failure ordering can't be [`Release`] or [`AcqRel`] @@ -812,18 +836,18 @@ impl AtomicPtr { /// Stores a value into the pointer if the current value is the same as the `current` value. /// - /// Unlike [`compare_exchange`], this function is allowed to spuriously fail even when the + /// Unlike [`compare_exchange()`], this function is allowed to spuriously fail even when the /// comparison succeeds, which can result in more efficient code on some platforms. The /// return value is a result indicating whether the new value was written and containing the /// previous value. /// - /// `compare_exchange_weak` takes two [`Ordering`] arguments to describe the memory + /// `compare_exchange_weak()` takes two [`Ordering`] arguments to describe the memory /// ordering of this operation. The first describes the required ordering if the operation /// succeeds while the second describes the required ordering when the operation fails. The /// failure ordering can't be [`Release`] or [`AcqRel`] and must be equivalent or /// weaker than the success ordering. /// - /// [`compare_exchange`]: #method.compare_exchange + /// [`compare_exchange()`]: #method.compare_exchange /// [`Ordering`]: enum.Ordering.html /// [`Release`]: enum.Ordering.html#variant.Release /// [`AcqRel`]: enum.Ordering.html#variant.AcqRel @@ -962,7 +986,7 @@ macro_rules! atomic_int { /// Loads a value from the atomic integer. /// - /// `load` takes an [`Ordering`] argument which describes the memory ordering of this + /// `load()` takes an [`Ordering`] argument which describes the memory ordering of this /// operation. /// /// # Panics @@ -990,7 +1014,7 @@ macro_rules! atomic_int { /// Stores a value into the atomic integer. /// - /// `store` takes an [`Ordering`] argument which describes the memory ordering of this + /// `store()` takes an [`Ordering`] argument which describes the memory ordering of this /// operation. /// /// [`Ordering`]: enum.Ordering.html @@ -1008,7 +1032,11 @@ macro_rules! atomic_int { /// /// # Panics /// - /// Panics if `order` is `Acquire` or `AcqRel`. + /// Panics if `order` is [`Acquire`] or [`AcqRel`]. + /// + /// [`Acquire`]: enum.Ordering.html#variant.Acquire + /// [`AcqRel`]: enum.Ordering.html#variant.AcqRel + /// #[inline] #[$stable] pub fn store(&self, val: $int_type, order: Ordering) { @@ -1017,7 +1045,7 @@ macro_rules! atomic_int { /// Stores a value into the atomic integer, returning the old value. /// - /// `swap` takes an [`Ordering`] argument which describes the memory ordering of this + /// `swap()` takes an [`Ordering`] argument which describes the memory ordering of this /// operation. /// /// [`Ordering`]: enum.Ordering.html @@ -1043,7 +1071,7 @@ macro_rules! atomic_int { /// The return value is always the previous value. If it is equal to `current`, then the /// value was updated. /// - /// `compare_and_swap` also takes an [`Ordering`] argument which describes the memory + /// `compare_and_swap()` also takes an [`Ordering`] argument which describes the memory /// ordering of this operation. /// /// [`Ordering`]: enum.Ordering.html @@ -1083,7 +1111,7 @@ macro_rules! atomic_int { /// containing the previous value. On success this value is guaranteed to be equal to /// `current`. /// - /// `compare_exchange` takes two [`Ordering`] arguments to describe the memory + /// `compare_exchange()` takes two [`Ordering`] arguments to describe the memory /// ordering of this operation. The first describes the required ordering if /// the operation succeeds while the second describes the required ordering when /// the operation fails. The failure ordering can't be [`Release`] or [`AcqRel`] and @@ -1125,18 +1153,18 @@ macro_rules! atomic_int { /// Stores a value into the atomic integer if the current value is the same as the /// `current` value. /// - /// Unlike [`compare_exchange`], this function is allowed to spuriously fail even + /// Unlike [`compare_exchange()`], this function is allowed to spuriously fail even /// when the comparison succeeds, which can result in more efficient code on some /// platforms. The return value is a result indicating whether the new value was /// written and containing the previous value. /// - /// `compare_exchange_weak` takes two [`Ordering`] arguments to describe the memory + /// `compare_exchange_weak()` takes two [`Ordering`] arguments to describe the memory /// ordering of this operation. The first describes the required ordering if the /// operation succeeds while the second describes the required ordering when the /// operation fails. The failure ordering can't be [`Release`] or [`AcqRel`] and /// must be equivalent or weaker than the success ordering. /// - /// [`compare_exchange`]: #method.compare_exchange + /// [`compare_exchange()`]: #method.compare_exchange /// [`Ordering`]: enum.Ordering.html /// [`Release`]: enum.Ordering.html#variant.Release /// [`AcqRel`]: enum.Ordering.html#variant.AcqRel From cd2ec7eded8d65b88b4c2fdb26efe1b3c505bd6f Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Tue, 28 Mar 2017 13:27:46 -0400 Subject: [PATCH 08/19] add missing import --- src/libstd/io/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 1b0c992ba0976..32ead78f6cd58 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -150,6 +150,8 @@ //! on the return value to catch any possible errors: //! //! ``` +//! use std::io; +//! //! let mut input = String::new(); //! //! io::stdin().read_line(&mut input).unwrap(); From 11ce5b72a21718f6d49b5f40b71ea0f53b8ea4bc Mon Sep 17 00:00:00 2001 From: topecongiro Date: Wed, 22 Mar 2017 16:17:15 +0900 Subject: [PATCH 09/19] Make overlapping_inherent_impls lint a hard error --- src/librustc_lint/lib.rs | 5 +---- src/librustc_typeck/coherence/inherent_impls.rs | 1 - src/librustc_typeck/diagnostics.rs | 1 + .../coherence-overlapping-inherent-impl-trait.rs | 2 -- src/test/compile-fail/inherent-overlap.rs | 3 --- 5 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 05dbbc0987025..8d759d89135ac 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -196,10 +196,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { id: LintId::of(SUPER_OR_SELF_IN_GLOBAL_PATH), reference: "issue #36888 ", }, - FutureIncompatibleInfo { - id: LintId::of(OVERLAPPING_INHERENT_IMPLS), - reference: "issue #36889 ", - }, FutureIncompatibleInfo { id: LintId::of(ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN), reference: "issue #36890 ", @@ -263,4 +259,5 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { store.register_removed("drop_with_repr_extern", "drop flags have been removed"); store.register_removed("transmute_from_fn_item_types", "always cast functions before transmuting them"); + store.register_removed("overlapping_inherent_impls", "converted into hard error, see #36889"); } diff --git a/src/librustc_typeck/coherence/inherent_impls.rs b/src/librustc_typeck/coherence/inherent_impls.rs index 3a39df505eb07..dc4bd7733fc21 100644 --- a/src/librustc_typeck/coherence/inherent_impls.rs +++ b/src/librustc_typeck/coherence/inherent_impls.rs @@ -322,4 +322,3 @@ impl<'a, 'tcx> InherentCollect<'a, 'tcx> { } } } - diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index bd6129eb5bee3..fb951fd20e564 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -4212,4 +4212,5 @@ register_diagnostics! { // but `{}` was found in the type `{}` E0567, // auto traits can not have type parameters E0568, // auto-traits can not have predicates, + E0592, // duplicate definitions with name `{}` } diff --git a/src/test/compile-fail/coherence-overlapping-inherent-impl-trait.rs b/src/test/compile-fail/coherence-overlapping-inherent-impl-trait.rs index 08e8605e91773..158d3606104a9 100644 --- a/src/test/compile-fail/coherence-overlapping-inherent-impl-trait.rs +++ b/src/test/compile-fail/coherence-overlapping-inherent-impl-trait.rs @@ -9,10 +9,8 @@ // except according to those terms. #![allow(dead_code)] -#![deny(overlapping_inherent_impls)] trait C {} impl C { fn f() {} } //~ ERROR duplicate definitions with name `f` -//~^ WARN: this was previously accepted impl C { fn f() {} } fn main() { } diff --git a/src/test/compile-fail/inherent-overlap.rs b/src/test/compile-fail/inherent-overlap.rs index 00d41244639f5..18e77ddfd2c5b 100644 --- a/src/test/compile-fail/inherent-overlap.rs +++ b/src/test/compile-fail/inherent-overlap.rs @@ -17,7 +17,6 @@ struct Foo; impl Foo { fn id() {} //~ ERROR duplicate definitions - //~^ WARN previously accepted } impl Foo { @@ -28,7 +27,6 @@ struct Bar(T); impl Bar { fn bar(&self) {} //~ ERROR duplicate definitions - //~^ WARN previously accepted } impl Bar { @@ -39,7 +37,6 @@ struct Baz(T); impl Baz { fn baz(&self) {} //~ ERROR duplicate definitions - //~^ WARN previously accepted } impl Baz> { From 4ea03c876ba864946ed50fde7788cfe2383027f1 Mon Sep 17 00:00:00 2001 From: projektir Date: Wed, 29 Mar 2017 00:52:16 -0400 Subject: [PATCH 10/19] Fixing formatting issues #29377 --- src/libcore/sync/atomic.rs | 80 ++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index c3e7c9b7c989c..ae47e6fdfa928 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -39,7 +39,7 @@ //! atomically-reference-counted shared pointer). //! //! [`Sync`]: ../../marker/trait.Sync.html -//! [arc]: ../struct.Arc.html +//! [arc]: ../../../std/sync/struct.Arc.html //! //! Most atomic types may be stored in static variables, initialized using //! the provided static initializers like [`ATOMIC_BOOL_INIT`]. Atomic statics @@ -158,27 +158,32 @@ unsafe impl Sync for AtomicPtr {} #[stable(feature = "rust1", since = "1.0.0")] #[derive(Copy, Clone, Debug)] pub enum Ordering { - /// No ordering constraints, only atomic operations. Corresponds to LLVM's - /// [`Monotonic`][1] ordering. - /// [1]: http://llvm.org/docs/Atomics.html#monotonic + /// No ordering constraints, only atomic operations. + /// + /// Corresponds to LLVM's [`Monotonic`] ordering. + /// + /// [`Monotonic`]: http://llvm.org/docs/Atomics.html#monotonic #[stable(feature = "rust1", since = "1.0.0")] Relaxed, /// When coupled with a store, all previous writes become visible - /// to the other threads that perform a load with [`Acquire`][1] ordering + /// to the other threads that perform a load with [`Acquire`] ordering /// on the same value. - /// [1]: http://llvm.org/docs/Atomics.html#acquire + /// + /// [`Acquire`]: http://llvm.org/docs/Atomics.html#acquire #[stable(feature = "rust1", since = "1.0.0")] Release, /// When coupled with a load, all subsequent loads will see data - /// written before a store with [`Release`][1] ordering on the same value + /// written before a store with [`Release`] ordering on the same value /// in other threads. - /// [1]: http://llvm.org/docs/Atomics.html#release + /// + /// [`Release`]: http://llvm.org/docs/Atomics.html#release #[stable(feature = "rust1", since = "1.0.0")] Acquire, - /// When coupled with a load, uses [`Acquire`][1] ordering, and with a store - /// [`Release`][2] ordering. - /// [1]: http://llvm.org/docs/Atomics.html#acquire - /// [2]: http://llvm.org/docs/Atomics.html#release + /// When coupled with a load, uses [`Acquire`] ordering, and with a store + /// [`Release`] ordering. + /// + /// [`Acquire`]: http://llvm.org/docs/Atomics.html#acquire + /// [`Release`]: http://llvm.org/docs/Atomics.html#release #[stable(feature = "rust1", since = "1.0.0")] AcqRel, /// Like `AcqRel` with the additional guarantee that all threads see all @@ -192,6 +197,7 @@ pub enum Ordering { } /// An [`AtomicBool`] initialized to `false`. +/// /// [`AtomicBool`]: struct.AtomicBool.html #[cfg(target_has_atomic = "8")] #[stable(feature = "rust1", since = "1.0.0")] @@ -257,7 +263,7 @@ impl AtomicBool { /// Loads a value from the bool. /// - /// `load()` takes an [`Ordering`] argument which describes the memory ordering + /// `load` takes an [`Ordering`] argument which describes the memory ordering /// of this operation. /// /// # Panics @@ -285,7 +291,7 @@ impl AtomicBool { /// Stores a value into the bool. /// - /// `store()` takes an [`Ordering`] argument which describes the memory ordering + /// `store` takes an [`Ordering`] argument which describes the memory ordering /// of this operation. /// /// [`Ordering`]: enum.Ordering.html @@ -317,7 +323,7 @@ impl AtomicBool { /// Stores a value into the bool, returning the old value. /// - /// `swap()` takes an [`Ordering`] argument which describes the memory ordering + /// `swap` takes an [`Ordering`] argument which describes the memory ordering /// of this operation. /// /// [`Ordering`]: enum.Ordering.html @@ -343,7 +349,7 @@ impl AtomicBool { /// The return value is always the previous value. If it is equal to `current`, then the value /// was updated. /// - /// `compare_and_swap()` also takes an [`Ordering`] argument which describes the memory + /// `compare_and_swap` also takes an [`Ordering`] argument which describes the memory /// ordering of this operation. /// /// [`Ordering`]: enum.Ordering.html @@ -375,7 +381,7 @@ impl AtomicBool { /// The return value is a result indicating whether the new value was written and containing /// the previous value. On success this value is guaranteed to be equal to `current`. /// - /// `compare_exchange()` takes two [`Ordering`] arguments to describe the memory + /// `compare_exchange` takes two [`Ordering`] arguments to describe the memory /// ordering of this operation. The first describes the required ordering if the /// operation succeeds while the second describes the required ordering when the /// operation fails. The failure ordering can't be [`Release`] or [`AcqRel`] and must @@ -423,18 +429,18 @@ impl AtomicBool { /// Stores a value into the `bool` if the current value is the same as the `current` value. /// - /// Unlike [`compare_exchange()`], this function is allowed to spuriously fail even when the + /// Unlike [`compare_exchange`], this function is allowed to spuriously fail even when the /// comparison succeeds, which can result in more efficient code on some platforms. The /// return value is a result indicating whether the new value was written and containing the /// previous value. /// - /// `compare_exchange_weak()` takes two [`Ordering`] arguments to describe the memory + /// `compare_exchange_weak` takes two [`Ordering`] arguments to describe the memory /// ordering of this operation. The first describes the required ordering if the operation /// succeeds while the second describes the required ordering when the operation fails. The /// failure ordering can't be [`Release`] or [`AcqRel`] and must be equivalent or /// weaker than the success ordering. /// - /// [`compare_exchange()`]: #method.compare_exchange + /// [`compare_exchange`]: #method.compare_exchange /// [`Ordering`]: enum.Ordering.html /// [`Release`]: enum.Ordering.html#variant.Release /// [`AcqRel`]: enum.Ordering.html#variant.Release @@ -665,7 +671,7 @@ impl AtomicPtr { /// Loads a value from the pointer. /// - /// `load()` takes an [`Ordering`] argument which describes the memory ordering + /// `load` takes an [`Ordering`] argument which describes the memory ordering /// of this operation. /// /// # Panics @@ -694,7 +700,7 @@ impl AtomicPtr { /// Stores a value into the pointer. /// - /// `store()` takes an [`Ordering`] argument which describes the memory ordering + /// `store` takes an [`Ordering`] argument which describes the memory ordering /// of this operation. /// /// [`Ordering`]: enum.Ordering.html @@ -718,7 +724,6 @@ impl AtomicPtr { /// /// [`Acquire`]: enum.Ordering.html#variant.Acquire /// [`AcqRel`]: enum.Ordering.html#variant.AcqRel - /// #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn store(&self, ptr: *mut T, order: Ordering) { @@ -729,7 +734,7 @@ impl AtomicPtr { /// Stores a value into the pointer, returning the old value. /// - /// `swap()` takes an [`Ordering`] argument which describes the memory ordering + /// `swap` takes an [`Ordering`] argument which describes the memory ordering /// of this operation. /// /// [`Ordering`]: enum.Ordering.html @@ -757,7 +762,7 @@ impl AtomicPtr { /// The return value is always the previous value. If it is equal to `current`, then the value /// was updated. /// - /// `compare_and_swap()` also takes an [`Ordering`] argument which describes the memory + /// `compare_and_swap` also takes an [`Ordering`] argument which describes the memory /// ordering of this operation. /// /// [`Ordering`]: enum.Ordering.html @@ -789,7 +794,7 @@ impl AtomicPtr { /// The return value is a result indicating whether the new value was written and containing /// the previous value. On success this value is guaranteed to be equal to `current`. /// - /// `compare_exchange()` takes two [`Ordering`] arguments to describe the memory + /// `compare_exchange` takes two [`Ordering`] arguments to describe the memory /// ordering of this operation. The first describes the required ordering if /// the operation succeeds while the second describes the required ordering when /// the operation fails. The failure ordering can't be [`Release`] or [`AcqRel`] @@ -836,18 +841,18 @@ impl AtomicPtr { /// Stores a value into the pointer if the current value is the same as the `current` value. /// - /// Unlike [`compare_exchange()`], this function is allowed to spuriously fail even when the + /// Unlike [`compare_exchange`], this function is allowed to spuriously fail even when the /// comparison succeeds, which can result in more efficient code on some platforms. The /// return value is a result indicating whether the new value was written and containing the /// previous value. /// - /// `compare_exchange_weak()` takes two [`Ordering`] arguments to describe the memory + /// `compare_exchange_weak` takes two [`Ordering`] arguments to describe the memory /// ordering of this operation. The first describes the required ordering if the operation /// succeeds while the second describes the required ordering when the operation fails. The /// failure ordering can't be [`Release`] or [`AcqRel`] and must be equivalent or /// weaker than the success ordering. /// - /// [`compare_exchange()`]: #method.compare_exchange + /// [`compare_exchange`]: #method.compare_exchange /// [`Ordering`]: enum.Ordering.html /// [`Release`]: enum.Ordering.html#variant.Release /// [`AcqRel`]: enum.Ordering.html#variant.AcqRel @@ -986,7 +991,7 @@ macro_rules! atomic_int { /// Loads a value from the atomic integer. /// - /// `load()` takes an [`Ordering`] argument which describes the memory ordering of this + /// `load` takes an [`Ordering`] argument which describes the memory ordering of this /// operation. /// /// # Panics @@ -1014,7 +1019,7 @@ macro_rules! atomic_int { /// Stores a value into the atomic integer. /// - /// `store()` takes an [`Ordering`] argument which describes the memory ordering of this + /// `store` takes an [`Ordering`] argument which describes the memory ordering of this /// operation. /// /// [`Ordering`]: enum.Ordering.html @@ -1036,7 +1041,6 @@ macro_rules! atomic_int { /// /// [`Acquire`]: enum.Ordering.html#variant.Acquire /// [`AcqRel`]: enum.Ordering.html#variant.AcqRel - /// #[inline] #[$stable] pub fn store(&self, val: $int_type, order: Ordering) { @@ -1045,7 +1049,7 @@ macro_rules! atomic_int { /// Stores a value into the atomic integer, returning the old value. /// - /// `swap()` takes an [`Ordering`] argument which describes the memory ordering of this + /// `swap` takes an [`Ordering`] argument which describes the memory ordering of this /// operation. /// /// [`Ordering`]: enum.Ordering.html @@ -1071,7 +1075,7 @@ macro_rules! atomic_int { /// The return value is always the previous value. If it is equal to `current`, then the /// value was updated. /// - /// `compare_and_swap()` also takes an [`Ordering`] argument which describes the memory + /// `compare_and_swap` also takes an [`Ordering`] argument which describes the memory /// ordering of this operation. /// /// [`Ordering`]: enum.Ordering.html @@ -1111,7 +1115,7 @@ macro_rules! atomic_int { /// containing the previous value. On success this value is guaranteed to be equal to /// `current`. /// - /// `compare_exchange()` takes two [`Ordering`] arguments to describe the memory + /// `compare_exchange` takes two [`Ordering`] arguments to describe the memory /// ordering of this operation. The first describes the required ordering if /// the operation succeeds while the second describes the required ordering when /// the operation fails. The failure ordering can't be [`Release`] or [`AcqRel`] and @@ -1153,18 +1157,18 @@ macro_rules! atomic_int { /// Stores a value into the atomic integer if the current value is the same as the /// `current` value. /// - /// Unlike [`compare_exchange()`], this function is allowed to spuriously fail even + /// Unlike [`compare_exchange`], this function is allowed to spuriously fail even /// when the comparison succeeds, which can result in more efficient code on some /// platforms. The return value is a result indicating whether the new value was /// written and containing the previous value. /// - /// `compare_exchange_weak()` takes two [`Ordering`] arguments to describe the memory + /// `compare_exchange_weak` takes two [`Ordering`] arguments to describe the memory /// ordering of this operation. The first describes the required ordering if the /// operation succeeds while the second describes the required ordering when the /// operation fails. The failure ordering can't be [`Release`] or [`AcqRel`] and /// must be equivalent or weaker than the success ordering. /// - /// [`compare_exchange()`]: #method.compare_exchange + /// [`compare_exchange`]: #method.compare_exchange /// [`Ordering`]: enum.Ordering.html /// [`Release`]: enum.Ordering.html#variant.Release /// [`AcqRel`]: enum.Ordering.html#variant.AcqRel From 9d4b486b845c7d04691801f1151219b41b7c327b Mon Sep 17 00:00:00 2001 From: Donnie Bishop Date: Thu, 30 Mar 2017 15:36:50 -0400 Subject: [PATCH 11/19] Modify Lines' description --- src/libcore/str/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 857eeb26af078..e995b59a14505 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -1161,9 +1161,13 @@ generate_pattern_iterators! { delegate double ended; } -/// Created with the method [`lines`]. +/// An iterator over the lines of a string, as string slices. /// -/// [`lines`]: ../../std/primitive.str.html#method.lines +/// This struct is created with the [`lines()`] method on [`str`]. +/// See its documentation for more. +/// +/// [`lines()`]: ../../std/primitive.str.html#method.lines +/// [`str`]: ../../std/primitive.str.html #[stable(feature = "rust1", since = "1.0.0")] #[derive(Clone, Debug)] pub struct Lines<'a>(Map, LinesAnyMap>); From 0f5cf54246f7a68a8fc18ee41dffc7cdf866e19c Mon Sep 17 00:00:00 2001 From: Donnie Bishop Date: Thu, 30 Mar 2017 15:40:05 -0400 Subject: [PATCH 12/19] Modify Bytes' description --- src/libcore/str/mod.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index e995b59a14505..4556d41dd0a5a 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -625,12 +625,13 @@ impl<'a> CharIndices<'a> { } } -/// External iterator for a string's bytes. -/// Use with the `std::iter` module. +/// An iterator over the bytes of a string slice. /// -/// Created with the method [`bytes`]. +/// This struct is created by the [`bytes()`] method on [`str`]. +/// See its documentation for more. /// -/// [`bytes`]: ../../std/primitive.str.html#method.bytes +/// [`bytes()`]: ../../std/primitive.str.html#method.bytes +/// [`str`]: ../../std/primitive.str.html #[stable(feature = "rust1", since = "1.0.0")] #[derive(Clone, Debug)] pub struct Bytes<'a>(Cloned>); From 41e04985867e04b2be7b7fbd90864e5d9b3a276f Mon Sep 17 00:00:00 2001 From: Donnie Bishop Date: Thu, 30 Mar 2017 15:46:41 -0400 Subject: [PATCH 13/19] Modify CharIndices' description --- src/libcore/str/mod.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 4556d41dd0a5a..4720c965c57ce 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -553,7 +553,15 @@ impl<'a> Chars<'a> { } } -/// Iterator for a string's characters and their byte offsets. +/// An iterator over the [`char`]s of a string slice, and their positions. +/// +/// [`char`]: ../../std/primitive.char.html +/// +/// This struct is created by the [`char_indices()`] method on [`str`]. +/// See its documentation for more. +/// +/// [`char_indices()`]: ../../std/primitive.str.html#method.char_indices +/// [`str`]: ../../std/primitive.str.html #[derive(Clone, Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub struct CharIndices<'a> { From 17b4884d3c3d88af7f43d5fca32fd8f48d75669b Mon Sep 17 00:00:00 2001 From: Donnie Bishop Date: Thu, 30 Mar 2017 15:51:49 -0400 Subject: [PATCH 14/19] Modify Chars' description --- src/libcore/str/mod.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 4720c965c57ce..11d52e3c15bc3 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -369,11 +369,15 @@ impl fmt::Display for Utf8Error { Section: Iterators */ -/// Iterator for the char (representing *Unicode Scalar Values*) of a string. +/// An iterator over the [`char`]s of a string slice. /// -/// Created with the method [`chars`]. +/// [`char`]: ../../std/primitive.char.html +/// +/// This struct is created by the [`chars()`] method on [`str`]. +/// See its documentation for more. /// -/// [`chars`]: ../../std/primitive.str.html#method.chars +/// [`chars()`]: ../../std/primitive.str.html#method.chars +/// [`str`]: ../../std/primitive.str.html #[derive(Clone, Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Chars<'a> { From 5d14ccbc96923607f6ab00810817885ee0939486 Mon Sep 17 00:00:00 2001 From: Donnie Bishop Date: Thu, 30 Mar 2017 16:35:19 -0400 Subject: [PATCH 15/19] Modify EncodeUtf16's description --- src/libcollections/str.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 219e818f7d738..aee6861a09f40 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -133,9 +133,15 @@ impl> SliceConcatExt for [S] { } } -/// External iterator for a string's UTF-16 code units. +/// An iterator of [`u16`] over the string encoded as UTF-16. /// -/// For use with the `std::iter` module. +/// [`u16`]: ../../std/primitive.u16.html +/// +/// This struct is created by the [`encode_utf16()`] method on [`str`]. +/// See its documentation for more. +/// +/// [`encode_utf16()`]: ../../std/primitive.str.html#method.encode_utf16 +/// [`str`]: ../../std/primitive.str.html #[derive(Clone)] #[stable(feature = "encode_utf16", since = "1.8.0")] pub struct EncodeUtf16<'a> { From a4a7166fd585802e9644ae9b4aa3e63861d11d3e Mon Sep 17 00:00:00 2001 From: Donnie Bishop Date: Thu, 30 Mar 2017 16:36:06 -0400 Subject: [PATCH 16/19] Modify SplitWhitespace's description --- src/libstd_unicode/u_str.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libstd_unicode/u_str.rs b/src/libstd_unicode/u_str.rs index 3c02ea82d2a11..fd309e822a0e5 100644 --- a/src/libstd_unicode/u_str.rs +++ b/src/libstd_unicode/u_str.rs @@ -17,8 +17,13 @@ use core::char; use core::iter::{Filter, FusedIterator}; use core::str::Split; -/// An iterator over the non-whitespace substrings of a string, -/// separated by any amount of whitespace. +/// An iterator over sub-slices of the original string slice. +/// +/// This struct is created by the [`split_whitespace()`] method on [`str`]. +/// See its documentation for more. +/// +/// [`split_whitespace()`]: ../../std/primitive.str.html#method.split_whitespace +/// [`str`]: ../../std/primitive.str.html #[stable(feature = "split_whitespace", since = "1.1.0")] pub struct SplitWhitespace<'a> { inner: Filter bool>, fn(&&str) -> bool>, From c4b11d19b85f970b759f14e6dd864512d8c41f66 Mon Sep 17 00:00:00 2001 From: Donnie Bishop Date: Thu, 30 Mar 2017 16:46:16 -0400 Subject: [PATCH 17/19] Revert SplitWhitespace's description Original headline of SplitWhitespace's description is more descriptive as to what it contains and iterates over. --- src/libstd_unicode/u_str.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libstd_unicode/u_str.rs b/src/libstd_unicode/u_str.rs index fd309e822a0e5..d3aa27b436d48 100644 --- a/src/libstd_unicode/u_str.rs +++ b/src/libstd_unicode/u_str.rs @@ -17,7 +17,8 @@ use core::char; use core::iter::{Filter, FusedIterator}; use core::str::Split; -/// An iterator over sub-slices of the original string slice. +/// An iterator over the non-whitespace substrings of a string, +/// separated by any amount of whitespace. /// /// This struct is created by the [`split_whitespace()`] method on [`str`]. /// See its documentation for more. From 3b396217b5b52cf87769263bf0b842c56471b54f Mon Sep 17 00:00:00 2001 From: Donnie Bishop Date: Thu, 30 Mar 2017 18:33:23 -0400 Subject: [PATCH 18/19] Remove parentheses in method references --- src/libcollections/str.rs | 4 ++-- src/libcore/str/mod.rs | 16 ++++++++-------- src/libstd_unicode/u_str.rs | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index aee6861a09f40..36a1f1eb2b7b2 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -137,10 +137,10 @@ impl> SliceConcatExt for [S] { /// /// [`u16`]: ../../std/primitive.u16.html /// -/// This struct is created by the [`encode_utf16()`] method on [`str`]. +/// This struct is created by the [`encode_utf16`] method on [`str`]. /// See its documentation for more. /// -/// [`encode_utf16()`]: ../../std/primitive.str.html#method.encode_utf16 +/// [`encode_utf16`]: ../../std/primitive.str.html#method.encode_utf16 /// [`str`]: ../../std/primitive.str.html #[derive(Clone)] #[stable(feature = "encode_utf16", since = "1.8.0")] diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 11d52e3c15bc3..56f42349b2041 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -373,10 +373,10 @@ Section: Iterators /// /// [`char`]: ../../std/primitive.char.html /// -/// This struct is created by the [`chars()`] method on [`str`]. +/// This struct is created by the [`chars`] method on [`str`]. /// See its documentation for more. /// -/// [`chars()`]: ../../std/primitive.str.html#method.chars +/// [`chars`]: ../../std/primitive.str.html#method.chars /// [`str`]: ../../std/primitive.str.html #[derive(Clone, Debug)] #[stable(feature = "rust1", since = "1.0.0")] @@ -561,10 +561,10 @@ impl<'a> Chars<'a> { /// /// [`char`]: ../../std/primitive.char.html /// -/// This struct is created by the [`char_indices()`] method on [`str`]. +/// This struct is created by the [`char_indices`] method on [`str`]. /// See its documentation for more. /// -/// [`char_indices()`]: ../../std/primitive.str.html#method.char_indices +/// [`char_indices`]: ../../std/primitive.str.html#method.char_indices /// [`str`]: ../../std/primitive.str.html #[derive(Clone, Debug)] #[stable(feature = "rust1", since = "1.0.0")] @@ -639,10 +639,10 @@ impl<'a> CharIndices<'a> { /// An iterator over the bytes of a string slice. /// -/// This struct is created by the [`bytes()`] method on [`str`]. +/// This struct is created by the [`bytes`] method on [`str`]. /// See its documentation for more. /// -/// [`bytes()`]: ../../std/primitive.str.html#method.bytes +/// [`bytes`]: ../../std/primitive.str.html#method.bytes /// [`str`]: ../../std/primitive.str.html #[stable(feature = "rust1", since = "1.0.0")] #[derive(Clone, Debug)] @@ -1176,10 +1176,10 @@ generate_pattern_iterators! { /// An iterator over the lines of a string, as string slices. /// -/// This struct is created with the [`lines()`] method on [`str`]. +/// This struct is created with the [`lines`] method on [`str`]. /// See its documentation for more. /// -/// [`lines()`]: ../../std/primitive.str.html#method.lines +/// [`lines`]: ../../std/primitive.str.html#method.lines /// [`str`]: ../../std/primitive.str.html #[stable(feature = "rust1", since = "1.0.0")] #[derive(Clone, Debug)] diff --git a/src/libstd_unicode/u_str.rs b/src/libstd_unicode/u_str.rs index d3aa27b436d48..770b67acd49ef 100644 --- a/src/libstd_unicode/u_str.rs +++ b/src/libstd_unicode/u_str.rs @@ -20,10 +20,10 @@ use core::str::Split; /// An iterator over the non-whitespace substrings of a string, /// separated by any amount of whitespace. /// -/// This struct is created by the [`split_whitespace()`] method on [`str`]. +/// This struct is created by the [`split_whitespace`] method on [`str`]. /// See its documentation for more. /// -/// [`split_whitespace()`]: ../../std/primitive.str.html#method.split_whitespace +/// [`split_whitespace`]: ../../std/primitive.str.html#method.split_whitespace /// [`str`]: ../../std/primitive.str.html #[stable(feature = "split_whitespace", since = "1.1.0")] pub struct SplitWhitespace<'a> { From 0e2d3d41bb42abe1c40585d2ed06aea2840e664f Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Fri, 31 Mar 2017 16:59:01 +0200 Subject: [PATCH 19/19] Test sort algorithms using a random cmp function --- src/libcollectionstest/slice.rs | 16 +++++++++++++++- src/libcoretest/slice.rs | 12 ++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/libcollectionstest/slice.rs b/src/libcollectionstest/slice.rs index 00d4dbe9c0458..c3e5304fb2b35 100644 --- a/src/libcollectionstest/slice.rs +++ b/src/libcollectionstest/slice.rs @@ -383,9 +383,11 @@ fn test_reverse() { #[test] fn test_sort() { + let mut rng = thread_rng(); + for len in (2..25).chain(500..510) { for _ in 0..100 { - let mut v: Vec<_> = thread_rng().gen_iter::().take(len).collect(); + let mut v: Vec<_> = rng.gen_iter::().take(len).collect(); let mut v1 = v.clone(); v.sort(); @@ -399,6 +401,18 @@ fn test_sort() { } } + // Sort using a completely random comparison function. + // This will reorder the elements *somehow*, but won't panic. + let mut v = [0; 500]; + for i in 0..v.len() { + v[i] = i as i32; + } + v.sort_by(|_, _| *rng.choose(&[Less, Equal, Greater]).unwrap()); + v.sort(); + for i in 0..v.len() { + assert_eq!(v[i], i as i32); + } + // Should not panic. [0i32; 0].sort(); [(); 10].sort(); diff --git a/src/libcoretest/slice.rs b/src/libcoretest/slice.rs index 89bd3be08519c..ec38345030fa5 100644 --- a/src/libcoretest/slice.rs +++ b/src/libcoretest/slice.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use core::cmp::Ordering::{Equal, Greater, Less}; use core::slice::heapsort; use core::result::Result::{Ok, Err}; use rand::{Rng, XorShiftRng}; @@ -268,6 +269,17 @@ fn sort_unstable() { } } + // Sort using a completely random comparison function. + // This will reorder the elements *somehow*, but won't panic. + for i in 0..v.len() { + v[i] = i as i32; + } + v.sort_unstable_by(|_, _| *rng.choose(&[Less, Equal, Greater]).unwrap()); + v.sort_unstable(); + for i in 0..v.len() { + assert_eq!(v[i], i as i32); + } + // Should not panic. [0i32; 0].sort_unstable(); [(); 10].sort_unstable();