Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix few Clippy warnings #62806

Merged
merged 2 commits into from
Jul 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/liballoc/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl<K: Clone, V: Clone> Clone for BTreeMap<K, V> {
}
}

if self.len() == 0 {
if self.is_empty() {
// Ideally we'd call `BTreeMap::new` here, but that has the `K:
// Ord` constraint, which this method lacks.
BTreeMap {
Expand Down Expand Up @@ -759,12 +759,12 @@ impl<K: Ord, V> BTreeMap<K, V> {
#[stable(feature = "btree_append", since = "1.11.0")]
pub fn append(&mut self, other: &mut Self) {
// Do we have to append anything at all?
if other.len() == 0 {
if other.is_empty() {
return;
}

// We can just swap `self` and `other` if `self` is empty.
if self.len() == 0 {
if self.is_empty() {
mem::swap(self, other);
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/liballoc/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,15 @@ impl<T> LinkedList<T> {

// Not creating new mutable (unique!) references overlapping `element`.
match node.prev {
Some(prev) => (*prev.as_ptr()).next = node.next.clone(),
Some(prev) => (*prev.as_ptr()).next = node.next,
// this node is the head node
None => self.head = node.next.clone(),
None => self.head = node.next,
};

match node.next {
Some(next) => (*next.as_ptr()).prev = node.prev.clone(),
Some(next) => (*next.as_ptr()).prev = node.prev,
// this node is the tail node
None => self.tail = node.prev.clone(),
None => self.tail = node.prev,
};

self.len -= 1;
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ impl<T> Rc<[T]> {
let slice = from_raw_parts_mut(self.elems, self.n_elems);
ptr::drop_in_place(slice);

Global.dealloc(self.mem, self.layout.clone());
Global.dealloc(self.mem, self.layout);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ impl<T> Arc<[T]> {
let slice = from_raw_parts_mut(self.elems, self.n_elems);
ptr::drop_in_place(slice);

Global.dealloc(self.mem.cast(), self.layout.clone());
Global.dealloc(self.mem.cast(), self.layout);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,11 +827,11 @@ pub unsafe trait Alloc {
let old_size = layout.size();

if new_size >= old_size {
if let Ok(()) = self.grow_in_place(ptr, layout.clone(), new_size) {
if let Ok(()) = self.grow_in_place(ptr, layout, new_size) {
return Ok(ptr);
}
} else if new_size < old_size {
if let Ok(()) = self.shrink_in_place(ptr, layout.clone(), new_size) {
if let Ok(()) = self.shrink_in_place(ptr, layout, new_size) {
return Ok(ptr);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/str/lossy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<'a> Iterator for Utf8LossyChunksIter<'a> {
type Item = Utf8LossyChunk<'a>;

fn next(&mut self) -> Option<Utf8LossyChunk<'a>> {
if self.source.len() == 0 {
if self.source.is_empty() {
return None;
}

Expand Down Expand Up @@ -141,7 +141,7 @@ impl fmt::Display for Utf8Lossy {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// If we're the empty string then our iterator won't actually yield
// anything, so perform the formatting manually
if self.bytes.len() == 0 {
if self.bytes.is_empty() {
return "".fmt(f)
}

Expand Down
4 changes: 2 additions & 2 deletions src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ impl<T: Read, U: Read> Read for Chain<T, U> {
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
if !self.done_first {
match self.first.read(buf)? {
0 if buf.len() != 0 => self.done_first = true,
0 if !buf.is_empty() => self.done_first = true,
n => return Ok(n),
}
}
Expand Down Expand Up @@ -1955,7 +1955,7 @@ impl<T: BufRead, U: BufRead> BufRead for Chain<T, U> {
fn fill_buf(&mut self) -> Result<&[u8]> {
if !self.done_first {
match self.first.fill_buf()? {
buf if buf.len() == 0 => { self.done_first = true; }
buf if buf.is_empty() => { self.done_first = true; }
buf => return Ok(buf),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/unix/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ unsafe impl GlobalAlloc for System {
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
libc::calloc(layout.size(), 1) as *mut u8
} else {
let ptr = self.alloc(layout.clone());
let ptr = self.alloc(layout);
if !ptr.is_null() {
ptr::write_bytes(ptr, 0, layout.size());
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl Command {
if self.get_gid().is_some() ||
self.get_uid().is_some() ||
self.env_saw_path() ||
self.get_closures().len() != 0 {
!self.get_closures().is_empty() {
return Ok(None)
}

Expand Down