Skip to content

Commit d7306db

Browse files
committed
Fix clippy lints
1 parent ee14cda commit d7306db

File tree

15 files changed

+120
-66
lines changed

15 files changed

+120
-66
lines changed

.github/workflows/build.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ jobs:
101101
- name: cargo fmt --check
102102
run: cargo fmt --all -- --check
103103

104+
clippy:
105+
runs-on: ubuntu-latest
106+
steps:
107+
- name: Checkout
108+
uses: actions/checkout@v4
109+
- name: Install Rust
110+
uses: dtolnay/rust-toolchain@stable
111+
with:
112+
components: clippy
113+
targets: i686-unknown-linux-gnu
114+
- run: cargo clippy --all --target i686-unknown-linux-gnu -- --deny warnings
115+
104116
# Compilation check
105117
check:
106118
name: check

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10-
- configure `stable_deref_trait` as a platform-dependent dependency
10+
### Changed
11+
12+
- Changed `stable_deref_trait` to a platform-dependent dependency.
13+
14+
### Fixed
15+
16+
- Fixed clippy lints.
1117

1218
## [v0.8.0] - 2023-11-07
1319

src/binary_heap.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ where
233233
/// assert_eq!(heap.peek(), Some(&5));
234234
/// ```
235235
pub fn peek(&self) -> Option<&T> {
236-
self.data.as_slice().get(0)
236+
self.data.as_slice().first()
237237
}
238238

239239
/// Returns a mutable reference to the greatest item in the binary heap, or
@@ -297,6 +297,7 @@ where
297297

298298
/// Removes the *top* (greatest if max-heap, smallest if min-heap) item from the binary heap and
299299
/// returns it, without checking if the binary heap is empty.
300+
#[allow(clippy::missing_safety_doc)] // TODO
300301
pub unsafe fn pop_unchecked(&mut self) -> T {
301302
let mut item = self.data.pop_unchecked();
302303

@@ -330,6 +331,7 @@ where
330331
}
331332

332333
/// Pushes an item onto the binary heap without first checking if it's full.
334+
#[allow(clippy::missing_safety_doc)] // TODO
333335
pub unsafe fn push_unchecked(&mut self, item: T) {
334336
let old_len = self.len();
335337
self.data.push_unchecked(item);

src/deque.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl<T, const N: usize> Deque<T, N> {
283283
let index = self.front;
284284
self.full = false;
285285
self.front = Self::increment(self.front);
286-
(self.buffer.get_unchecked_mut(index).as_ptr() as *const T).read()
286+
self.buffer.get_unchecked_mut(index).as_ptr().read()
287287
}
288288

289289
/// Removes an item from the back of the deque and returns it, without checking that the deque
@@ -297,7 +297,7 @@ impl<T, const N: usize> Deque<T, N> {
297297

298298
self.full = false;
299299
self.back = Self::decrement(self.back);
300-
(self.buffer.get_unchecked_mut(self.back).as_ptr() as *const T).read()
300+
self.buffer.get_unchecked_mut(self.back).as_ptr().read()
301301
}
302302

303303
/// Appends an `item` to the front of the deque

src/histbuf.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ impl<T, const N: usize> HistoryBuffer<T, N> {
117117
}
118118
}
119119

120+
/// Returns true if the buffer is empty.
121+
///
122+
/// # Examples
123+
///
124+
/// ```
125+
/// use heapless::HistoryBuffer;
126+
///
127+
/// let x: HistoryBuffer<u8, 16> = HistoryBuffer::new();
128+
/// assert!(x.is_empty());
129+
/// ```
130+
#[inline]
131+
pub fn is_empty(&self) -> bool {
132+
self.len() == 0
133+
}
134+
120135
/// Returns the capacity of the buffer, which is the length of the
121136
/// underlying backing array.
122137
#[inline]
@@ -219,7 +234,7 @@ impl<T, const N: usize> HistoryBuffer<T, N> {
219234
/// }
220235
///
221236
/// ```
222-
pub fn oldest_ordered<'a>(&'a self) -> OldestOrdered<'a, T, N> {
237+
pub fn oldest_ordered(&self) -> OldestOrdered<'_, T, N> {
223238
if self.filled {
224239
OldestOrdered {
225240
buf: self,

src/indexmap.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::{
22
borrow::Borrow,
33
fmt,
4-
hash::{BuildHasher, Hash, Hasher as _},
4+
hash::{BuildHasher, Hash},
55
iter::FromIterator,
66
mem,
77
num::NonZeroU32,
@@ -64,7 +64,7 @@ impl HashValue {
6464
}
6565

6666
fn probe_distance(&self, mask: usize, current: usize) -> usize {
67-
current.wrapping_sub(self.desired_pos(mask) as usize) & mask
67+
current.wrapping_sub(self.desired_pos(mask)) & mask
6868
}
6969
}
7070

@@ -364,7 +364,7 @@ where
364364
fn clone(&self) -> Self {
365365
Self {
366366
entries: self.entries.clone(),
367-
indices: self.indices.clone(),
367+
indices: self.indices,
368368
}
369369
}
370370
}
@@ -961,7 +961,7 @@ where
961961
K: Borrow<Q>,
962962
Q: ?Sized + Hash + Eq,
963963
{
964-
if self.len() == 0 {
964+
if self.is_empty() {
965965
return None;
966966
}
967967
let h = hash_with(key, &self.build_hasher);
@@ -1238,9 +1238,7 @@ where
12381238
K: ?Sized + Hash,
12391239
S: BuildHasher,
12401240
{
1241-
let mut h = build_hasher.build_hasher();
1242-
key.hash(&mut h);
1243-
HashValue(h.finish() as u16)
1241+
HashValue(build_hasher.hash_one(key) as u16)
12441242
}
12451243

12461244
#[cfg(test)]

src/linear_map.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ pub struct Iter<'a, K, V> {
448448
impl<'a, K, V> Iterator for Iter<'a, K, V> {
449449
type Item = (&'a K, &'a V);
450450

451+
#[allow(clippy::needless_borrowed_reference)]
451452
fn next(&mut self) -> Option<Self::Item> {
452453
self.iter.next().map(|&(ref k, ref v)| (k, v))
453454
}

src/mpmc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ impl<T, const N: usize> MpMcQueue<T, N> {
145145
crate::sealed::power_of_two::<N>();
146146

147147
// Const assert on size.
148-
Self::ASSERT[!(N < (IntSize::MAX as usize)) as usize];
148+
#[allow(clippy::no_effect)]
149+
Self::ASSERT[(N >= (IntSize::MAX as usize)) as usize];
149150

150151
let mut cell_count = 0;
151152

@@ -204,6 +205,7 @@ impl<T> Cell<T> {
204205
}
205206
}
206207

208+
#[allow(clippy::comparison_chain)]
207209
unsafe fn dequeue<T>(
208210
buffer: *mut Cell<T>,
209211
dequeue_pos: &AtomicTargetSize,
@@ -243,6 +245,7 @@ unsafe fn dequeue<T>(
243245
Some(data)
244246
}
245247

248+
#[allow(clippy::comparison_chain)]
246249
unsafe fn enqueue<T>(
247250
buffer: *mut Cell<T>,
248251
enqueue_pos: &AtomicTargetSize,

src/pool/arc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ where
221221
P: ArcPool,
222222
{
223223
fn as_ref(&self) -> &P::Data {
224-
&**self
224+
self
225225
}
226226
}
227227

src/sealed.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
1-
#[allow(dead_code)]
2-
#[allow(path_statements)]
1+
#[allow(dead_code, path_statements, clippy::no_effect)]
32
pub(crate) const fn smaller_than<const N: usize, const MAX: usize>() {
43
Assert::<N, MAX>::LESS;
54
}
65

7-
#[allow(dead_code)]
8-
#[allow(path_statements)]
6+
#[allow(dead_code, path_statements, clippy::no_effect)]
97
pub(crate) const fn greater_than_eq_0<const N: usize>() {
108
Assert::<N, 0>::GREATER_EQ;
119
}
1210

13-
#[allow(dead_code)]
14-
#[allow(path_statements)]
11+
#[allow(dead_code, path_statements, clippy::no_effect)]
1512
pub(crate) const fn greater_than_0<const N: usize>() {
1613
Assert::<N, 0>::GREATER;
1714
}
1815

19-
#[allow(dead_code)]
20-
#[allow(path_statements)]
16+
#[allow(dead_code, path_statements, clippy::no_effect)]
2117
pub(crate) const fn greater_than_1<const N: usize>() {
2218
Assert::<N, 1>::GREATER;
2319
}
2420

25-
#[allow(dead_code)]
26-
#[allow(path_statements)]
21+
#[allow(dead_code, path_statements, clippy::no_effect)]
2722
pub(crate) const fn power_of_two<const N: usize>() {
2823
Assert::<N, 0>::GREATER;
2924
Assert::<N, 0>::POWER_OF_TWO;
@@ -42,6 +37,7 @@ impl<const L: usize, const R: usize> Assert<L, R> {
4237
pub const LESS_EQ: usize = R - L;
4338

4439
/// Const assert hack
40+
#[allow(clippy::erasing_op)]
4541
pub const NOT_EQ: isize = 0 / (R as isize - L as isize);
4642

4743
/// Const assert hack

0 commit comments

Comments
 (0)