Skip to content

Fix a ton of clippy lints #479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/generate/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ fn new_syn_field(ident: &str, ty: syn::Type) -> syn::Field {
}
}

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

fn name_to_wrapped_ty_str(name: &String, ns: Option<&str>) -> String {
fn name_to_wrapped_ty_str(name: &str, ns: Option<&str>) -> String {
if let Some(ns) = ns {
format!(
"crate::Reg<self::{}::{}::{}_SPEC>",
Expand All @@ -924,7 +924,7 @@ fn name_to_wrapped_ty_str(name: &String, ns: Option<&str>) -> String {
}
}

fn name_to_wrapped_ty(name: &String, ns: Option<&str>) -> Result<syn::Type, syn::Error> {
fn name_to_wrapped_ty(name: &str, ns: Option<&str>) -> Result<syn::Type, syn::Error> {
let ident = name_to_wrapped_ty_str(name, ns);
Ok(syn::Type::Path(parse_str::<syn::TypePath>(&ident)?))
}
44 changes: 18 additions & 26 deletions src/generate/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ pub fn fields(
.map(|element| element.parse::<u32>())
.eq((first..de.dim + first).map(Ok));
if !sequential_indexes {
return Err(anyhow!("unsupported array indexes in {}", f.name))?;
return Err(anyhow!("unsupported array indexes in {}", f.name));
}
(first, None)
} else {
Expand All @@ -341,7 +341,7 @@ pub fn fields(
}
Field::Single(_) => {
if f.name.contains("%s") {
return Err(anyhow!("incorrect field {}", f.name))?;
return Err(anyhow!("incorrect field {}", f.name));
}
None
}
Expand Down Expand Up @@ -870,7 +870,7 @@ fn description_with_bits(description: &str, offset: u64, width: u32) -> String {
} else {
format!("Bits {}:{}", offset, offset + width as u64 - 1)
};
if description.len() > 0 {
if !description.is_empty() {
res.push_str(" - ");
res.push_str(&util::respace(&util::escape_brackets(description)));
}
Expand Down Expand Up @@ -998,8 +998,7 @@ fn lookup_in_fields<'f>(
"Field {} not found in register {}",
base_field,
register.name
)
.into())
))
}
}

Expand All @@ -1026,15 +1025,14 @@ fn lookup_in_peripheral<'p>(
"No field {} in register {}",
base_field,
register.name
))?
))
}
} else {
Err(anyhow!(
"No register {} in peripheral {}",
base_register,
peripheral.name
)
.into())
))
}
}

Expand All @@ -1061,7 +1059,7 @@ fn lookup_in_field<'f>(
"No EnumeratedValues {} in field {}",
base_evs,
field.name
))?
))
}

fn lookup_in_register<'r>(
Expand All @@ -1085,8 +1083,7 @@ fn lookup_in_register<'r>(
"EnumeratedValues {} not found in register {}",
base_evs,
register.name
)
.into()),
)),
Some(&(evs, field)) => {
if matches.len() == 1 {
Ok((
Expand All @@ -1104,8 +1101,7 @@ fn lookup_in_register<'r>(
enumeratedValues named {}",
fields,
base_evs
)
.into())
))
}
}
}
Expand All @@ -1129,7 +1125,7 @@ fn lookup_in_peripherals<'p>(
peripheral,
)
} else {
Err(anyhow!("No peripheral {}", base_peripheral))?
Err(anyhow!("No peripheral {}", base_peripheral))
}
}

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

loop {
if let Some(b) = rem.pop() {
match b {
RegisterCluster::Register(reg) => {
par.push(reg);
}
RegisterCluster::Cluster(cluster) => {
for c in cluster.children.iter() {
rem.push(c);
}
while let Some(b) = rem.pop() {
match b {
RegisterCluster::Register(reg) => {
par.push(reg);
}
RegisterCluster::Cluster(cluster) => {
for c in cluster.children.iter() {
rem.push(c);
}
}
} else {
break;
}
}
par
Expand Down
20 changes: 12 additions & 8 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,12 @@ impl U32Ext for u32 {
9..=16 => "u16",
17..=32 => "u32",
33..=64 => "u64",
_ => Err(anyhow!(
"can't convert {} bits into a Rust integral type",
*self
))?,
_ => {
return Err(anyhow!(
"can't convert {} bits into a Rust integral type",
*self
))
}
},
Span::call_site(),
))
Expand All @@ -295,10 +297,12 @@ impl U32Ext for u32 {
9..=16 => 16,
17..=32 => 32,
33..=64 => 64,
_ => Err(anyhow!(
"can't convert {} bits into a Rust integral type width",
*self
))?,
_ => {
return Err(anyhow!(
"can't convert {} bits into a Rust integral type width",
*self
))
}
})
}
}
Expand Down