Skip to content

Commit 3dd4d53

Browse files
committed
Run cargo clippy and fmt
1 parent 9f1a17a commit 3dd4d53

File tree

10 files changed

+118
-127
lines changed

10 files changed

+118
-127
lines changed

rust/.clippy.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
avoid-breaking-exported-api = true
2+
msrv = "1.71.0"

rust/cmsis-cffi/src/config.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct Config {
1212
pack_store: PathBuf,
1313
}
1414

15+
#[derive(Default)]
1516
pub struct ConfigBuilder {
1617
pack_store: Option<PathBuf>,
1718
}
@@ -40,12 +41,6 @@ impl ConfigBuilder {
4041
}
4142
}
4243

43-
impl Default for ConfigBuilder {
44-
fn default() -> Self {
45-
Self { pack_store: None }
46-
}
47-
}
48-
4944
impl Config {
5045
pub fn new() -> Result<Config, Error> {
5146
ConfigBuilder::default().build()

rust/cmsis-cli/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ impl Config {
6868
}
6969
match OpenOptions::new()
7070
.create(true)
71+
.truncate(true)
7172
.write(true)
7273
.open(&self.vidx_list)
7374
{

rust/cmsis-cli/src/lib.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn install_args() -> App<'static, 'static> {
6262
)
6363
}
6464

65-
pub fn install_command<'a>(conf: &Config, args: &ArgMatches<'a>) -> Result<(), Error> {
65+
pub fn install_command(conf: &Config, args: &ArgMatches<'_>) -> Result<(), Error> {
6666
let pdsc_list: Vec<_> = args
6767
.values_of("PDSC")
6868
.unwrap()
@@ -91,7 +91,7 @@ pub fn update_args<'a, 'b>() -> App<'a, 'b> {
9191
.version("0.1.0")
9292
}
9393

94-
pub fn update_command<'a>(conf: &Config, _: &ArgMatches<'a>) -> Result<(), Error> {
94+
pub fn update_command(conf: &Config, _: &ArgMatches<'_>) -> Result<(), Error> {
9595
let vidx_list = conf.read_vidx_list();
9696
for url in vidx_list.iter() {
9797
log::info!("Updating registry from `{}`", url);
@@ -136,7 +136,7 @@ pub fn dump_devices_args<'a, 'b>() -> App<'a, 'b> {
136136
)
137137
}
138138

139-
pub fn dump_devices_command<'a>(c: &Config, args: &ArgMatches<'a>) -> Result<(), Error> {
139+
pub fn dump_devices_command(c: &Config, args: &ArgMatches<'_>) -> Result<(), Error> {
140140
let files = args
141141
.value_of("INPUT")
142142
.map(|input| vec![Path::new(input).to_path_buf()]);
@@ -175,27 +175,27 @@ pub fn check_args<'a, 'b>() -> App<'a, 'b> {
175175
)
176176
}
177177

178-
pub fn check_command<'a>(_: &Config, args: &ArgMatches<'a>) -> Result<(), Error> {
178+
pub fn check_command(_: &Config, args: &ArgMatches<'_>) -> Result<(), Error> {
179179
let filename = args.value_of("INPUT").unwrap();
180180
match Package::from_path(Path::new(filename)) {
181181
Ok(c) => {
182182
log::info!("Parsing succedded");
183-
log::info!("{} Valid Conditions", c.conditions.0.iter().count());
183+
log::info!("{} Valid Conditions", c.conditions.0.len());
184184
let cond_lookup = c.make_condition_lookup();
185185
let mut num_components = 0;
186186
let mut num_files = 0;
187-
for &Component {
188-
ref class,
189-
ref group,
190-
ref condition,
191-
ref files,
187+
for Component {
188+
class,
189+
group,
190+
condition,
191+
files,
192192
..
193193
} in c.make_components().iter()
194194
{
195195
num_components += 1;
196-
num_files += files.iter().count();
196+
num_files += files.len();
197197
if let Some(ref cond_name) = condition {
198-
if cond_lookup.get(cond_name.as_str()).is_none() {
198+
if !cond_lookup.contains_key(cond_name.as_str()) {
199199
log::warn!(
200200
"Component {}::{} references an unknown condition '{}'",
201201
class,
@@ -204,14 +204,12 @@ pub fn check_command<'a>(_: &Config, args: &ArgMatches<'a>) -> Result<(), Error>
204204
);
205205
}
206206
}
207-
for &FileRef {
208-
ref path,
209-
ref condition,
210-
..
207+
for FileRef {
208+
path, condition, ..
211209
} in files.iter()
212210
{
213211
if let Some(ref cond_name) = condition {
214-
if cond_lookup.get(cond_name.as_str()).is_none() {
212+
if !cond_lookup.contains_key(cond_name.as_str()) {
215213
log::warn!(
216214
"File {:?} Component {}::{} references an unknown condition '{}'",
217215
path,

rust/cmsis-pack/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::upper_case_acronyms)]
2+
13
pub mod pack_index;
24
pub mod pdsc;
35
pub mod update;

rust/cmsis-pack/src/pdsc/device.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,13 @@ impl ProcessorBuilder {
162162
mpu: self.mpu.or(other.mpu.clone()),
163163
}
164164
}
165-
fn build(self, debugs: &Vec<Debug>) -> Result<Vec<Processor>, Error> {
165+
fn build(self, debugs: &[Debug]) -> Result<Vec<Processor>, Error> {
166166
let units = self.units.unwrap_or(1);
167167
let name = self.name.clone();
168168

169-
let map = (0..units)
169+
170+
171+
(0..units)
170172
.map(|unit| {
171173
// The attributes we're interested in may be spread across multiple debug
172174
// attributes defined in the family, subfamily, or device; and which may or may not
@@ -176,7 +178,10 @@ impl ProcessorBuilder {
176178
// family and subfamily debug elements are appended after device debug elements.
177179
let debugs_iterator = debugs.iter().filter(|debug| {
178180
// If Pname or Punit are present on the <debug> element, they must match.
179-
debug.name.as_ref().map_or(true, |n| Some(n) == name.as_ref())
181+
debug
182+
.name
183+
.as_ref()
184+
.map_or(true, |n| Some(n) == name.as_ref())
180185
&& debug.unit.map_or(true, |u| u == unit)
181186
});
182187

@@ -204,9 +209,7 @@ impl ProcessorBuilder {
204209
.find_map(|d| d.default_reset_sequence.clone()),
205210
})
206211
})
207-
.collect::<Result<Vec<_>, _>>();
208-
209-
map
212+
.collect::<Result<Vec<_>, _>>()
210213
}
211214
}
212215

@@ -240,7 +243,7 @@ impl ProcessorsBuilder {
240243
}
241244

242245
fn merge_into(&mut self, other: Self) {
243-
self.0.extend(other.0.into_iter());
246+
self.0.extend(other.0);
244247
}
245248

246249
fn build(self, debugs: Vec<Debug>) -> Result<Vec<Processor>, Error> {
@@ -362,12 +365,12 @@ impl DebugsBuilder {
362365

363366
impl DebugsBuilder {
364367
fn merge(mut self, parent: &Self) -> Self {
365-
self.0.extend(parent.0.iter().map(|v| v.clone()));
368+
self.0.extend(parent.0.iter().cloned());
366369
self
367370
}
368371

369372
fn merge_into(&mut self, other: Self) {
370-
self.0.extend(other.0.into_iter())
373+
self.0.extend(other.0)
371374
}
372375

373376
fn build(self) -> Vec<Debug> {
@@ -418,9 +421,9 @@ enum NumberBool {
418421
True,
419422
}
420423

421-
impl Into<bool> for NumberBool {
422-
fn into(self) -> bool {
423-
match self {
424+
impl From<NumberBool> for bool {
425+
fn from(val: NumberBool) -> Self {
426+
match val {
424427
NumberBool::True => true,
425428
NumberBool::False => false,
426429
}
@@ -554,7 +557,7 @@ impl FromElem for Algorithm {
554557
let file_name: &str = attr_map(e, "name")?;
555558
let style = attr_parse(e, "style").ok().unwrap_or(AlgorithmStyle::Keil);
556559
Ok(Self {
557-
file_name: file_name.replace("\\", "/").into(),
560+
file_name: file_name.replace('\\', "/").into(),
558561
start: attr_parse_hex(e, "start")?,
559562
size: attr_parse_hex(e, "size")?,
560563
ram_start: attr_parse_hex(e, "RAMstart").ok(),
@@ -680,7 +683,7 @@ impl<'dom> DeviceBuilder<'dom> {
680683
}
681684
}
682685

683-
fn parse_device<'dom>(e: &'dom Element) -> Vec<DeviceBuilder<'dom>> {
686+
fn parse_device(e: &Element) -> Vec<DeviceBuilder<'_>> {
684687
let mut device = DeviceBuilder::from_elem(e);
685688
let variants = e
686689
.children()
@@ -723,7 +726,7 @@ fn parse_device<'dom>(e: &'dom Element) -> Vec<DeviceBuilder<'dom>> {
723726
}
724727
}
725728

726-
fn parse_sub_family<'dom>(e: &'dom Element) -> Vec<DeviceBuilder<'dom>> {
729+
fn parse_sub_family(e: &Element) -> Vec<DeviceBuilder<'_>> {
727730
let mut sub_family_device = DeviceBuilder::from_elem(e);
728731
let devices = e
729732
.children()
@@ -808,14 +811,10 @@ pub struct Devices(pub HashMap<String, Device>);
808811
impl FromElem for Devices {
809812
fn from_elem(e: &Element) -> Result<Self, Error> {
810813
e.children()
811-
.fold(Ok(HashMap::new()), |res, c| match (res, parse_family(c)) {
812-
(Ok(mut devs), Ok(add_this)) => {
813-
devs.extend(add_this.into_iter().map(|dev| (dev.name.clone(), dev)));
814-
Ok(devs)
815-
}
816-
(Ok(_), Err(e)) => Err(e),
817-
(Err(e), Ok(_)) => Err(e),
818-
(Err(e), Err(_)) => Err(e),
814+
.try_fold(HashMap::new(), |mut res, c| {
815+
let add_this = parse_family(c)?;
816+
res.extend(add_this.into_iter().map(|dev| (dev.name.clone(), dev)));
817+
Ok(res)
819818
})
820819
.map(Devices)
821820
}

rust/cmsis-pack/src/pdsc/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ impl Package {
220220
.collect()
221221
}
222222

223-
pub fn make_condition_lookup<'a>(&'a self) -> HashMap<&'a str, &'a Condition> {
224-
let mut map = HashMap::with_capacity(self.conditions.0.iter().count());
223+
pub fn make_condition_lookup(&self) -> HashMap<&str, &Condition> {
224+
let mut map = HashMap::with_capacity(self.conditions.0.len());
225225
for cond in self.conditions.0.iter() {
226226
if let Some(dup) = map.insert(cond.id.as_str(), cond) {
227227
log::warn!("Duplicate Condition found {}", dup.id);
@@ -230,7 +230,7 @@ impl Package {
230230
map
231231
}
232232

233-
pub fn make_dump_devices<'a>(&'a self) -> Vec<(&'a str, DumpDevice<'a>)> {
233+
pub fn make_dump_devices(&self) -> Vec<(&str, DumpDevice<'_>)> {
234234
let from_pack = FromPack::new(
235235
&self.vendor,
236236
&self.name,

0 commit comments

Comments
 (0)