Skip to content
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

refactor with clippy #19

Merged
merged 1 commit into from
Jan 10, 2024
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
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn commit_info() -> String {
fn commit_hash() -> Result<String, IgnoredError> {
Ok(String::from_utf8(
Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])
.args(["rev-parse", "--short", "HEAD"])
.output()?
.stdout,
)?)
Expand All @@ -46,7 +46,7 @@ fn commit_hash() -> Result<String, IgnoredError> {
fn commit_date() -> Result<String, IgnoredError> {
Ok(String::from_utf8(
Command::new("git")
.args(&["log", "-1", "--date=short", "--pretty=format:%cd"])
.args(["log", "-1", "--date=short", "--pretty=format:%cd"])
.output()?
.stdout,
)?)
Expand Down
2 changes: 1 addition & 1 deletion src/generate/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn render(_opts: &super::Options, ir: &IR, d: &Device, path: &str) -> Result

for p in sorted(&d.peripherals, |p| p.base_address) {
let name = Ident::new(&p.name, span);
let address = util::hex(p.base_address as u64);
let address = util::hex(p.base_address);
let doc = util::doc(&p.description);

if let Some(block_name) = &p.block {
Expand Down
2 changes: 1 addition & 1 deletion src/generate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Module {
res.extend(self.items.clone());

for (name, module) in sorted_map(&self.children, |name, _| name.clone()) {
let name = Ident::new(&name, span);
let name = Ident::new(name, span);
let contents = module.render()?;
res.extend(quote! {
pub mod #name {
Expand Down
11 changes: 3 additions & 8 deletions src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{de, de::Visitor, ser::SerializeMap, Deserialize, Deserializer, Seria
use std::collections::{BTreeMap, HashMap};
use std::fmt;

#[derive(Clone, Debug, PartialEq)]
#[derive(Default, Clone, Debug, PartialEq)]
pub struct IR {
pub devices: HashMap<String, Device>,
pub blocks: HashMap<String, Block>,
Expand All @@ -13,12 +13,7 @@ pub struct IR {

impl IR {
pub fn new() -> Self {
Self {
devices: HashMap::new(),
blocks: HashMap::new(),
fieldsets: HashMap::new(),
enums: HashMap::new(),
}
Self::default()
}

pub fn merge(&mut self, other: IR) {
Expand Down Expand Up @@ -263,7 +258,7 @@ impl<'de> Visitor<'de> for IRVisitor {
// into our map.
while let Some(key) = access.next_key()? {
let key: String = key;
let (kind, name) = key.split_once("/").ok_or(de::Error::custom("item names must be in form `kind/name`, where kind is `block`, `fieldset` or `enum`"))?;
let (kind, name) = key.split_once('/').ok_or(de::Error::custom("item names must be in form `kind/name`, where kind is `block`, `fieldset` or `enum`"))?;
match kind {
"block" => {
let val: Block = access.next_value()?;
Expand Down
28 changes: 10 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,9 @@ fn fmt(args: Fmt) -> Result<()> {

if args.remove_unused {
let mut used_enums = HashSet::new();
for (_, fs) in &mut ir.fieldsets {
for f in &mut fs.fields {
if let Some(enumm) = &f.enumm {
used_enums.insert(enumm.clone());
}
for fs in ir.fieldsets.values_mut() {
for f in fs.fields.iter_mut().filter(|f| f.enumm.is_some()) {
used_enums.insert(f.enumm.as_ref().unwrap().clone());
}
}

Expand All @@ -325,23 +323,23 @@ fn fmt(args: Fmt) -> Result<()> {
}
};

for (_, b) in &mut ir.blocks {
for b in ir.blocks.values_mut() {
cleanup(&mut b.description);
for i in &mut b.items {
for i in b.items.iter_mut() {
cleanup(&mut i.description);
}
}

for (_, b) in &mut ir.fieldsets {
for b in ir.fieldsets.values_mut() {
cleanup(&mut b.description);
for i in &mut b.fields {
for i in b.fields.iter_mut() {
cleanup(&mut i.description);
}
}

for (_, b) in &mut ir.enums {
for b in ir.enums.values_mut() {
cleanup(&mut b.description);
for i in &mut b.variants {
for i in b.variants.iter_mut() {
cleanup(&mut i.description);
}
}
Expand Down Expand Up @@ -404,7 +402,7 @@ fn gen_block(args: GenBlock) -> Result<()> {

Ok(())
}
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(Default, serde::Serialize, serde::Deserialize)]
struct Config {
transforms: Vec<chiptool::transform::Transform>,
}
Expand All @@ -415,9 +413,3 @@ impl FromIterator<Config> for Config {
Self { transforms }
}
}

impl Default for Config {
fn default() -> Self {
Self { transforms: vec![] }
}
}
8 changes: 4 additions & 4 deletions src/transform/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ impl Rename {
}
};

super::map_device_names(ir, &renamer);
super::map_block_names(ir, &renamer);
super::map_fieldset_names(ir, &renamer);
super::map_enum_names(ir, &renamer);
super::map_device_names(ir, renamer);
super::map_block_names(ir, renamer);
super::map_fieldset_names(ir, renamer);
super::map_enum_names(ir, renamer);

Ok(())
}
Expand Down