Skip to content

Commit 7759c34

Browse files
authored
Merge pull request #88 from rust-embedded-community/feature/ci
Addressing clippy lints
2 parents 10b4e12 + 77e0d3c commit 7759c34

File tree

6 files changed

+25
-27
lines changed

6 files changed

+25
-27
lines changed

src/bus.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl<B: UsbBus> UsbBusAllocator<B> {
211211
///
212212
/// This directly delegates to [`UsbBus::alloc_ep`], so see that method for details. In most
213213
/// cases classes should call the endpoint type specific methods instead.
214-
pub fn alloc<'a, D: EndpointDirection>(
214+
pub fn alloc<D: EndpointDirection>(
215215
&self,
216216
ep_addr: Option<EndpointAddress>,
217217
ep_type: EndpointType,

src/control_pipe.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ impl<B: UsbBus> ControlPipe<'_, B> {
5151
}
5252

5353
pub fn waiting_for_response(&self) -> bool {
54-
match self.state {
55-
ControlState::CompleteOut | ControlState::CompleteIn(_) => true,
56-
_ => false,
57-
}
54+
matches!(
55+
self.state,
56+
ControlState::CompleteOut | ControlState::CompleteIn(_)
57+
)
5858
}
5959

6060
pub fn data(&self) -> &[u8] {
@@ -65,7 +65,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
6565
self.state = ControlState::Idle;
6666
}
6767

68-
pub fn handle_setup<'p>(&'p mut self) -> Option<Request> {
68+
pub fn handle_setup(&mut self) -> Option<Request> {
6969
let count = match self.ep_out.read(&mut self.buf[..]) {
7070
Ok(count) => count,
7171
Err(UsbError::WouldBlock) => return None,
@@ -125,7 +125,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
125125
None
126126
}
127127

128-
pub fn handle_out<'p>(&'p mut self) -> Option<Request> {
128+
pub fn handle_out(&mut self) -> Option<Request> {
129129
match self.state {
130130
ControlState::DataOut(req) => {
131131
let i = self.i;

src/device.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
295295

296296
match (req.recipient, req.request) {
297297
(Recipient::Device, Request::GET_STATUS) => {
298-
let status: u16 = 0x0000
299-
| if self.self_powered { 0x0001 } else { 0x0000 }
298+
let status: u16 = if self.self_powered { 0x0001 } else { 0x0000 }
300299
| if self.remote_wakeup_enabled {
301300
0x0002
302301
} else {
@@ -315,12 +314,11 @@ impl<B: UsbBus> UsbDevice<'_, B> {
315314
(Recipient::Endpoint, Request::GET_STATUS) => {
316315
let ep_addr = ((req.index as u8) & 0x8f).into();
317316

318-
let status: u16 = 0x0000
319-
| if self.bus.is_stalled(ep_addr) {
320-
0x0001
321-
} else {
322-
0x0000
323-
};
317+
let status: u16 = if self.bus.is_stalled(ep_addr) {
318+
0x0001
319+
} else {
320+
0x0000
321+
};
324322

325323
xfer.accept_with(&status.to_le_bytes()).ok();
326324
}

src/endpoint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ pub struct Endpoint<'a, B: UsbBus, D: EndpointDirection> {
5757
}
5858

5959
impl<B: UsbBus, D: EndpointDirection> Endpoint<'_, B, D> {
60-
pub(crate) fn new<'a>(
61-
bus_ptr: &'a AtomicPtr<B>,
60+
pub(crate) fn new(
61+
bus_ptr: &AtomicPtr<B>,
6262
address: EndpointAddress,
6363
ep_type: EndpointType,
6464
max_packet_size: u16,

tests/test_class_host/device.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn open_device(ctx: &Context) -> rusb::Result<DeviceHandles> {
3939
let mut handle = device.open()?;
4040

4141
let langs = handle.read_languages(TIMEOUT)?;
42-
if langs.len() == 0 || langs[0].lang_id() != EN_US {
42+
if langs.is_empty() || langs[0].lang_id() != EN_US {
4343
continue;
4444
}
4545

tests/test_class_host/tests.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn control_request(dev, _out) {
3838
let data = random_data(rng.gen_range(0, 16));
3939

4040
let mut expected = [0u8; 8];
41-
expected[0] = (0x02 as u8) << 5;
41+
expected[0] = 0x02_u8 << 5;
4242
expected[1] = test_class::REQ_STORE_REQUEST;
4343
expected[2..4].copy_from_slice(&value.to_le_bytes());
4444
expected[4..6].copy_from_slice(&index.to_le_bytes());
@@ -71,7 +71,7 @@ fn control_data(dev, _out) {
7171
dev.write_control(
7272
request_type(Direction::Out, RequestType::Vendor, Recipient::Device),
7373
test_class::REQ_WRITE_BUFFER, 0, 0,
74-
&data, TIMEOUT).expect(&format!("control write len {}", len)),
74+
&data, TIMEOUT).unwrap_or_else(|_| panic!("control write len {}", len)),
7575
data.len());
7676

7777
let mut response = vec![0u8; *len];
@@ -80,7 +80,7 @@ fn control_data(dev, _out) {
8080
dev.read_control(
8181
request_type(Direction::In, RequestType::Vendor, Recipient::Device),
8282
test_class::REQ_READ_BUFFER, 0, 0,
83-
&mut response, TIMEOUT).expect(&format!("control read len {}", len)),
83+
&mut response, TIMEOUT).unwrap_or_else(|_| panic!("control read len {}", len)),
8484
data.len());
8585

8686
assert_eq!(&response, &data);
@@ -169,14 +169,14 @@ fn bulk_loopback(dev, _out) {
169169

170170
assert_eq!(
171171
dev.write_bulk(0x01, &data, TIMEOUT)
172-
.expect(&format!("bulk write len {}", len)),
172+
.unwrap_or_else(|_| panic!("bulk write len {}", len)),
173173
data.len(),
174174
"bulk write len {}", len);
175175

176176
if *len > 0 && *len % 64 == 0 {
177177
assert_eq!(
178178
dev.write_bulk(0x01, &[], TIMEOUT)
179-
.expect(&format!("bulk write zero-length packet")),
179+
.expect("bulk write zero-length packet"),
180180
0,
181181
"bulk write zero-length packet");
182182
}
@@ -187,7 +187,7 @@ fn bulk_loopback(dev, _out) {
187187

188188
assert_eq!(
189189
dev.read_bulk(0x81, &mut response, TIMEOUT)
190-
.expect(&format!("bulk read len {}", len)),
190+
.unwrap_or_else(|_| panic!("bulk read len {}", len)),
191191
data.len(),
192192
"bulk read len {}", len);
193193

@@ -201,7 +201,7 @@ fn interrupt_loopback(dev, _out) {
201201

202202
assert_eq!(
203203
dev.write_interrupt(0x02, &data, TIMEOUT)
204-
.expect(&format!("interrupt write len {}", len)),
204+
.unwrap_or_else(|_| panic!("interrupt write len {}", len)),
205205
data.len(),
206206
"interrupt write len {}", len);
207207

@@ -211,7 +211,7 @@ fn interrupt_loopback(dev, _out) {
211211

212212
assert_eq!(
213213
dev.read_interrupt(0x82, &mut response, TIMEOUT)
214-
.expect(&format!("interrupt read len {}", len)),
214+
.unwrap_or_else(|_| panic!("interrupt read len {}", len)),
215215
data.len(),
216216
"interrupt read len {}", len);
217217

@@ -241,7 +241,7 @@ fn bench_bulk_read(dev, out) {
241241

242242
}
243243

244-
fn run_bench(dev: &DeviceHandles, out: &mut String, f: impl Fn(&mut [u8]) -> ()) {
244+
fn run_bench(dev: &DeviceHandles, out: &mut String, f: impl Fn(&mut [u8])) {
245245
const TRANSFER_BYTES: usize = 64 * 1024;
246246
const TRANSFERS: usize = 16;
247247
const TOTAL_BYTES: usize = TRANSFER_BYTES * TRANSFERS;

0 commit comments

Comments
 (0)