Skip to content

Commit 6db54e5

Browse files
committed
Fix clippy::if_not_else warnings
1 parent 739dbc4 commit 6db54e5

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

src/histbuf.rs

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

467-
if !self.filled {
468-
(buffer, &[])
469-
} else {
467+
if self.filled {
470468
(&buffer[self.write_at..], &buffer[..self.write_at])
469+
} else {
470+
(buffer, &[])
471471
}
472472
}
473473

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 & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,8 @@ where
364364
if self
365365
.read_data_in_node_at(head)
366366
.cmp(self.read_data_in_node_at(new))
367-
!= K::ordering()
367+
== K::ordering()
368368
{
369-
self.node_at_mut(new).next = self.head;
370-
self.head = Idx::new_unchecked(new);
371-
} else {
372369
// It's not head, search the list for the correct placement
373370
let mut current = head;
374371

@@ -386,6 +383,9 @@ where
386383

387384
self.node_at_mut(new).next = self.node_at(current).next;
388385
self.node_at_mut(current).next = Idx::new_unchecked(new);
386+
} else {
387+
self.node_at_mut(new).next = self.head;
388+
self.head = Idx::new_unchecked(new);
389389
}
390390
} else {
391391
self.node_at_mut(new).next = self.head;
@@ -417,11 +417,11 @@ where
417417
/// assert_eq!(ll.push(4), Err(4));
418418
/// ```
419419
pub fn push(&mut self, value: T) -> Result<(), T> {
420-
if !self.is_full() {
420+
if self.is_full() {
421+
Err(value)
422+
} else {
421423
unsafe { self.push_unchecked(value) }
422424
Ok(())
423-
} else {
424-
Err(value)
425425
}
426426
}
427427

@@ -572,10 +572,10 @@ where
572572
/// assert_eq!(ll.pop(), None);
573573
/// ```
574574
pub fn pop(&mut self) -> Option<T> {
575-
if !self.is_empty() {
576-
Some(unsafe { self.pop_unchecked() })
577-
} else {
575+
if self.is_empty() {
578576
None
577+
} else {
578+
Some(unsafe { self.pop_unchecked() })
579579
}
580580
}
581581

src/spsc.rs

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

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

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

285287
Ok(())
286-
} else {
287-
Err(val)
288288
}
289289
}
290290

0 commit comments

Comments
 (0)