Skip to content

Commit

Permalink
Change unused .ok() to let _ =
Browse files Browse the repository at this point in the history
`.ok()` satisfies the `must_use` without actually generating any error/panic
on failure giving a false sense that the result it being checked.

This changes occurrences of unused `.ok()` to `let _ = ` which explicitly
shows the result is being ignored.
  • Loading branch information
ithinuel authored and eldruin committed Nov 10, 2023
1 parent 195b7d8 commit f154b66
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/control_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ impl<B: UsbBus> ControlPipe<'_, B> {
| ControlState::DataInLast
| ControlState::DataInZlp
| ControlState::StatusOut => {
self.ep_out.read(&mut []).ok();
let _ = self.ep_out.read(&mut []);
self.state = ControlState::Idle;
}
_ => {
// Discard the packet
self.ep_out.read(&mut []).ok();
let _ = self.ep_out.read(&mut []);

// Unexpected OUT packet
self.set_error()
Expand Down Expand Up @@ -235,7 +235,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
_ => return Err(UsbError::InvalidState),
};

self.ep_in.write(&[]).ok();
let _ = self.ep_in.write(&[]);
self.state = ControlState::StatusIn;
Ok(())
}
Expand Down
54 changes: 26 additions & 28 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,13 @@ impl<B: UsbBus> UsbDevice<'_, B> {
0x0000
};

xfer.accept_with(&status.to_le_bytes()).ok();
let _ = xfer.accept_with(&status.to_le_bytes());
}

(Recipient::Interface, Request::GET_STATUS) => {
let status: u16 = 0x0000;

xfer.accept_with(&status.to_le_bytes()).ok();
let _ = xfer.accept_with(&status.to_le_bytes());
}

(Recipient::Endpoint, Request::GET_STATUS) => {
Expand All @@ -342,7 +342,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
0x0000
};

xfer.accept_with(&status.to_le_bytes()).ok();
let _ = xfer.accept_with(&status.to_le_bytes());
}

(Recipient::Device, Request::GET_DESCRIPTOR) => {
Expand All @@ -355,13 +355,13 @@ impl<B: UsbBus> UsbDevice<'_, B> {
_ => CONFIGURATION_NONE,
};

xfer.accept_with(&config.to_le_bytes()).ok();
let _ = xfer.accept_with(&config.to_le_bytes());
}

(Recipient::Interface, Request::GET_INTERFACE) => {
// Reject interface numbers bigger than 255
if req.index > core::u8::MAX.into() {
xfer.reject().ok();
let _ = xfer.reject();
return;
}

Expand All @@ -370,22 +370,21 @@ impl<B: UsbBus> UsbDevice<'_, B> {
for cls in classes {
if let Some(setting) = cls.get_alt_setting(InterfaceNumber(req.index as u8))
{
xfer.accept_with(&setting.to_le_bytes()).ok();
let _ = xfer.accept_with(&setting.to_le_bytes());
return;
}
}

// If no class returned an alternate setting, return the default value
xfer.accept_with(&DEFAULT_ALTERNATE_SETTING.to_le_bytes())
.ok();
let _ = xfer.accept_with(&DEFAULT_ALTERNATE_SETTING.to_le_bytes());
}

_ => (),
};
}

if self.control.waiting_for_response() {
self.control.reject().ok();
let _ = self.control.reject();
}
}

Expand Down Expand Up @@ -414,13 +413,13 @@ impl<B: UsbBus> UsbDevice<'_, B> {
Request::FEATURE_DEVICE_REMOTE_WAKEUP,
) => {
self.remote_wakeup_enabled = false;
xfer.accept().ok();
let _ = xfer.accept();
}

(Recipient::Endpoint, Request::CLEAR_FEATURE, Request::FEATURE_ENDPOINT_HALT) => {
self.bus
.set_stalled(((req.index as u8) & 0x8f).into(), false);
xfer.accept().ok();
let _ = xfer.accept();
}

(
Expand All @@ -429,13 +428,13 @@ impl<B: UsbBus> UsbDevice<'_, B> {
Request::FEATURE_DEVICE_REMOTE_WAKEUP,
) => {
self.remote_wakeup_enabled = true;
xfer.accept().ok();
let _ = xfer.accept();
}

(Recipient::Endpoint, Request::SET_FEATURE, Request::FEATURE_ENDPOINT_HALT) => {
self.bus
.set_stalled(((req.index as u8) & 0x8f).into(), true);
xfer.accept().ok();
let _ = xfer.accept();
}

(Recipient::Device, Request::SET_ADDRESS, 1..=127) => {
Expand All @@ -445,59 +444,59 @@ impl<B: UsbBus> UsbDevice<'_, B> {
} else {
self.pending_address = req.value as u8;
}
xfer.accept().ok();
let _ = xfer.accept();
}

(Recipient::Device, Request::SET_CONFIGURATION, CONFIGURATION_VALUE_U16) => {
self.device_state = UsbDeviceState::Configured;
xfer.accept().ok();
let _ = xfer.accept();
}

(Recipient::Device, Request::SET_CONFIGURATION, CONFIGURATION_NONE_U16) => {
match self.device_state {
UsbDeviceState::Default => {
xfer.reject().ok();
let _ = xfer.accept();
}
_ => {
self.device_state = UsbDeviceState::Addressed;
xfer.accept().ok();
let _ = xfer.accept();
}
}
}

(Recipient::Interface, Request::SET_INTERFACE, alt_setting) => {
// Reject interface numbers and alt settings bigger than 255
if req.index > core::u8::MAX.into() || alt_setting > core::u8::MAX.into() {
xfer.reject().ok();
let _ = xfer.reject();
return;
}

// Ask class implementations, whether they accept the alternate interface setting.
for cls in classes {
if cls.set_alt_setting(InterfaceNumber(req.index as u8), alt_setting as u8)
{
xfer.accept().ok();
let _ = xfer.accept();
return;
}
}

// Default behaviour, if no class implementation accepted the alternate setting.
if alt_setting == DEFAULT_ALTERNATE_SETTING_U16 {
xfer.accept().ok();
let _ = xfer.accept();
} else {
xfer.reject().ok();
let _ = xfer.reject();
}
}

_ => {
xfer.reject().ok();
let _ = xfer.reject();
return;
}
}
}

if self.control.waiting_for_response() {
self.control.reject().ok();
let _ = self.control.reject();
}
}

Expand All @@ -510,12 +509,11 @@ impl<B: UsbBus> UsbDevice<'_, B> {
xfer: ControlIn<B>,
f: impl FnOnce(&mut DescriptorWriter) -> Result<()>,
) {
xfer.accept(|buf| {
let _ = xfer.accept(|buf| {
let mut writer = DescriptorWriter::new(buf);
f(&mut writer)?;
Ok(writer.position())
})
.ok();
});
}

match dtype {
Expand Down Expand Up @@ -642,13 +640,13 @@ impl<B: UsbBus> UsbDevice<'_, B> {
if let Some(s) = s {
accept_writer(xfer, |w| w.string(s));
} else {
xfer.reject().ok();
let _ = xfer.reject();
}
}
},

_ => {
xfer.reject().ok();
let _ = xfer.reject();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_class_host/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn run_tests(tests: &[(&str, TestFn)]) {
}

print!("test {} ... ", name);
stdout().flush().ok();
let _ = stdout().flush();

let mut out = String::new();

Expand Down

0 comments on commit f154b66

Please sign in to comment.