Skip to content

Commit 4b8f040

Browse files
committed
clippy fixes
Giving in, even though I am not so sure that `assert!(!a)` is truly an improvement over `assert_eq!(false, a)`
1 parent 7259116 commit 4b8f040

File tree

8 files changed

+35
-27
lines changed

8 files changed

+35
-27
lines changed

integration_tests/tests/bootloader_test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ async fn test_device_info_readback() {
3838
// Number of sections
3939
assert_eq!(1, client.read_u8(BOOTLOADER_INFO_INDEX, 2).await.unwrap());
4040

41-
assert_eq!(false, object_dict2::BOOTLOADER_INFO.reset_flag());
41+
assert!(!object_dict2::BOOTLOADER_INFO.reset_flag());
4242

4343
client
4444
.write_u32(BOOTLOADER_INFO_INDEX, 3, BOOTLOADER_RESET_CMD)
4545
.await
4646
.unwrap();
4747

48-
assert_eq!(true, object_dict2::BOOTLOADER_INFO.reset_flag());
48+
assert!(object_dict2::BOOTLOADER_INFO.reset_flag());
4949
};
5050

5151
test_with_background_process(&mut [&mut node], &mut bus.new_sender(), test_task).await;
@@ -144,9 +144,9 @@ async fn test_program() {
144144
.await
145145
.unwrap();
146146

147-
assert_eq!(true, callbacks.erase_flag());
147+
assert!(callbacks.erase_flag());
148148
assert_eq!(download_data, callbacks.data());
149-
assert_eq!(true, callbacks.finalize_flag())
149+
assert!(callbacks.finalize_flag())
150150
};
151151

152152
test_with_background_process(&mut [&mut node], &mut bus.new_sender(), test_task).await;

integration_tests/tests/sdo_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,12 @@ async fn test_domain_access() {
191191
.await
192192
.unwrap();
193193
assert_eq!([0xa, 0xb, 0xc, 0xd], domain.get_data()[0..4]);
194-
assert_eq!(false, domain.end_flag.load(Ordering::Relaxed));
194+
assert!(!domain.end_flag.load(Ordering::Relaxed));
195195

196196
// Do a large write
197197
client.block_download(0x3007, 0, &write_data).await.unwrap();
198198
assert_eq!(write_data, domain.get_data());
199-
assert_eq!(true, domain.end_flag.load(Ordering::Relaxed));
199+
assert!(domain.end_flag.load(Ordering::Relaxed));
200200

201201
// Do tooo large a write
202202
write_data.extend_from_slice(&[0]);

zencan-node/src/node_state.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ pub struct NodeState<const N_RPDO: usize, const N_TPDO: usize> {
2929
storage_context: StorageContext,
3030
}
3131

32+
impl<const N_RPDO: usize, const N_TPDO: usize> Default for NodeState<N_RPDO, N_TPDO> {
33+
fn default() -> Self {
34+
Self::new()
35+
}
36+
}
37+
3238
impl<const N_RPDO: usize, const N_TPDO: usize> NodeState<N_RPDO, N_TPDO> {
3339
/// Create a new NodeState object
3440
pub const fn new() -> Self {

zencan-node/src/object_dict/objects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ pub struct ODEntry<'a> {
407407
/// Lookup an object from the Object dictionary table
408408
///
409409
/// Note: `table` must be sorted by index
410-
pub fn find_object<'a, 'b>(table: &'b [ODEntry<'a>], index: u16) -> Option<&'a dyn ObjectAccess> {
410+
pub fn find_object<'a>(table: &[ODEntry<'a>], index: u16) -> Option<&'a dyn ObjectAccess> {
411411
find_object_entry(table, index).map(|entry| entry.data)
412412
}
413413

zencan-node/src/object_dict/sub_objects.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,12 @@ pub struct CallbackSubObject {
478478
handler: AtomicCell<Option<&'static dyn SubObjectAccess>>,
479479
}
480480

481+
impl Default for CallbackSubObject {
482+
fn default() -> Self {
483+
Self::new()
484+
}
485+
}
486+
481487
impl CallbackSubObject {
482488
/// Create a new object
483489
pub const fn new() -> Self {

zencan-node/src/pdo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl SubObjectAccess for PdoTransmissionTypeSubObject {
303303
}
304304

305305
fn write(&self, data: &[u8]) -> Result<(), AbortCode> {
306-
if data.len() < 1 {
306+
if data.is_empty() {
307307
Err(AbortCode::DataTypeMismatchLengthLow)
308308
} else {
309309
self.pdo.set_transmission_type(data[0]);
@@ -369,7 +369,7 @@ impl PdoMappingObject {
369369
impl ObjectAccess for PdoMappingObject {
370370
fn read(&self, sub: u8, offset: usize, buf: &mut [u8]) -> Result<usize, AbortCode> {
371371
if sub == 0 {
372-
if offset < 1 && buf.len() > 0 {
372+
if offset < 1 && !buf.is_empty() {
373373
buf[0] = self.pdo.valid_maps.load();
374374
Ok(1)
375375
} else {

zencan-node/src/sdo_server/sdo_receiver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl SdoReceiver {
158158
///
159159
/// This function will panic if the buffer has already been borrowed, or if the buffer was never
160160
/// set via `store_buffer`.
161-
pub(crate) fn borrow_buffer<'a>(&'a self) -> BufferGuard<'a> {
161+
pub(crate) fn borrow_buffer(&self) -> BufferGuard<'_> {
162162
let buf = self.buffer.take();
163163

164164
BufferGuard {

zencan-node/src/sdo_server/sdo_server.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ impl SdoState {
210210
Err(abort_code) => return SdoResult::abort(index, sub, abort_code),
211211
};
212212

213-
let response = if read_size <= 4 {
213+
214+
if read_size <= 4 {
214215
// Do expedited upload
215216
SdoResult::response(
216217
SdoResponse::expedited_upload(index, sub, &buf[..read_size]),
@@ -241,8 +242,7 @@ impl SdoState {
241242
bytes_in_buffer: ack_size,
242243
}),
243244
)
244-
};
245-
response
245+
}
246246
}
247247
SdoRequest::InitiateBlockDownload {
248248
cc,
@@ -362,22 +362,18 @@ impl SdoState {
362362
{
363363
return SdoResult::abort(state.object.index, state.sub, abort_code);
364364
}
365-
} else {
366-
if let Err(abort_code) =
367-
obj.write_partial(state.sub, &buf[..buffer_offset + segment_size])
368-
{
369-
return SdoResult::abort(state.object.index, state.sub, abort_code);
370-
}
371-
}
372-
if let Err(abort_code) = obj.end_partial(state.sub) {
365+
} else if let Err(abort_code) =
366+
obj.write_partial(state.sub, &buf[..buffer_offset + segment_size])
367+
{
373368
return SdoResult::abort(state.object.index, state.sub, abort_code);
374369
}
375-
} else {
376-
if let Err(abort_code) =
377-
obj.write(state.sub, &buf[0..buffer_offset + segment_size])
378-
{
370+
if let Err(abort_code) = obj.end_partial(state.sub) {
379371
return SdoResult::abort(state.object.index, state.sub, abort_code);
380372
}
373+
} else if let Err(abort_code) =
374+
obj.write(state.sub, &buf[0..buffer_offset + segment_size])
375+
{
376+
return SdoResult::abort(state.object.index, state.sub, abort_code);
381377
}
382378

383379
SdoResult::response_with_update(
@@ -803,7 +799,7 @@ mod tests {
803799
const SUB: u8 = 1;
804800
let mut round_trip = |msg_data: [u8; 8], elapsed| {
805801
rx.handle_req(&msg_data);
806-
server.process(&rx, elapsed, od)
802+
server.process(rx, elapsed, od)
807803
};
808804

809805
let msg = SdoRequest::initiate_block_download(INDEX, SUB, true, size as u32).to_bytes();
@@ -827,7 +823,7 @@ mod tests {
827823
while pos < size {
828824
let len = (size - pos).min(7);
829825
let mut chunk = [0; 7];
830-
chunk[0..len].copy_from_slice(&data[pos..pos + len as usize]);
826+
chunk[0..len].copy_from_slice(&data[pos..pos + len]);
831827

832828
pos += len;
833829
seqnum += 1;

0 commit comments

Comments
 (0)