Skip to content

Commit 1d4a935

Browse files
committed
clippy
1 parent 0915046 commit 1d4a935

File tree

4 files changed

+16
-23
lines changed

4 files changed

+16
-23
lines changed

src/generate/peripheral.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,12 @@ impl FieldRegions {
426426
.filter(|r| {
427427
r.fields.len() > 1 && (idents.iter().filter(|ident| **ident == r.ident).count() > 1)
428428
})
429-
.inspect(|r| {
429+
.for_each(|r| {
430430
warn!(
431431
"Found type name conflict with region {:?}, renamed to {:?}",
432432
r.ident,
433433
r.shortest_ident()
434-
)
435-
})
436-
.for_each(|r| {
434+
);
437435
r.ident = r.shortest_ident();
438436
});
439437
Ok(())

src/generate/register.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::svd::{
33
RegisterProperties, Usage, WriteConstraint,
44
};
55
use cast::u64;
6+
use core::u64;
67
use log::warn;
78
use proc_macro2::{Ident, Punct, Spacing, Span, TokenStream};
89
use quote::{quote, ToTokens};
@@ -254,6 +255,7 @@ pub fn render(
254255
Ok(out)
255256
}
256257

258+
#[allow(clippy::too_many_arguments)]
257259
pub fn fields(
258260
fields: &[Field],
259261
parent: &Register,
@@ -291,7 +293,7 @@ pub fn fields(
291293
&& (f.access != Some(Access::WriteOnce));
292294
let can_write = can_write && (f.access != Some(Access::ReadOnly));
293295

294-
let mask = 1u64.wrapping_neg() >> (64 - width);
296+
let mask = u64::MAX >> (64 - width);
295297
let hexmask = &util::hex(mask);
296298
let offset = u64::from(offset);
297299
let rv = reset_value.map(|rv| (rv >> offset) & mask);
@@ -749,8 +751,7 @@ pub fn fields(
749751
fn unsafety(write_constraint: Option<&WriteConstraint>, width: u32) -> Option<Ident> {
750752
match &write_constraint {
751753
Some(&WriteConstraint::Range(range))
752-
if u64::from(range.min) == 0
753-
&& u64::from(range.max) == 1u64.wrapping_neg() >> (64 - width) =>
754+
if range.min == 0 && range.max == u64::MAX >> (64 - width) =>
754755
{
755756
// the SVD has acknowledged that it's safe to write
756757
// any value that can fit in the field
@@ -1052,8 +1053,7 @@ fn lookup_in_peripheral<'p>(
10521053
if let Some(register) = all_registers.iter().find(|r| r.name == base_register) {
10531054
if let Some(field) = register
10541055
.fields
1055-
.as_ref()
1056-
.map(|fs| &**fs)
1056+
.as_deref()
10571057
.unwrap_or(&[])
10581058
.iter()
10591059
.find(|f| f.name == base_field)
@@ -1082,7 +1082,7 @@ fn lookup_in_field<'f>(
10821082
field: &'f Field,
10831083
) -> Result<(&'f EnumeratedValues, Option<Base<'f>>)> {
10841084
for evs in &field.enumerated_values {
1085-
if evs.name.as_ref().map(|s| &**s) == Some(base_evs) {
1085+
if evs.name.as_deref() == Some(base_evs) {
10861086
return Ok((
10871087
evs,
10881088
Some(Base {
@@ -1107,11 +1107,11 @@ fn lookup_in_register<'r>(
11071107
) -> Result<(&'r EnumeratedValues, Option<Base<'r>>)> {
11081108
let mut matches = vec![];
11091109

1110-
for f in register.fields.as_ref().map(|v| &**v).unwrap_or(&[]) {
1110+
for f in register.fields.as_deref().unwrap_or(&[]) {
11111111
if let Some(evs) = f
11121112
.enumerated_values
11131113
.iter()
1114-
.find(|evs| evs.name.as_ref().map(|s| &**s) == Some(base_evs))
1114+
.find(|evs| evs.name.as_deref() == Some(base_evs))
11151115
{
11161116
matches.push((evs, &f.name))
11171117
}
@@ -1168,7 +1168,7 @@ fn lookup_in_peripherals<'p>(
11681168
}
11691169
}
11701170

1171-
fn periph_all_registers<'a>(p: &'a Peripheral) -> Vec<&'a Register> {
1171+
fn periph_all_registers(p: &Peripheral) -> Vec<&Register> {
11721172
let mut par: Vec<&Register> = Vec::new();
11731173
let mut rem: Vec<&RegisterCluster> = Vec::new();
11741174
if p.registers.is_none() {

src/lib.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,20 +484,16 @@ mod util;
484484

485485
pub use crate::util::Target;
486486

487+
#[non_exhaustive]
487488
pub struct Generation {
488489
pub lib_rs: String,
489490
pub device_specific: Option<DeviceSpecific>,
490-
491-
// Reserve the right to add more fields to this struct
492-
_extensible: (),
493491
}
494492

493+
#[non_exhaustive]
495494
pub struct DeviceSpecific {
496495
pub device_x: String,
497496
pub build_rs: String,
498-
499-
// Reserve the right to add more fields to this struct
500-
_extensible: (),
501497
}
502498

503499
use anyhow::Result;
@@ -534,14 +530,12 @@ pub fn generate(xml: &str, target: Target, nightly: bool) -> Result<Generation>
534530
Some(DeviceSpecific {
535531
device_x,
536532
build_rs: util::build_rs().to_string(),
537-
_extensible: (),
538533
})
539534
};
540535

541536
Ok(Generation {
542537
lib_rs,
543538
device_specific,
544-
_extensible: (),
545539
})
546540
}
547541

src/util.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub const BITS_PER_BYTE: u32 = 8;
1313
/// that are not valid in Rust ident
1414
const BLACKLIST_CHARS: &[char] = &['(', ')', '[', ']', '/', ' ', '-'];
1515

16+
#[allow(non_camel_case_types)]
1617
#[derive(Clone, Copy, PartialEq)]
1718
pub enum Target {
1819
CortexM,
@@ -166,7 +167,7 @@ pub fn respace(s: &str) -> String {
166167
pub fn escape_brackets(s: &str) -> String {
167168
s.split('[')
168169
.fold("".to_string(), |acc, x| {
169-
if acc == "" {
170+
if acc.is_empty() {
170171
x.to_string()
171172
} else if acc.ends_with('\\') {
172173
acc + "[" + x
@@ -176,7 +177,7 @@ pub fn escape_brackets(s: &str) -> String {
176177
})
177178
.split(']')
178179
.fold("".to_string(), |acc, x| {
179-
if acc == "" {
180+
if acc.is_empty() {
180181
x.to_string()
181182
} else if acc.ends_with('\\') {
182183
acc + "]" + x

0 commit comments

Comments
 (0)