Skip to content

Commit 2a02b55

Browse files
committed
Fix a ton of clippy lints
Signed-off-by: Daniel Egger <daniel@eggers-club.de>
1 parent 29129c0 commit 2a02b55

File tree

3 files changed

+33
-37
lines changed

3 files changed

+33
-37
lines changed

src/generate/peripheral.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ fn new_syn_field(ident: &str, ty: syn::Type) -> syn::Field {
893893
}
894894
}
895895

896-
fn name_to_ty(name: &String, ns: Option<&str>) -> Result<syn::Type, syn::Error> {
896+
fn name_to_ty(name: &str, ns: Option<&str>) -> Result<syn::Type, syn::Error> {
897897
let ident = if let Some(ns) = ns {
898898
Cow::Owned(
899899
String::from("self::")
@@ -907,7 +907,7 @@ fn name_to_ty(name: &String, ns: Option<&str>) -> Result<syn::Type, syn::Error>
907907
Ok(syn::Type::Path(parse_str::<syn::TypePath>(&ident)?))
908908
}
909909

910-
fn name_to_wrapped_ty_str(name: &String, ns: Option<&str>) -> String {
910+
fn name_to_wrapped_ty_str(name: &str, ns: Option<&str>) -> String {
911911
if let Some(ns) = ns {
912912
format!(
913913
"crate::Reg<self::{}::{}::{}_SPEC>",
@@ -924,7 +924,7 @@ fn name_to_wrapped_ty_str(name: &String, ns: Option<&str>) -> String {
924924
}
925925
}
926926

927-
fn name_to_wrapped_ty(name: &String, ns: Option<&str>) -> Result<syn::Type, syn::Error> {
927+
fn name_to_wrapped_ty(name: &str, ns: Option<&str>) -> Result<syn::Type, syn::Error> {
928928
let ident = name_to_wrapped_ty_str(name, ns);
929929
Ok(syn::Type::Path(parse_str::<syn::TypePath>(&ident)?))
930930
}

src/generate/register.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ pub fn fields(
323323
.map(|element| element.parse::<u32>())
324324
.eq((first..de.dim + first).map(Ok));
325325
if !sequential_indexes {
326-
return Err(anyhow!("unsupported array indexes in {}", f.name))?;
326+
return Err(anyhow!("unsupported array indexes in {}", f.name));
327327
}
328328
(first, None)
329329
} else {
@@ -341,7 +341,7 @@ pub fn fields(
341341
}
342342
Field::Single(_) => {
343343
if f.name.contains("%s") {
344-
return Err(anyhow!("incorrect field {}", f.name))?;
344+
return Err(anyhow!("incorrect field {}", f.name));
345345
}
346346
None
347347
}
@@ -870,7 +870,7 @@ fn description_with_bits(description: &str, offset: u64, width: u32) -> String {
870870
} else {
871871
format!("Bits {}:{}", offset, offset + width as u64 - 1)
872872
};
873-
if description.len() > 0 {
873+
if !description.is_empty() {
874874
res.push_str(" - ");
875875
res.push_str(&util::respace(&util::escape_brackets(description)));
876876
}
@@ -998,8 +998,7 @@ fn lookup_in_fields<'f>(
998998
"Field {} not found in register {}",
999999
base_field,
10001000
register.name
1001-
)
1002-
.into())
1001+
))
10031002
}
10041003
}
10051004

@@ -1026,15 +1025,14 @@ fn lookup_in_peripheral<'p>(
10261025
"No field {} in register {}",
10271026
base_field,
10281027
register.name
1029-
))?
1028+
))
10301029
}
10311030
} else {
10321031
Err(anyhow!(
10331032
"No register {} in peripheral {}",
10341033
base_register,
10351034
peripheral.name
1036-
)
1037-
.into())
1035+
))
10381036
}
10391037
}
10401038

@@ -1061,7 +1059,7 @@ fn lookup_in_field<'f>(
10611059
"No EnumeratedValues {} in field {}",
10621060
base_evs,
10631061
field.name
1064-
))?
1062+
))
10651063
}
10661064

10671065
fn lookup_in_register<'r>(
@@ -1085,8 +1083,7 @@ fn lookup_in_register<'r>(
10851083
"EnumeratedValues {} not found in register {}",
10861084
base_evs,
10871085
register.name
1088-
)
1089-
.into()),
1086+
)),
10901087
Some(&(evs, field)) => {
10911088
if matches.len() == 1 {
10921089
Ok((
@@ -1104,8 +1101,7 @@ fn lookup_in_register<'r>(
11041101
enumeratedValues named {}",
11051102
fields,
11061103
base_evs
1107-
)
1108-
.into())
1104+
))
11091105
}
11101106
}
11111107
}
@@ -1129,7 +1125,7 @@ fn lookup_in_peripherals<'p>(
11291125
peripheral,
11301126
)
11311127
} else {
1132-
Err(anyhow!("No peripheral {}", base_peripheral))?
1128+
Err(anyhow!("No peripheral {}", base_peripheral))
11331129
}
11341130
}
11351131

@@ -1146,20 +1142,16 @@ fn periph_all_registers<'a>(p: &'a Peripheral) -> Vec<&'a Register> {
11461142
}
11471143
}
11481144

1149-
loop {
1150-
if let Some(b) = rem.pop() {
1151-
match b {
1152-
RegisterCluster::Register(reg) => {
1153-
par.push(reg);
1154-
}
1155-
RegisterCluster::Cluster(cluster) => {
1156-
for c in cluster.children.iter() {
1157-
rem.push(c);
1158-
}
1145+
while let Some(b) = rem.pop() {
1146+
match b {
1147+
RegisterCluster::Register(reg) => {
1148+
par.push(reg);
1149+
}
1150+
RegisterCluster::Cluster(cluster) => {
1151+
for c in cluster.children.iter() {
1152+
rem.push(c);
11591153
}
11601154
}
1161-
} else {
1162-
break;
11631155
}
11641156
}
11651157
par

src/util.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,12 @@ impl U32Ext for u32 {
279279
9..=16 => "u16",
280280
17..=32 => "u32",
281281
33..=64 => "u64",
282-
_ => Err(anyhow!(
283-
"can't convert {} bits into a Rust integral type",
284-
*self
285-
))?,
282+
_ => {
283+
return Err(anyhow!(
284+
"can't convert {} bits into a Rust integral type",
285+
*self
286+
))
287+
}
286288
},
287289
Span::call_site(),
288290
))
@@ -295,10 +297,12 @@ impl U32Ext for u32 {
295297
9..=16 => 16,
296298
17..=32 => 32,
297299
33..=64 => 64,
298-
_ => Err(anyhow!(
299-
"can't convert {} bits into a Rust integral type width",
300-
*self
301-
))?,
300+
_ => {
301+
return Err(anyhow!(
302+
"can't convert {} bits into a Rust integral type width",
303+
*self
304+
))
305+
}
302306
})
303307
}
304308
}

0 commit comments

Comments
 (0)