Skip to content

Commit

Permalink
liballoc: fix some idiom lints.
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Feb 2, 2019
1 parent 95a9518 commit 857530c
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 87 deletions.
4 changes: 2 additions & 2 deletions src/liballoc/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl<B: ?Sized> fmt::Debug for Cow<'_, B>
where B: fmt::Debug + ToOwned,
<B as ToOwned>::Owned: fmt::Debug
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Borrowed(ref b) => fmt::Debug::fmt(b, f),
Owned(ref o) => fmt::Debug::fmt(o, f),
Expand All @@ -345,7 +345,7 @@ impl<B: ?Sized> fmt::Display for Cow<'_, B>
where B: fmt::Display + ToOwned,
<B as ToOwned>::Owned: fmt::Display
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Borrowed(ref b) => fmt::Display::fmt(b, f),
Owned(ref o) => fmt::Display::fmt(o, f),
Expand Down
6 changes: 3 additions & 3 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,21 +605,21 @@ impl Box<dyn Any + Send> {

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Display + ?Sized> fmt::Display for Box<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&**self, f)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Debug + ?Sized> fmt::Debug for Box<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&**self, f)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> fmt::Pointer for Box<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// It's not possible to extract the inner Uniq directly from the Box,
// instead we cast it to a *const which aliases the Unique
let ptr: *const T = &**self;
Expand Down
14 changes: 7 additions & 7 deletions src/liballoc/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ pub struct PeekMut<'a, T: 'a + Ord> {

#[stable(feature = "collection_debug", since = "1.17.0")]
impl<T: Ord + fmt::Debug> fmt::Debug for PeekMut<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("PeekMut")
.field(&self.heap.data[0])
.finish()
Expand Down Expand Up @@ -295,7 +295,7 @@ impl<T: Ord> Default for BinaryHeap<T> {

#[stable(feature = "binaryheap_debug", since = "1.4.0")]
impl<T: fmt::Debug + Ord> fmt::Debug for BinaryHeap<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_list().entries(self.iter()).finish()
}
}
Expand Down Expand Up @@ -353,7 +353,7 @@ impl<T: Ord> BinaryHeap<T> {
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter<T> {
pub fn iter(&self) -> Iter<'_, T> {
Iter { iter: self.data.iter() }
}

Expand Down Expand Up @@ -404,7 +404,7 @@ impl<T: Ord> BinaryHeap<T> {
/// assert_eq!(heap.peek(), Some(&2));
/// ```
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
pub fn peek_mut(&mut self) -> Option<PeekMut<T>> {
pub fn peek_mut(&mut self) -> Option<PeekMut<'_, T>> {
if self.is_empty() {
None
} else {
Expand Down Expand Up @@ -765,7 +765,7 @@ impl<T: Ord> BinaryHeap<T> {
/// ```
#[inline]
#[stable(feature = "drain", since = "1.6.0")]
pub fn drain(&mut self) -> Drain<T> {
pub fn drain(&mut self) -> Drain<'_, T> {
Drain { iter: self.data.drain(..) }
}

Expand Down Expand Up @@ -937,7 +937,7 @@ pub struct Iter<'a, T: 'a> {

#[stable(feature = "collection_debug", since = "1.17.0")]
impl<T: fmt::Debug> fmt::Debug for Iter<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("Iter")
.field(&self.iter.as_slice())
.finish()
Expand Down Expand Up @@ -1000,7 +1000,7 @@ pub struct IntoIter<T> {

#[stable(feature = "collection_debug", since = "1.17.0")]
impl<T: fmt::Debug> fmt::Debug for IntoIter<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("IntoIter")
.field(&self.iter.as_slice())
.finish()
Expand Down
34 changes: 17 additions & 17 deletions src/liballoc/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl<K, Q: ?Sized> super::Recover<Q> for BTreeMap<K, ()>

fn replace(&mut self, key: K) -> Option<K> {
self.ensure_root_is_owned();
match search::search_tree::<marker::Mut, K, (), K>(self.root.as_mut(), &key) {
match search::search_tree::<marker::Mut<'_>, K, (), K>(self.root.as_mut(), &key) {
Found(handle) => Some(mem::replace(handle.into_kv_mut().0, key)),
GoDown(handle) => {
VacantEntry {
Expand Down Expand Up @@ -280,7 +280,7 @@ pub struct Iter<'a, K: 'a, V: 'a> {

#[stable(feature = "collection_debug", since = "1.17.0")]
impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for Iter<'_, K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_list().entries(self.clone()).finish()
}
}
Expand Down Expand Up @@ -315,7 +315,7 @@ pub struct IntoIter<K, V> {

#[stable(feature = "collection_debug", since = "1.17.0")]
impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for IntoIter<K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let range = Range {
front: self.front.reborrow(),
back: self.back.reborrow(),
Expand All @@ -338,7 +338,7 @@ pub struct Keys<'a, K: 'a, V: 'a> {

#[stable(feature = "collection_debug", since = "1.17.0")]
impl<K: fmt::Debug, V> fmt::Debug for Keys<'_, K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_list().entries(self.clone()).finish()
}
}
Expand All @@ -357,7 +357,7 @@ pub struct Values<'a, K: 'a, V: 'a> {

#[stable(feature = "collection_debug", since = "1.17.0")]
impl<K, V: fmt::Debug> fmt::Debug for Values<'_, K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_list().entries(self.clone()).finish()
}
}
Expand Down Expand Up @@ -390,7 +390,7 @@ pub struct Range<'a, K: 'a, V: 'a> {

#[stable(feature = "collection_debug", since = "1.17.0")]
impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for Range<'_, K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_list().entries(self.clone()).finish()
}
}
Expand All @@ -413,7 +413,7 @@ pub struct RangeMut<'a, K: 'a, V: 'a> {

#[stable(feature = "collection_debug", since = "1.17.0")]
impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for RangeMut<'_, K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let range = Range {
front: self.front.reborrow(),
back: self.back.reborrow(),
Expand Down Expand Up @@ -443,7 +443,7 @@ pub enum Entry<'a, K: 'a, V: 'a> {

#[stable(feature= "debug_btree_map", since = "1.12.0")]
impl<K: Debug + Ord, V: Debug> Debug for Entry<'_, K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Vacant(ref v) => f.debug_tuple("Entry")
.field(v)
Expand Down Expand Up @@ -471,7 +471,7 @@ pub struct VacantEntry<'a, K: 'a, V: 'a> {

#[stable(feature= "debug_btree_map", since = "1.12.0")]
impl<K: Debug + Ord, V> Debug for VacantEntry<'_, K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("VacantEntry")
.field(self.key())
.finish()
Expand All @@ -494,7 +494,7 @@ pub struct OccupiedEntry<'a, K: 'a, V: 'a> {

#[stable(feature= "debug_btree_map", since = "1.12.0")]
impl<K: Debug + Ord, V: Debug> Debug for OccupiedEntry<'_, K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("OccupiedEntry")
.field("key", self.key())
.field("value", self.get())
Expand Down Expand Up @@ -818,7 +818,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// assert_eq!(Some((&5, &"b")), map.range(4..).next());
/// ```
#[stable(feature = "btree_range", since = "1.17.0")]
pub fn range<T: ?Sized, R>(&self, range: R) -> Range<K, V>
pub fn range<T: ?Sized, R>(&self, range: R) -> Range<'_, K, V>
where T: Ord, K: Borrow<T>, R: RangeBounds<T>
{
let root1 = self.root.as_ref();
Expand Down Expand Up @@ -859,7 +859,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// }
/// ```
#[stable(feature = "btree_range", since = "1.17.0")]
pub fn range_mut<T: ?Sized, R>(&mut self, range: R) -> RangeMut<K, V>
pub fn range_mut<T: ?Sized, R>(&mut self, range: R) -> RangeMut<'_, K, V>
where T: Ord, K: Borrow<T>, R: RangeBounds<T>
{
let root1 = self.root.as_mut();
Expand Down Expand Up @@ -892,7 +892,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// assert_eq!(count["a"], 3);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn entry(&mut self, key: K) -> Entry<K, V> {
pub fn entry(&mut self, key: K) -> Entry<'_, K, V> {
// FIXME(@porglezomp) Avoid allocating if we don't insert
self.ensure_root_is_owned();
match search::search_tree(self.root.as_mut(), &key) {
Expand Down Expand Up @@ -1783,7 +1783,7 @@ impl<K: Ord, V: Ord> Ord for BTreeMap<K, V> {

#[stable(feature = "rust1", since = "1.0.0")]
impl<K: Debug, V: Debug> Debug for BTreeMap<K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_map().entries(self.iter()).finish()
}
}
Expand Down Expand Up @@ -1940,7 +1940,7 @@ impl<K, V> BTreeMap<K, V> {
/// assert_eq!((*first_key, *first_value), (1, "a"));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter<K, V> {
pub fn iter(&self) -> Iter<'_, K, V> {
Iter {
range: Range {
front: first_leaf_edge(self.root.as_ref()),
Expand Down Expand Up @@ -1972,7 +1972,7 @@ impl<K, V> BTreeMap<K, V> {
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter_mut(&mut self) -> IterMut<K, V> {
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> {
let root1 = self.root.as_mut();
let root2 = unsafe { ptr::read(&root1) };
IterMut {
Expand Down Expand Up @@ -2049,7 +2049,7 @@ impl<K, V> BTreeMap<K, V> {
/// String::from("goodbye!")]);
/// ```
#[stable(feature = "map_values_mut", since = "1.10.0")]
pub fn values_mut(&mut self) -> ValuesMut<K, V> {
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> {
ValuesMut { inner: self.iter_mut() }
}

Expand Down
20 changes: 10 additions & 10 deletions src/liballoc/collections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl<K, V> Root<K, V> {
}

pub fn as_ref(&self)
-> NodeRef<marker::Immut, K, V, marker::LeafOrInternal> {
-> NodeRef<marker::Immut<'_>, K, V, marker::LeafOrInternal> {
NodeRef {
height: self.height,
node: self.node.as_ptr(),
Expand All @@ -240,7 +240,7 @@ impl<K, V> Root<K, V> {
}

pub fn as_mut(&mut self)
-> NodeRef<marker::Mut, K, V, marker::LeafOrInternal> {
-> NodeRef<marker::Mut<'_>, K, V, marker::LeafOrInternal> {
NodeRef {
height: self.height,
node: self.node.as_ptr(),
Expand All @@ -262,7 +262,7 @@ impl<K, V> Root<K, V> {
/// Adds a new internal node with a single edge, pointing to the previous root, and make that
/// new node the root. This increases the height by 1 and is the opposite of `pop_level`.
pub fn push_level(&mut self)
-> NodeRef<marker::Mut, K, V, marker::Internal> {
-> NodeRef<marker::Mut<'_>, K, V, marker::Internal> {
debug_assert!(!self.is_shared_root());
let mut new_node = Box::new(unsafe { InternalNode::new() });
new_node.edges[0].set(unsafe { BoxedNode::from_ptr(self.node.as_ptr()) });
Expand Down Expand Up @@ -535,7 +535,7 @@ impl<'a, K, V, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
/// Unsafely asserts to the compiler some static information about whether this
/// node is a `Leaf`.
unsafe fn cast_unchecked<NewType>(&mut self)
-> NodeRef<marker::Mut, K, V, NewType> {
-> NodeRef<marker::Mut<'_>, K, V, NewType> {

NodeRef {
height: self.height,
Expand All @@ -555,7 +555,7 @@ impl<'a, K, V, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
/// of a reborrowed handle, out of bounds.
// FIXME(@gereeter) consider adding yet another type parameter to `NodeRef` that restricts
// the use of `ascend` and `into_root_mut` on reborrowed pointers, preventing this unsafety.
unsafe fn reborrow_mut(&mut self) -> NodeRef<marker::Mut, K, V, Type> {
unsafe fn reborrow_mut(&mut self) -> NodeRef<marker::Mut<'_>, K, V, Type> {
NodeRef {
height: self.height,
node: self.node,
Expand Down Expand Up @@ -932,7 +932,7 @@ impl<BorrowType, K, V, NodeType, HandleType>

/// Temporarily takes out another, immutable handle on the same location.
pub fn reborrow(&self)
-> Handle<NodeRef<marker::Immut, K, V, NodeType>, HandleType> {
-> Handle<NodeRef<marker::Immut<'_>, K, V, NodeType>, HandleType> {

// We can't use Handle::new_kv or Handle::new_edge because we don't know our type
Handle {
Expand All @@ -957,7 +957,7 @@ impl<'a, K, V, NodeType, HandleType>
// FIXME(@gereeter) consider adding yet another type parameter to `NodeRef` that restricts
// the use of `ascend` and `into_root_mut` on reborrowed pointers, preventing this unsafety.
pub unsafe fn reborrow_mut(&mut self)
-> Handle<NodeRef<marker::Mut, K, V, NodeType>, HandleType> {
-> Handle<NodeRef<marker::Mut<'_>, K, V, NodeType>, HandleType> {

// We can't use Handle::new_kv or Handle::new_edge because we don't know our type
Handle {
Expand Down Expand Up @@ -1072,7 +1072,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
/// Unsafely asserts to the compiler some static information about whether the underlying
/// node of this handle is a `Leaf`.
unsafe fn cast_unchecked<NewType>(&mut self)
-> Handle<NodeRef<marker::Mut, K, V, NewType>, marker::Edge> {
-> Handle<NodeRef<marker::Mut<'_>, K, V, NewType>, marker::Edge> {

Handle::new_edge(self.node.cast_unchecked(), self.idx)
}
Expand Down Expand Up @@ -1562,8 +1562,8 @@ unsafe fn move_kv<K, V>(

// Source and destination must have the same height.
unsafe fn move_edges<K, V>(
mut source: NodeRef<marker::Mut, K, V, marker::Internal>, source_offset: usize,
mut dest: NodeRef<marker::Mut, K, V, marker::Internal>, dest_offset: usize,
mut source: NodeRef<marker::Mut<'_>, K, V, marker::Internal>, source_offset: usize,
mut dest: NodeRef<marker::Mut<'_>, K, V, marker::Internal>, dest_offset: usize,
count: usize)
{
let source_ptr = source.as_internal_mut().edges.as_mut_ptr();
Expand Down
Loading

0 comments on commit 857530c

Please sign in to comment.