Skip to content

Commit f154b66

Browse files
ithinueleldruin
authored andcommitted
Change unused .ok() to let _ =
`.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.
1 parent 195b7d8 commit f154b66

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

src/control_pipe.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ impl<B: UsbBus> ControlPipe<'_, B> {
154154
| ControlState::DataInLast
155155
| ControlState::DataInZlp
156156
| ControlState::StatusOut => {
157-
self.ep_out.read(&mut []).ok();
157+
let _ = self.ep_out.read(&mut []);
158158
self.state = ControlState::Idle;
159159
}
160160
_ => {
161161
// Discard the packet
162-
self.ep_out.read(&mut []).ok();
162+
let _ = self.ep_out.read(&mut []);
163163

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

238-
self.ep_in.write(&[]).ok();
238+
let _ = self.ep_in.write(&[]);
239239
self.state = ControlState::StatusIn;
240240
Ok(())
241241
}

src/device.rs

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,13 @@ impl<B: UsbBus> UsbDevice<'_, B> {
324324
0x0000
325325
};
326326

327-
xfer.accept_with(&status.to_le_bytes()).ok();
327+
let _ = xfer.accept_with(&status.to_le_bytes());
328328
}
329329

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

333-
xfer.accept_with(&status.to_le_bytes()).ok();
333+
let _ = xfer.accept_with(&status.to_le_bytes());
334334
}
335335

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

345-
xfer.accept_with(&status.to_le_bytes()).ok();
345+
let _ = xfer.accept_with(&status.to_le_bytes());
346346
}
347347

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

358-
xfer.accept_with(&config.to_le_bytes()).ok();
358+
let _ = xfer.accept_with(&config.to_le_bytes());
359359
}
360360

361361
(Recipient::Interface, Request::GET_INTERFACE) => {
362362
// Reject interface numbers bigger than 255
363363
if req.index > core::u8::MAX.into() {
364-
xfer.reject().ok();
364+
let _ = xfer.reject();
365365
return;
366366
}
367367

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

378378
// If no class returned an alternate setting, return the default value
379-
xfer.accept_with(&DEFAULT_ALTERNATE_SETTING.to_le_bytes())
380-
.ok();
379+
let _ = xfer.accept_with(&DEFAULT_ALTERNATE_SETTING.to_le_bytes());
381380
}
382381

383382
_ => (),
384383
};
385384
}
386385

387386
if self.control.waiting_for_response() {
388-
self.control.reject().ok();
387+
let _ = self.control.reject();
389388
}
390389
}
391390

@@ -414,13 +413,13 @@ impl<B: UsbBus> UsbDevice<'_, B> {
414413
Request::FEATURE_DEVICE_REMOTE_WAKEUP,
415414
) => {
416415
self.remote_wakeup_enabled = false;
417-
xfer.accept().ok();
416+
let _ = xfer.accept();
418417
}
419418

420419
(Recipient::Endpoint, Request::CLEAR_FEATURE, Request::FEATURE_ENDPOINT_HALT) => {
421420
self.bus
422421
.set_stalled(((req.index as u8) & 0x8f).into(), false);
423-
xfer.accept().ok();
422+
let _ = xfer.accept();
424423
}
425424

426425
(
@@ -429,13 +428,13 @@ impl<B: UsbBus> UsbDevice<'_, B> {
429428
Request::FEATURE_DEVICE_REMOTE_WAKEUP,
430429
) => {
431430
self.remote_wakeup_enabled = true;
432-
xfer.accept().ok();
431+
let _ = xfer.accept();
433432
}
434433

435434
(Recipient::Endpoint, Request::SET_FEATURE, Request::FEATURE_ENDPOINT_HALT) => {
436435
self.bus
437436
.set_stalled(((req.index as u8) & 0x8f).into(), true);
438-
xfer.accept().ok();
437+
let _ = xfer.accept();
439438
}
440439

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

451450
(Recipient::Device, Request::SET_CONFIGURATION, CONFIGURATION_VALUE_U16) => {
452451
self.device_state = UsbDeviceState::Configured;
453-
xfer.accept().ok();
452+
let _ = xfer.accept();
454453
}
455454

456455
(Recipient::Device, Request::SET_CONFIGURATION, CONFIGURATION_NONE_U16) => {
457456
match self.device_state {
458457
UsbDeviceState::Default => {
459-
xfer.reject().ok();
458+
let _ = xfer.accept();
460459
}
461460
_ => {
462461
self.device_state = UsbDeviceState::Addressed;
463-
xfer.accept().ok();
462+
let _ = xfer.accept();
464463
}
465464
}
466465
}
467466

468467
(Recipient::Interface, Request::SET_INTERFACE, alt_setting) => {
469468
// Reject interface numbers and alt settings bigger than 255
470469
if req.index > core::u8::MAX.into() || alt_setting > core::u8::MAX.into() {
471-
xfer.reject().ok();
470+
let _ = xfer.reject();
472471
return;
473472
}
474473

475474
// Ask class implementations, whether they accept the alternate interface setting.
476475
for cls in classes {
477476
if cls.set_alt_setting(InterfaceNumber(req.index as u8), alt_setting as u8)
478477
{
479-
xfer.accept().ok();
478+
let _ = xfer.accept();
480479
return;
481480
}
482481
}
483482

484483
// Default behaviour, if no class implementation accepted the alternate setting.
485484
if alt_setting == DEFAULT_ALTERNATE_SETTING_U16 {
486-
xfer.accept().ok();
485+
let _ = xfer.accept();
487486
} else {
488-
xfer.reject().ok();
487+
let _ = xfer.reject();
489488
}
490489
}
491490

492491
_ => {
493-
xfer.reject().ok();
492+
let _ = xfer.reject();
494493
return;
495494
}
496495
}
497496
}
498497

499498
if self.control.waiting_for_response() {
500-
self.control.reject().ok();
499+
let _ = self.control.reject();
501500
}
502501
}
503502

@@ -510,12 +509,11 @@ impl<B: UsbBus> UsbDevice<'_, B> {
510509
xfer: ControlIn<B>,
511510
f: impl FnOnce(&mut DescriptorWriter) -> Result<()>,
512511
) {
513-
xfer.accept(|buf| {
512+
let _ = xfer.accept(|buf| {
514513
let mut writer = DescriptorWriter::new(buf);
515514
f(&mut writer)?;
516515
Ok(writer.position())
517-
})
518-
.ok();
516+
});
519517
}
520518

521519
match dtype {
@@ -642,13 +640,13 @@ impl<B: UsbBus> UsbDevice<'_, B> {
642640
if let Some(s) = s {
643641
accept_writer(xfer, |w| w.string(s));
644642
} else {
645-
xfer.reject().ok();
643+
let _ = xfer.reject();
646644
}
647645
}
648646
},
649647

650648
_ => {
651-
xfer.reject().ok();
649+
let _ = xfer.reject();
652650
}
653651
}
654652
}

tests/test_class_host/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn run_tests(tests: &[(&str, TestFn)]) {
6767
}
6868

6969
print!("test {} ... ", name);
70-
stdout().flush().ok();
70+
let _ = stdout().flush();
7171

7272
let mut out = String::new();
7373

0 commit comments

Comments
 (0)