Skip to content

Commit 33da10c

Browse files
committed
Use let chains where possible
1 parent 5c55a03 commit 33da10c

13 files changed

Lines changed: 152 additions & 159 deletions

File tree

build/i2c/src/lib.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,12 @@ impl ConfigGenerator {
538538
// their bus.
539539
//
540540
for (index, (p, port)) in c.ports.iter().enumerate() {
541-
if let Some(name) = &port.name {
542-
if buses
541+
if let Some(name) = &port.name
542+
&& buses
543543
.insert(name.clone(), (c.controller, index))
544544
.is_some()
545-
{
546-
panic!("i2c bus {name} appears twice");
547-
}
545+
{
546+
panic!("i2c bus {name} appears twice");
548547
}
549548

550549
if c.ports.len() == 1 {
@@ -1011,10 +1010,10 @@ impl ConfigGenerator {
10111010
by_bus.insert((&d.device, bus), d);
10121011
}
10131012

1014-
if let Some(name) = &d.name {
1015-
if by_name.insert((&d.device, name), d).is_some() {
1016-
panic!("duplicate name {} for device {}", name, d.device)
1017-
}
1013+
if let Some(name) = &d.name
1014+
&& by_name.insert((&d.device, name), d).is_some()
1015+
{
1016+
panic!("duplicate name {} for device {}", name, d.device)
10181017
}
10191018
if let Some(refdes) = &d.refdes {
10201019
if by_refdes.insert((&d.device, refdes), d).is_some() {
@@ -1241,10 +1240,10 @@ impl ConfigGenerator {
12411240
println!("cargo::rerun-if-changed={}", dir.join("src").display());
12421241

12431242
for entry in std::fs::read_dir(dir.join("src"))? {
1244-
if let Some(f) = entry?.path().file_name() {
1245-
if let Some(name) = f.to_str().unwrap().strip_suffix(".rs") {
1246-
drivers.insert(name.to_string());
1247-
}
1243+
if let Some(f) = entry?.path().file_name()
1244+
&& let Some(name) = f.to_str().unwrap().strip_suffix(".rs")
1245+
{
1246+
drivers.insert(name.to_string());
12481247
}
12491248
}
12501249

drv/psc-psu-update/src/main.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,14 @@ impl Psu {
233233

234234
if let (Some(started), Some(backoff)) =
235235
(self.update_started, self.update_backoff)
236+
&& started + backoff > now
236237
{
237-
if started + backoff > now {
238-
//
239-
// Indicate we are backing off, but in a way that won't flood
240-
// the ring buffer with the backing off of a single PSU.
241-
//
242-
ringbuf_entry!(Trace::BackingOff(ndx));
243-
return false;
244-
}
238+
//
239+
// Indicate we are backing off, but in a way that won't flood
240+
// the ring buffer with the backing off of a single PSU.
241+
//
242+
ringbuf_entry!(Trace::BackingOff(ndx));
243+
return false;
245244
}
246245

247246
true

drv/sidecar-seq-server/src/main.rs

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -276,50 +276,48 @@ impl ServerImpl {
276276
}
277277

278278
fn actually_reset_front_io_phy(&mut self) -> Result<(), SeqError> {
279-
if let Some(front_io_board) = self.front_io_board.as_mut() {
280-
if front_io_board.initialized() {
281-
// The board was initialized prior and this function is called
282-
// by the monorail task because it is initializing the front IO
283-
// PHY. Unfortunately some front IO boards have PHY oscillators
284-
// which do not start reliably when their enable pin is used and
285-
// the only way to resolve this is by power cycling the front IO
286-
// board. But power cycling the board also bounces any QSFP
287-
// transceivers which may be running, so this function attempts
288-
// to determine what the monorail task wants to do.
289-
//
290-
// Whether or not the PHY oscillator was found to be operating
291-
// nominally is recorded in the front IO board controller. Look
292-
// up what this value is to determine if a power reset of the
293-
// front IO board is needed.
294-
match front_io_board.phy().osc_state()? {
295-
PhyOscState::Bad => {
296-
// The PHY was attempted to be initialized but its
297-
// oscillator was deemed not functional. Unfortunately
298-
// the only course of action is to power cycle the
299-
// entire front IO board, so do so now.
300-
self.front_io_hsc.set_enable(false)?;
301-
ringbuf_entry!(Trace::FrontIOBoardPowerEnable(false));
302-
303-
// Wait some cool down period to allow caps to bleed off
304-
// etc.
305-
userlib::hl::sleep_for(1000);
306-
}
307-
PhyOscState::Good => {
308-
// The PHY was initialized properly before and its
309-
// oscillator declared operating nominally. Assume this
310-
// has not changed and only a reset the PHY itself is
311-
// desired.
312-
front_io_board.phy().set_phy_power_enabled(false)?;
313-
ringbuf_entry!(Trace::FrontIOBoardPhyPowerEnable(
314-
false
315-
));
316-
317-
userlib::hl::sleep_for(10);
318-
}
319-
PhyOscState::Unknown => {
320-
// Do nothing (yet) since the oscillator state is
321-
// unknown.
322-
}
279+
if let Some(front_io_board) = self.front_io_board.as_mut()
280+
&& front_io_board.initialized()
281+
{
282+
// The board was initialized prior and this function is called
283+
// by the monorail task because it is initializing the front IO
284+
// PHY. Unfortunately some front IO boards have PHY oscillators
285+
// which do not start reliably when their enable pin is used and
286+
// the only way to resolve this is by power cycling the front IO
287+
// board. But power cycling the board also bounces any QSFP
288+
// transceivers which may be running, so this function attempts
289+
// to determine what the monorail task wants to do.
290+
//
291+
// Whether or not the PHY oscillator was found to be operating
292+
// nominally is recorded in the front IO board controller. Look
293+
// up what this value is to determine if a power reset of the
294+
// front IO board is needed.
295+
match front_io_board.phy().osc_state()? {
296+
PhyOscState::Bad => {
297+
// The PHY was attempted to be initialized but its
298+
// oscillator was deemed not functional. Unfortunately
299+
// the only course of action is to power cycle the
300+
// entire front IO board, so do so now.
301+
self.front_io_hsc.set_enable(false)?;
302+
ringbuf_entry!(Trace::FrontIOBoardPowerEnable(false));
303+
304+
// Wait some cool down period to allow caps to bleed off
305+
// etc.
306+
userlib::hl::sleep_for(1000);
307+
}
308+
PhyOscState::Good => {
309+
// The PHY was initialized properly before and its
310+
// oscillator declared operating nominally. Assume this
311+
// has not changed and only a reset the PHY itself is
312+
// desired.
313+
front_io_board.phy().set_phy_power_enabled(false)?;
314+
ringbuf_entry!(Trace::FrontIOBoardPhyPowerEnable(false));
315+
316+
userlib::hl::sleep_for(10);
317+
}
318+
PhyOscState::Unknown => {
319+
// Do nothing (yet) since the oscillator state is
320+
// unknown.
323321
}
324322
}
325323
}
@@ -853,10 +851,10 @@ impl NotificationHandler for ServerImpl {
853851
// Currently, we will only resequence a single time to resolve the problem.
854852
match self.tofino.sequencer.state().unwrap_or(TofinoSeqState::A2) {
855853
TofinoSeqState::A0 => {
856-
if !self.resequenced {
857-
if let Err(e) = self.monitor_tofino_pcie_link() {
858-
ringbuf_entry!(Trace::TofinoSequencerError(e));
859-
}
854+
if !self.resequenced
855+
&& let Err(e) = self.monitor_tofino_pcie_link()
856+
{
857+
ringbuf_entry!(Trace::TofinoSequencerError(e));
860858
}
861859
}
862860
// If we're not in A0, make sure next time we go into A0 we will attempt to

drv/stm32h7-spi-server-core/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ impl SpiServerCore {
312312

313313
// If we are locked, check that the caller isn't mistakenly
314314
// addressing the wrong device.
315-
if let Some(lockstate) = &self.lock_holder.get() {
316-
if lockstate.device_index != device_index {
317-
return Err(TransferError::BadDevice);
318-
}
315+
if let Some(lockstate) = &self.lock_holder.get()
316+
&& lockstate.device_index != device_index
317+
{
318+
return Err(TransferError::BadDevice);
319319
}
320320

321321
// Reject out-of-range devices.
@@ -508,11 +508,11 @@ impl SpiServerCore {
508508

509509
// Deposit the byte if we're still within the bounds of the
510510
// caller's incoming lease.
511-
if let Some(rx_reader) = &mut rx {
512-
if rx_reader.write(b).is_err() {
513-
// We're off the end. Stop checking.
514-
rx = None;
515-
}
511+
if let Some(rx_reader) = &mut rx
512+
&& rx_reader.write(b).is_err()
513+
{
514+
// We're off the end. Stop checking.
515+
rx = None;
516516
}
517517

518518
// By releasing a TX permit, we might have unblocked the TX

drv/stm32xx-i2c/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,10 +716,10 @@ impl I2cController<'_> {
716716
let mut pos = 0;
717717

718718
loop {
719-
if let ReadLength::Fixed(rlen) = rlen {
720-
if pos >= rlen {
721-
break;
722-
}
719+
if let ReadLength::Fixed(rlen) = rlen
720+
&& pos >= rlen
721+
{
722+
break;
723723
}
724724

725725
loop {

lib/counters/derive/src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,11 @@ impl<'input> CountGenerator<'input> {
285285
#variant_name: <#variant_type as counters::Count>::NEW_COUNTERS
286286
});
287287
where_clause_types.insert(variant_type.clone());
288-
if let syn::Type::Path(ty_path) = variant_type {
289-
if let Some(ident) = ty_path.path.get_ident() {
290-
if all_generics.contains(ident) {
291-
needed_generics.insert(ident.clone());
292-
}
293-
}
288+
if let syn::Type::Path(ty_path) = variant_type
289+
&& let Some(ident) = ty_path.path.get_ident()
290+
&& all_generics.contains(ident)
291+
{
292+
needed_generics.insert(ident.clone());
294293
}
295294
}
296295
}

sys/kern/src/task.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ impl Task {
238238

239239
// We only need to check the mask, and make updates, if the task is
240240
// ready to hear about notifications.
241-
if self.state.can_accept_notification() {
242-
if let Some(firing) = self.take_notifications() {
243-
// A bit the task is interested in has newly become set!
244-
// Interrupt it.
245-
self.save.set_recv_result(TaskId::KERNEL, firing, 0, 0, 0);
246-
self.state = TaskState::Healthy(SchedState::Runnable);
247-
return true;
248-
}
241+
if self.state.can_accept_notification()
242+
&& let Some(firing) = self.take_notifications()
243+
{
244+
// A bit the task is interested in has newly become set!
245+
// Interrupt it.
246+
self.save.set_recv_result(TaskId::KERNEL, firing, 0, 0, 0);
247+
self.state = TaskState::Healthy(SchedState::Runnable);
248+
return true;
249249
}
250250
false
251251
}
@@ -776,16 +776,16 @@ impl NextTask {
776776
pub fn process_timers(tasks: &mut [Task], current_time: Timestamp) -> NextTask {
777777
let mut sched_hint = NextTask::Same;
778778
for (index, task) in tasks.iter_mut().enumerate() {
779-
if let Some(deadline) = task.timer.deadline {
780-
if deadline <= current_time {
781-
task.timer.deadline = None;
782-
let task_hint = if task.post(task.timer.to_post) {
783-
NextTask::Specific(index)
784-
} else {
785-
NextTask::Same
786-
};
787-
sched_hint = sched_hint.combine(task_hint)
788-
}
779+
if let Some(deadline) = task.timer.deadline
780+
&& deadline <= current_time
781+
{
782+
task.timer.deadline = None;
783+
let task_hint = if task.post(task.timer.to_post) {
784+
NextTask::Specific(index)
785+
} else {
786+
NextTask::Same
787+
};
788+
sched_hint = sched_hint.combine(task_hint)
789789
}
790790
}
791791
sched_hint
@@ -859,10 +859,10 @@ pub fn priority_scan(
859859
continue;
860860
}
861861

862-
if let Some((_, best_task)) = choice {
863-
if !t.priority.is_more_important_than(best_task.priority) {
864-
continue;
865-
}
862+
if let Some((_, best_task)) = choice
863+
&& !t.priority.is_more_important_than(best_task.priority)
864+
{
865+
continue;
866866
}
867867

868868
choice = Some((pos, t));

task/control-plane-agent/src/mgs_sidecar.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ impl MgsHandler {
190190

191191
let now = sys_get_timer().now;
192192
for (vid, k) in self.locked.clone().iter() {
193-
if let LockState::UnlockedUntil(lock_at) = k {
194-
if now >= *lock_at {
195-
ringbuf_entry!(Trace::TimedRelock { vid });
196-
if let Err(e) = self.lock(vid) {
197-
ringbuf_entry!(Trace::TimedLockFailed(e));
198-
}
193+
if let LockState::UnlockedUntil(lock_at) = k
194+
&& now >= *lock_at
195+
{
196+
ringbuf_entry!(Trace::TimedRelock { vid });
197+
if let Err(e) = self.lock(vid) {
198+
ringbuf_entry!(Trace::TimedLockFailed(e));
199199
}
200200
}
201201
}

task/control-plane-agent/src/update/host_flash.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,16 @@ impl ComponentUpdater for HostFlashUpdate {
400400
return Err(SpError::UpdateFailed(err as u32));
401401
}
402402

403-
if skip_bytes < buffer.len() {
404-
if let Err(err) = self.task.page_program_dev(
403+
if skip_bytes < buffer.len()
404+
&& let Err(err) = self.task.page_program_dev(
405405
*dev,
406406
*next_write_offset + skip_bytes as u32,
407407
HfProtectMode::ProtectSector0,
408408
&buffer[skip_bytes..],
409-
) {
410-
*current.state_mut() = State::Failed(err);
411-
return Err(SpError::UpdateFailed(err as u32));
412-
}
409+
)
410+
{
411+
*current.state_mut() = State::Failed(err);
412+
return Err(SpError::UpdateFailed(err as u32));
413413
}
414414

415415
*next_write_offset += buffer.len() as u32;

task/monorail-server/src/server.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ impl<'a, R: Vsc7448Rw> ServerImpl<'a, R> {
5858

5959
pub fn wake(&mut self) -> Result<(), VscError> {
6060
let now = sys_get_timer().now;
61-
if let Some(wake_interval) = bsp::WAKE_INTERVAL {
62-
if now >= self.wake_target_time {
63-
let out = self.bsp.wake();
64-
self.wake_target_time = userlib::set_timer_relative(
65-
wake_interval,
66-
notifications::WAKE_TIMER_MASK,
67-
);
68-
return out;
69-
}
61+
if let Some(wake_interval) = bsp::WAKE_INTERVAL
62+
&& now >= self.wake_target_time
63+
{
64+
let out = self.bsp.wake();
65+
self.wake_target_time = userlib::set_timer_relative(
66+
wake_interval,
67+
notifications::WAKE_TIMER_MASK,
68+
);
69+
return out;
7070
}
7171
Ok(())
7272
}

0 commit comments

Comments
 (0)