Skip to content

Commit 2176940

Browse files
committed
apply clippy suggestions
1 parent 29ad43c commit 2176940

File tree

6 files changed

+54
-58
lines changed

6 files changed

+54
-58
lines changed

src/generate/device.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
236236
Peripheral::Single(_p) => {
237237
let p_name = util::name_of(p, config.ignore_groups);
238238
let p_feature = feature_format.apply(&p_name);
239-
let p_ty = ident(&p_name, &config, "peripheral", span);
240-
let p_singleton = ident(&p_name, &config, "peripheral_singleton", span);
239+
let p_ty = ident(&p_name, config, "peripheral", span);
240+
let p_singleton = ident(&p_name, config, "peripheral_singleton", span);
241241
if config.feature_peripheral {
242242
feature_attribute.extend(quote! { #[cfg(feature = #p_feature)] })
243243
};
@@ -253,8 +253,8 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
253253
Peripheral::Array(p, dim_element) => {
254254
for p_name in names(p, dim_element) {
255255
let p_feature = feature_format.apply(&p_name);
256-
let p_ty = ident(&p_name, &config, "peripheral", span);
257-
let p_singleton = ident(&p_name, &config, "peripheral_singleton", span);
256+
let p_ty = ident(&p_name, config, "peripheral", span);
257+
let p_singleton = ident(&p_name, config, "peripheral_singleton", span);
258258
if config.feature_peripheral {
259259
feature_attribute.extend(quote! { #[cfg(feature = #p_feature)] })
260260
};

src/generate/interrupt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub fn render(
5555
}
5656
pos += 1;
5757

58-
let i_ty = ident(&interrupt.0.name, &config, "interrupt", span);
58+
let i_ty = ident(&interrupt.0.name, config, "interrupt", span);
5959
let description = format!(
6060
"{} - {}",
6161
interrupt.0.value,

src/generate/peripheral.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
3737

3838
let name = util::name_of(&p, config.ignore_groups);
3939
let span = Span::call_site();
40-
let p_ty = ident(&name, &config, "peripheral", span);
40+
let p_ty = ident(&name, config, "peripheral", span);
4141
let name_str = p_ty.to_string();
4242
let address = util::hex(p.base_address + config.base_address_shift);
4343
let description = util::respace(p.description.as_ref().unwrap_or(&p.name));
@@ -85,7 +85,7 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
8585
for pi in svd::peripheral::expand(p, dim) {
8686
let name = &pi.name;
8787
let description = pi.description.as_deref().unwrap_or(&p.name);
88-
let p_ty = ident(name, &config, "peripheral", span);
88+
let p_ty = ident(name, config, "peripheral", span);
8989
let name_str = p_ty.to_string();
9090
let doc_alias = (&name_str != name).then(|| quote!(#[doc(alias = #name)]));
9191
let address = util::hex(pi.base_address + config.base_address_shift);
@@ -640,8 +640,8 @@ fn register_or_cluster_block(
640640

641641
let mut doc_alias = None;
642642
let block_ty = if let Some(name) = name {
643-
let ty = ident(name, &config, "cluster", span);
644-
if ty.to_string() != name {
643+
let ty = ident(name, config, "cluster", span);
644+
if ty != name {
645645
doc_alias = Some(quote!(#[doc(alias = #name)]));
646646
}
647647
ty
@@ -996,12 +996,12 @@ fn expand_cluster(cluster: &Cluster, config: &Config) -> Result<Vec<RegisterBloc
996996
util::replace_suffix(&cluster.name, "")
997997
};
998998
let span = Span::call_site();
999-
let ty = name_to_ty(ident(&ty_name, &config, "cluster", span));
999+
let ty = name_to_ty(ident(&ty_name, config, "cluster", span));
10001000

10011001
match cluster {
10021002
Cluster::Single(info) => {
10031003
let doc = make_comment(cluster_size, info.address_offset, &description);
1004-
let name: Ident = ident(&info.name, &config, "cluster_accessor", span);
1004+
let name: Ident = ident(&info.name, config, "cluster_accessor", span);
10051005
let syn_field = new_syn_field(name.clone(), ty.clone());
10061006
cluster_expanded.push(RegisterBlockField {
10071007
syn_field,
@@ -1050,7 +1050,7 @@ fn expand_cluster(cluster: &Cluster, config: &Config) -> Result<Vec<RegisterBloc
10501050
} else {
10511051
&ty_name
10521052
},
1053-
&config,
1053+
config,
10541054
"cluster_accessor",
10551055
span,
10561056
);
@@ -1083,7 +1083,7 @@ fn expand_cluster(cluster: &Cluster, config: &Config) -> Result<Vec<RegisterBloc
10831083
});
10841084
if !sequential_indexes_from0 || !ends_with_index {
10851085
for (i, ci) in svd::cluster::expand(info, array_info).enumerate() {
1086-
let idx_name = ident(&ci.name, &config, "cluster_accessor", span);
1086+
let idx_name = ident(&ci.name, config, "cluster_accessor", span);
10871087
let doc = make_comment(
10881088
cluster_size,
10891089
ci.address_offset,
@@ -1125,7 +1125,7 @@ fn expand_cluster(cluster: &Cluster, config: &Config) -> Result<Vec<RegisterBloc
11251125
ci.address_offset,
11261126
ci.description.as_deref().unwrap_or(&ci.name),
11271127
);
1128-
let name = ident(&ci.name, &config, "cluster_accessor", span);
1128+
let name = ident(&ci.name, config, "cluster_accessor", span);
11291129
let syn_field = new_syn_field(name.clone(), ty.clone());
11301130

11311131
cluster_expanded.push(RegisterBlockField {
@@ -1176,8 +1176,8 @@ fn expand_register(
11761176
Register::Single(info) => {
11771177
let doc = make_comment(register_size, info.address_offset, &description);
11781178
let span = Span::call_site();
1179-
let ty = name_to_ty(ident(&ty_str, &config, "register", span));
1180-
let name: Ident = ident(&ty_name, &config, "register_accessor", span);
1179+
let ty = name_to_ty(ident(&ty_str, config, "register", span));
1180+
let name: Ident = ident(&ty_name, config, "register_accessor", span);
11811181
let syn_field = new_syn_field(name.clone(), ty.clone());
11821182
register_expanded.push(RegisterBlockField {
11831183
syn_field,
@@ -1232,18 +1232,18 @@ fn expand_register(
12321232
let array_convertible = ac && sequential_addresses;
12331233
let array_proxy_convertible = ac && disjoint_sequential_addresses;
12341234
let span = Span::call_site();
1235-
let ty = name_to_ty(ident(&ty_str, &config, "register", span));
1235+
let ty = name_to_ty(ident(&ty_str, config, "register", span));
12361236

12371237
if array_convertible || array_proxy_convertible {
12381238
let accessor_name = if let Some(dim_name) = array_info.dim_name.as_ref() {
12391239
ident(
12401240
&util::fullname(dim_name, &info.alternate_group, config.ignore_groups),
1241-
&config,
1241+
config,
12421242
"register_accessor",
12431243
span,
12441244
)
12451245
} else {
1246-
ident(&ty_name, &config, "register_accessor", span)
1246+
ident(&ty_name, config, "register_accessor", span)
12471247
};
12481248
let doc = make_comment(
12491249
register_size * array_info.dim,
@@ -1276,7 +1276,7 @@ fn expand_register(
12761276
for (i, ri) in svd::register::expand(info, array_info).enumerate() {
12771277
let idx_name = ident(
12781278
&util::fullname(&ri.name, &info.alternate_group, config.ignore_groups),
1279-
&config,
1279+
config,
12801280
"cluster_accessor",
12811281
span,
12821282
);
@@ -1321,7 +1321,7 @@ fn expand_register(
13211321
info.address_offset,
13221322
ri.description.as_deref().unwrap_or(&ri.name),
13231323
);
1324-
let name = ident(&ri.name, &config, "register_accessor", span);
1324+
let name = ident(&ri.name, config, "register_accessor", span);
13251325
let syn_field = new_syn_field(name.clone(), ty.clone());
13261326

13271327
register_expanded.push(RegisterBlockField {
@@ -1404,7 +1404,7 @@ fn cluster_block(
14041404
// name_snake_case needs to take into account array type.
14051405
let span = Span::call_site();
14061406
let mod_ty = ident(&mod_name, config, "cluster_mod", span);
1407-
let block_ty = ident(&mod_name, &config, "cluster", span);
1407+
let block_ty = ident(&mod_name, config, "cluster", span);
14081408

14091409
if let Some(dpath) = dpath {
14101410
let dparent = dpath.parent().unwrap();
@@ -1418,7 +1418,7 @@ fn cluster_block(
14181418
derived
14191419
.path
14201420
.segments
1421-
.push(path_segment(ident(&dname, &config, "cluster", span)));
1421+
.push(path_segment(ident(&dname, config, "cluster", span)));
14221422
mod_derived
14231423
.path
14241424
.segments

src/generate/register.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use anyhow::{anyhow, Result};
2222
use syn::punctuated::Punctuated;
2323

2424
fn regspec(name: &str, config: &Config, span: Span) -> Ident {
25-
ident(name, &config, "register_spec", span)
25+
ident(name, config, "register_spec", span)
2626
}
2727

2828
fn field_accessor(name: &str, config: &Config, span: Span) -> Ident {
@@ -60,8 +60,8 @@ pub fn render(
6060
}
6161
}
6262
let span = Span::call_site();
63-
let reg_ty = ident(&name, &config, "register", span);
64-
let doc_alias = (&reg_ty.to_string() != &name).then(|| quote!(#[doc(alias = #name)]));
63+
let reg_ty = ident(&name, config, "register", span);
64+
let doc_alias = (reg_ty.to_string().as_str() != name).then(|| quote!(#[doc(alias = #name)]));
6565
let mod_ty = ident(&name, config, "register_mod", span);
6666
let description = util::escape_special_chars(
6767
util::respace(&register.description.clone().unwrap_or_else(|| {
@@ -82,7 +82,7 @@ pub fn render(
8282
derived
8383
.path
8484
.segments
85-
.push(path_segment(ident(&dname, &config, "register", span)));
85+
.push(path_segment(ident(&dname, config, "register", span)));
8686
mod_derived
8787
.path
8888
.segments
@@ -656,7 +656,7 @@ pub fn fields(
656656
{
657657
ident(
658658
evs.name.as_deref().unwrap_or(&name),
659-
&config,
659+
config,
660660
"enum_name",
661661
span,
662662
)
@@ -666,7 +666,7 @@ pub fn fields(
666666
};
667667

668668
// name of read proxy type
669-
let reader_ty = ident(&name, &config, "field_reader", span);
669+
let reader_ty = ident(&name, config, "field_reader", span);
670670

671671
// if it's enumeratedValues and it's derived from base, don't derive the read proxy
672672
// as the base has already dealt with this;
@@ -861,7 +861,7 @@ pub fn fields(
861861
evs_r = Some(evs);
862862
// generate pub use field_1 reader as field_2 reader
863863
let base_field = util::replace_suffix(&base.field.name, "");
864-
let base_r = ident(&base_field, &config, "field_reader", span);
864+
let base_r = ident(&base_field, config, "field_reader", span);
865865
if !reader_derives.contains(&reader_ty) {
866866
let base_path = base_syn_path(base, &fpath, &base_r, config)?;
867867
mod_items.extend(quote! {
@@ -977,14 +977,14 @@ pub fn fields(
977977
} else {
978978
"enum_name"
979979
};
980-
ident(evs.name.as_deref().unwrap_or(&name), &config, fmt, span)
980+
ident(evs.name.as_deref().unwrap_or(&name), config, fmt, span)
981981
} else {
982982
// raw_field_value_write_ty
983983
fty.clone()
984984
};
985985

986986
// name of write proxy type
987-
let writer_ty = ident(&name, &config, "field_writer", span);
987+
let writer_ty = ident(&name, config, "field_writer", span);
988988

989989
let mut proxy_items = TokenStream::new();
990990
let mut unsafety = unsafety(f.write_constraint.as_ref(), width);
@@ -1136,7 +1136,7 @@ pub fn fields(
11361136

11371137
// generate pub use field_1 writer as field_2 writer
11381138
let base_field = util::replace_suffix(&base.field.name, "");
1139-
let base_w = ident(&base_field, &config, "field_writer", span);
1139+
let base_w = ident(&base_field, config, "field_writer", span);
11401140
if !writer_derives.contains(&writer_ty) {
11411141
let base_path = base_syn_path(base, &fpath, &base_w, config)?;
11421142
mod_items.extend(quote! {
@@ -1304,7 +1304,7 @@ impl Variant {
13041304
.description
13051305
.clone()
13061306
.unwrap_or_else(|| format!("`{value:b}`")),
1307-
pc: ident(&ev.name, &config, "enum_value", span),
1307+
pc: ident(&ev.name, config, "enum_value", span),
13081308
is_sc,
13091309
sc,
13101310
value,

src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn parse_configs(app: Command) -> Result<Config> {
3939

4040
if let Some(ident_formats) = ident_formats.get_many::<String>("ident_format") {
4141
for f in ident_formats {
42-
let mut f = f.split(":");
42+
let mut f = f.split(':');
4343
if let (Some(n), Some(p), Some(c), Some(s)) = (f.next(), f.next(), f.next(), f.next()) {
4444
let case = match c {
4545
"" | "unchanged" | "svd" => None,
@@ -335,23 +335,23 @@ Ignore this option if you are not building your own FPGA based soft-cores."),
335335
let mut features = Vec::new();
336336
if config.feature_group {
337337
features.extend(
338-
util::group_names(&device, &feature_format)
338+
util::group_names(&device, feature_format)
339339
.iter()
340340
.map(|s| format!("{s} = []\n")),
341341
);
342-
let add_groups: Vec<_> = util::group_names(&device, &feature_format)
342+
let add_groups: Vec<_> = util::group_names(&device, feature_format)
343343
.iter()
344344
.map(|s| format!("\"{s}\""))
345345
.collect();
346346
features.push(format!("all-groups = [{}]\n", add_groups.join(",")))
347347
}
348348
if config.feature_peripheral {
349349
features.extend(
350-
util::peripheral_names(&device, &feature_format)
350+
util::peripheral_names(&device, feature_format)
351351
.iter()
352352
.map(|s| format!("{s} = []\n")),
353353
);
354-
let add_peripherals: Vec<_> = util::peripheral_names(&device, &feature_format)
354+
let add_peripherals: Vec<_> = util::peripheral_names(&device, feature_format)
355355
.iter()
356356
.map(|s| format!("\"{s}\""))
357357
.collect();

src/util.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,22 @@ fn to_pascal_case(s: &str) -> String {
3333
if let Some(&"") = parts.peek() {
3434
string.push('_');
3535
}
36-
loop {
37-
if let Some(p) = parts.next() {
38-
if p.is_empty() {
39-
continue;
36+
while let Some(p) = parts.next() {
37+
if p.is_empty() {
38+
continue;
39+
}
40+
string.push_str(&p.to_pascal_case());
41+
match parts.peek() {
42+
Some(nxt)
43+
if p.ends_with(|s: char| s.is_numeric())
44+
&& nxt.starts_with(|s: char| s.is_numeric()) =>
45+
{
46+
string.push('_');
4047
}
41-
string.push_str(&p.to_pascal_case());
42-
match parts.peek() {
43-
Some(nxt)
44-
if p.ends_with(|s: char| s.is_numeric())
45-
&& nxt.starts_with(|s: char| s.is_numeric()) =>
46-
{
47-
string.push('_');
48-
}
49-
Some(&"") => {
50-
string.push('_');
51-
}
52-
_ => {}
48+
Some(&"") => {
49+
string.push('_');
5350
}
54-
} else {
55-
break;
51+
_ => {}
5652
}
5753
}
5854
string
@@ -310,7 +306,7 @@ pub fn block_path_to_ty(
310306
span,
311307
)));
312308
for ps in &bpath.path {
313-
segments.push(path_segment(ident(&ps, config, "cluster_mod", span)));
309+
segments.push(path_segment(ident(ps, config, "cluster_mod", span)));
314310
}
315311
type_path(segments)
316312
}

0 commit comments

Comments
 (0)