Skip to content

Commit e56df16

Browse files
committed
Fix clippy::if_not_else warnings
1 parent 9da68d6 commit e56df16

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

src/histbuf.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,10 @@ impl<T, S: HistBufStorage<T> + ?Sized> HistoryBufferInner<T, S> {
463463
pub fn as_slices(&self) -> (&[T], &[T]) {
464464
let buffer = self.as_slice();
465465

466-
if !self.filled {
467-
(buffer, &[])
468-
} else {
466+
if self.filled {
469467
(&buffer[self.write_at..], &buffer[..self.write_at])
468+
} else {
469+
(buffer, &[])
470470
}
471471
}
472472

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@
147147
clippy::option_if_let_else,
148148
clippy::ptr_as_ptr,
149149
clippy::doc_markdown,
150-
clippy::semicolon_if_nothing_returned
150+
clippy::semicolon_if_nothing_returned,
151+
clippy::if_not_else
151152
)]
152153

153154
pub use binary_heap::BinaryHeap;

src/sorted_linked_list.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,7 @@ where
362362
// Check if we need to replace head
363363
if self
364364
.read_data_in_node_at(head)
365-
.cmp(self.read_data_in_node_at(new))
366-
!= K::ordering()
367-
{
368-
self.node_at_mut(new).next = self.head;
369-
self.head = Idx::new_unchecked(new);
370-
} else {
365+
.cmp(self.read_data_in_node_at(new)) == K::ordering() {
371366
// It's not head, search the list for the correct placement
372367
let mut current = head;
373368

@@ -385,6 +380,9 @@ where
385380

386381
self.node_at_mut(new).next = self.node_at(current).next;
387382
self.node_at_mut(current).next = Idx::new_unchecked(new);
383+
} else {
384+
self.node_at_mut(new).next = self.head;
385+
self.head = Idx::new_unchecked(new);
388386
}
389387
} else {
390388
self.node_at_mut(new).next = self.head;
@@ -416,11 +414,11 @@ where
416414
/// assert_eq!(ll.push(4), Err(4));
417415
/// ```
418416
pub fn push(&mut self, value: T) -> Result<(), T> {
419-
if !self.is_full() {
417+
if self.is_full() {
418+
Err(value)
419+
} else {
420420
unsafe { self.push_unchecked(value) }
421421
Ok(())
422-
} else {
423-
Err(value)
424422
}
425423
}
426424

@@ -571,10 +569,10 @@ where
571569
/// assert_eq!(ll.pop(), None);
572570
/// ```
573571
pub fn pop(&mut self) -> Option<T> {
574-
if !self.is_empty() {
575-
Some(unsafe { self.pop_unchecked() })
576-
} else {
572+
if self.is_empty() {
577573
None
574+
} else {
575+
Some(unsafe { self.pop_unchecked() })
578576
}
579577
}
580578

src/spsc.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,11 @@ impl<T, S: Storage> QueueInner<T, S> {
262262
/// assert_eq!(None, consumer.peek());
263263
/// ```
264264
pub fn peek(&self) -> Option<&T> {
265-
if !self.is_empty() {
265+
if self.is_empty() {
266+
None
267+
} else {
266268
let head = self.head.load(Ordering::Relaxed);
267269
Some(unsafe { &*(self.buffer.borrow().get_unchecked(head).get() as *const T) })
268-
} else {
269-
None
270270
}
271271
}
272272

@@ -277,13 +277,13 @@ impl<T, S: Storage> QueueInner<T, S> {
277277
let current_tail = self.tail.load(Ordering::Relaxed);
278278
let next_tail = self.increment(current_tail);
279279

280-
if next_tail != self.head.load(Ordering::Acquire) {
280+
if next_tail == self.head.load(Ordering::Acquire) {
281+
Err(val)
282+
} else {
281283
(self.buffer.borrow().get_unchecked(current_tail).get()).write(MaybeUninit::new(val));
282284
self.tail.store(next_tail, Ordering::Release);
283285

284286
Ok(())
285-
} else {
286-
Err(val)
287287
}
288288
}
289289

0 commit comments

Comments
 (0)