8000 clippy: Document or fix all style lints by bradjc · Pull Request #4477 · tock/tock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

clippy: Document or fix all style lints #4477

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

Merged
merged 10 commits into from
Jun 23, 2025
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
32 changes: 21 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -179,35 +179,45 @@ zero_prefixed_literal = "allow"
# STYLE
style = { level = "deny", priority = -1 }

blocks_in_conditions = "allow"
# Sometimes an if block is standalone and shouldn't be merged with an else.
collapsible_else_if = "allow"
# Multiple if blocks can be clearer to express a particular logical flow.
collapsible_if = "allow"
collapsible_match = "allow"
# Sometimes if statements are easier to read than match statements.
comparison_chain = "allow"
# Sometimes it's more clear to have repetition in enum names.
enum-variant-names = "allow"
field-reassign-with-default = "allow"
# For buffers, `.get(0)` (using byte index) makes more sense than `.first()`.
get_first = "allow"
# Buffers and objects can have a length of 0, but it isn't necessarily intuitive
# to think of a buffer or those objects as "empty".
len_without_is_empty = "allow"
# Buffer logic often makes more sense with lengths, and not `is_empty()`.
len_zero = "allow"
# Sometimes the borrow checker works better with `match` instead of `.map()`.
manual-map = "allow"
# Syntax like `!(-17..=4).contains(&x)` is just not clear.
manual_range_contains = "allow"
# Match statement is clear, using `matches!()` is not an improvement.
match_like_matches_macro = "allow"
# Sometimes it makes sense to have module in a folder of the same name.
module_inception = "allow"
new-ret-no-self = "allow"
# Maybe someday we want this, but right now `for i in 0..4` is much more clear
# than using `.iter()` functions like `.skip(n)`.
needless-range-loop = "allow"
# We don't need unused Default implementations.
new_without_default = "allow"
redundant_closure = "allow"
# Using `Result()` is good practice, even if there is no meaning to the error.
result_unit_err = "allow"
single_match = "allow"
# For hardware registers it can make sense to group bits semantically and not
# just in multiples of four.
unusual-byte-groupings = "allow"
# We widely use upper case acronyms for hardware registers and fields.
upper_case_acronyms = "allow"


declare-interior-mutable-const = "allow"
let_and_return = "allow"
missing_safety_doc = "allow"
needless-range-loop = "allow"
option_map_or_none = "allow"
redundant_pattern_matching = "allow"
unusual-byte-groupings = "allow"
doc_lazy_continuation = "allow"


Expand Down
2 changes: 1 addition & 1 deletion arch/cortex-m/src/mpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl<const NUM_REGIONS: usize> CortexMConfig<NUM_REGIONS> {
if number <= APP_MEMORY_REGION_MAX_NUM {
continue;
}
if let None = region.location() {
if region.location().is_none() {
return Some(number);
}
}
Expand Down
6 changes: 2 additions & 4 deletions boards/nordic/nrf52_components/src/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,8 @@ impl Component for UartChannelComponent {
self.uarte0
}
UartChannel::Rtt(rtt_memory) => {
let rtt =
components::segger_rtt::SeggerRttComponent::new(self.mux_alarm, rtt_memory)
.finalize(s);
rtt
components::segger_rtt::SeggerRttComponent::new(self.mux_alarm, rtt_memory)
.finalize(s)
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions boards/nucleo_f429zi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,8 @@ unsafe fn start() -> (
));

// RTC DATE TIME
match peripherals.rtc.rtc_init() {
Err(e) => debug!("{:?}", e),
_ => (),
if let Err(e) = peripherals.rtc.rtc_init() {
debug!("{:?}", e)
}

let date_time = components::date_time::DateTimeComponent::new(
Expand Down
21 changes: 9 additions & 12 deletions capsules/core/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,16 @@ impl<'a> Console<'a> {
})
.unwrap_or(0);
app.write_remaining -= transaction_len;
match self.uart.transmit_buffer(buffer, transaction_len) {
Err((_e, tx_buffer)) => {
// The UART didn't start, so we will not get a transmit
// done callback. Need to signal the app now.
self.tx_buffer.replace(tx_buffer);
self.tx_in_progress.clear();
if let Err((_e, tx_buffer)) = self.uart.transmit_buffer(buffer, transaction_len) {
// The UART didn't start, so we will not get a transmit
// done callback. Need to signal the app now.
self.tx_buffer.replace(tx_buffer);
self.tx_in_progress.clear();

// Go ahead and signal the application
let written = app.write_len;
app.write_len = 0;
kernel_data.schedule_upcall(1, (written, 0, 0)).ok();
}
Ok(()) => {}
// Go ahead and signal the application
let written = app.write_len;
app.write_len = 0;
kernel_data.schedule_upcall(1, (written, 0, 0)).ok();
}
});
} else {
Expand Down
7 changes: 2 additions & 5 deletions capsules/core/src/process_console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,11 +1031,8 @@ impl<

fn prompt(&self) {
// Only display the prompt in active mode.
match self.mode.get() {
ProcessConsoleState::Active => {
let _ = self.write_bytes(b"tock$ ");
}
_ => {}
if self.mode.get() == ProcessConsoleState::Active {
let _ = self.write_bytes(b"tock$ ");
}
}

Expand Down
7 changes: 2 additions & 5 deletions capsules/core/src/virtualizers/virtual_flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,8 @@ impl<'a, F: hil::flash::Flash> MuxFlash<'a, F> {
node.buffer.take().map_or_else(
|| {
// Don't need a buffer for erase.
match node.operation.get() {
Op::Erase(page_number) => {
let _ = self.flash.erase_page(page_number);
}
_ => {}
if let Op::Erase(page_number) = node.operation.get() {
let _ = self.flash.erase_page(page_number);
}
},
|buf| {
Expand Down
14 changes: 5 additions & 9 deletions capsules/core/src/virtualizers/virtual_spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,11 @@ impl<'a, Spi: hil::spi::SpiMaster<'a>> MuxSpiMaster<'a, Spi> {
});
} else {
self.inflight.map(|node| {
match node.operation.get() {
// we have to report an error
Op::ReadWriteDone(status) => {
node.txbuffer.take().map(|write_buffer| {
let read_buffer = node.rxbuffer.take();
self.read_write_done(write_buffer, read_buffer, status);
});
}
_ => {} // Something is really in flight
if let Op::ReadWriteDone(status) = node.operation.get() {
node.txbuffer.take().map(|write_buffer| {
let read_buffer = node.rxbuffer.take();
self.read_write_done(write_buffer, read_buffer, status);
});
}
});
}
Expand Down
6 changes: 2 additions & 4 deletions capsules/extra/src/analog_comparator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ impl<'a, A: hil::analog_comparator::AnalogComparator<'a>> AnalogComparator<'a, A
}
// Convert channel index
let chan = self.channels[channel];
let result = self.analog_comparator.start_comparing(chan);

result
self.analog_comparator.start_comparing(chan)
}

// Stop comparing on a channel
Expand All @@ -105,9 +104,8 @@ impl<'a, A: hil::analog_comparator::AnalogComparator<'a>> AnalogComparator<'a, A
}
// Convert channel index
let chan = self.channels[channel];
let result = self.analog_comparator.stop_comparing(chan);

result
self.analog_comparator.stop_comparing(chan)
}
}

Expand Down
10 changes: 5 additions & 5 deletions capsules/extra/src/analog_sensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ impl<'a, A: hil::adc::Adc<'a>> AnalogLightSensor<'a, A> {
adc: &'a A,
channel: &'a <A as kernel::hil::adc::Adc<'a>>::Channel,
sensor_type: AnalogLightSensorType,
) -> AnalogLightSensor<'a, A> {
AnalogLightSensor {
) -> Self {
Self {
adc,
channel,
sensor_type,
Expand Down Expand Up @@ -82,9 +82,9 @@ impl<'a, A: hil::adc::Adc<'a>> AnalogTemperatureSensor<'a, A> {
pub fn new(
adc: &'a A,
channel: &'a <A as kernel::hil::adc::Adc<'a>>::Channel,
sensor_type: AnalogLightSensorType,
) -> AnalogLightSensor<'a, A> {
AnalogLightSensor {
sensor_type: AnalogTemperatureSensorType,
) -> Self {
Self {
Comment on lines -85 to +87
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it fixes a bug(?) where sensor_type had an incorrect type? Should probably be its own PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually even worse, we're constructing a completely wrong type here. Should definitely be its own PR.

adc,
channel,
sensor_type,
Expand Down
4 changes: 2 additions & 2 deletions capsules/extra/src/atecc508a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ impl Iterator for Atecc508aRngIter<'_, '_> {
type Item = u32;

fn next(&mut self) -> Option<u32> {
self.0.entropy_buffer.take().map_or(None, |entropy_buffer| {
self.0.entropy_buffer.take().map(|entropy_buffer| {
let offset = self.0.entropy_offset.get();
let entropy_bytes =
<[u8; 4]>::try_from(&entropy_buffer[(offset + 0)..(offset + 4)]).unwrap();
Expand All @@ -1215,7 +1215,7 @@ impl Iterator for Atecc508aRngIter<'_, '_> {
}
self.0.entropy_buffer.replace(entropy_buffer);

Some(entropy)
entropy
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion capsules/extra/src/date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl<'a, DateTime: date_time::DateTime<'a>> DateTimeCapsule<'a, DateTime> {
self.apps.iter().find_map(|grant| {
let processid = grant.processid();
grant.enter(|app, kernel| {
app.task.map_or(None, |command| {
app.task.and_then(|command| {
let command_return = self.call_driver(command, processid);
match command_return {
Ok(()) => Some(()),
Expand Down
2 changes: 1 addition & 1 deletion capsules/extra/src/ethernet_tap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ impl<'a, E: EthernetAdapterDatapath<'a>> EthernetTapDriver<'a, E> {
let _ = self.apps.enter(process_id, |grant, kernel_data| {
// If the application has allowed a "TX info" buffer, write some
// transmission metadata to it:
let ts_bytes = timestamp.map_or(u64::to_be_bytes(0), |ts| u64::to_be_bytes(ts));
let ts_bytes = timestamp.map_or(u64::to_be_bytes(0), u64::to_be_bytes);
let _ = kernel_data
.get_readwrite_processbuffer(rw_allow::TX_FRAME_INFO)
.and_then(|tx_frame_info| {
Expand Down
15 changes: 6 additions & 9 deletions capsules/extra/src/hs3003.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,13 @@ impl<'a, I: I2CDevice> Hs3003<'a, I> {
.take()
.map(|buffer| {
self.i2c.enable();
match self.state.get() {
State::Sleep => {
if let Err((_error, buffer)) = self.i2c.write(buffer, 1) {
self.buffer.replace(buffer);
self.i2c.disable();
} else {
self.state.set(State::InitiateReading);
}
if let State::Sleep = self.state.get() {
if let Err((_error, buffer)) = self.i2c.write(buffer, 1) {
self.buffer.replace(buffer);
self.i2c.disable();
} else {
self.state.set(State::InitiateReading);
}
_ => {}
}
})
.ok_or(ErrorCode::BUSY)
Expand Down
11 changes: 6 additions & 5 deletions capsules/extra/src/ieee802154/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ impl<'a, M: device::MacDevice<'a>> framer::DeviceProcedure for RadioDriver<'a, M
self.backup_device_procedure
.and_then(|procedure| procedure.lookup_addr_long(addr))
},
|res| Some(res),
Some,
)
}
}
Expand Down Expand Up @@ -609,7 +609,7 @@ impl<'a, M: device::MacDevice<'a>> framer::KeyProcedure for RadioDriver<'a, M> {
procedure.lookup_key(SecurityLevel::EncMic32, KeyId::Index(2))
})
},
|res| Some(res),
Some,
)
}
}
Expand Down Expand Up @@ -792,9 +792,10 @@ impl<'a, M: device::MacDevice<'a>> SyscallDriver for RadioDriver<'a, M> {
if cfg.len() != 8 {
return CommandReturn::failure(ErrorCode::SIZE);
}
let mut new_neighbor: DeviceDescriptor =
DeviceDescriptor::default();
new_neighbor.short_addr = arg1 as u16;
let mut new_neighbor = DeviceDescriptor {
short_addr: arg1 as u16,
..Default::default()
};
cfg.copy_to_slice(&mut new_neighbor.long_addr);
self.add_neighbor(new_neighbor)
.map_or(CommandReturn::failure(ErrorCode::INVAL), |index| {
Expand Down
39 changes: 18 additions & 21 deletions capsules/extra/src/isolated_nonvolatile_storage_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,31 +913,28 @@ impl<const APP_REGION_SIZE: usize> hil::nonvolatile_storage::NonvolatileStorageC
match user {
User::RegionManager(state) => {
self.buffer.replace(buffer);
match state {
ManagerTask::DiscoverRegions(address) => {
let res = self.header_read_done(address);
match res {
Ok(addr) => match addr {
Some(next_header_address) => {
self.current_user.set(User::RegionManager(
ManagerTask::DiscoverRegions(next_header_address),
));
}
None => {
// We finished the scan of existing
// regions. Now we can check the queue
// to see if there is any work to be
// done.
self.check_queue();
}
},
Err(_e) => {
// Not clear what to do here.
if let ManagerTask::DiscoverRegions(address) = state {
let res = self.header_read_done(address);
match res {
Ok(addr) => match addr {
Some(next_header_address) => {
self.current_user.set(User::RegionManager(
ManagerTask::DiscoverRegions(next_header_address),
));
}
None => {
// We finished the scan of existing
// regions. Now we can check the queue
// to see if there is any work to be
// done.
self.check_queue();
}
},
Err(_e) => {
// Not clear what to do here.
self.check_queue();
}
}
_ => {}
}
}
User::App { processid } => {
Expand Down
7 changes: 2 additions & 5 deletions capsules/extra/src/net/ieee802154.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,8 @@ impl Header<'_> {
stream_cond!(self.dst_addr.is_some() == self.dst_pan.is_some());
stream_cond!(self.src_addr.is_some() == self.src_pan.is_some());

match (self.dst_pan, self.src_pan) {
(Some(dst_pan), Some(src_pan)) => {
drop_src_pan = dst_pan == src_pan;
}
_ => {}
if let (Some(dst_pan), Some(src_pan)) = (self.dst_pan, self.src_pan) {
drop_src_pan = dst_pan == src_pan;
}
drop_src_pan
}
Expand Down
4 changes: 2 additions & 2 deletions capsules/extra/src/net/ipv6/ipv6_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ impl<'a, A: time::Alarm<'a>> IP6Sender<'a> for IP6SendStruct<'a, A> {
.init(self.src_mac_addr, dst_mac_addr, self.radio.get_pan(), None);

self.init_packet(dst, transport_header, payload);
let ret = self.send_next_fragment();
ret

self.send_next_fragment()
}
}

Expand Down
7 changes: 3 additions & 4 deletions capsules/extra/src/net/udp/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,9 @@ impl SyscallDriver for UDPDriver<'_> {
})
.unwrap_or_else(|err| Err(err.into()));
match res {
Ok(()) => self.do_next_tx_immediate(processid).map_or_else(
|err| CommandReturn::failure(err),
|v| CommandReturn::success_u32(v),
),
Ok(()) => self
.do_next_tx_immediate(processid)
.map_or_else(CommandReturn::failure, CommandReturn::success_u32),
Err(e) => CommandReturn::failure(e),
}
}
Expand Down
Loading
0