Skip to content

Commit 307e112

Browse files
committed
clippy
1 parent 70592bd commit 307e112

12 files changed

+33
-32
lines changed

src/elementext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl ElementExt for Element {
4747
K: core::fmt::Display + Clone,
4848
{
4949
self.get_child_text_opt(k.clone())?
50-
.ok_or(SVDErrorKind::MissingTag(self.clone(), format!("{}", k)).into())
50+
.ok_or_else(|| SVDErrorKind::MissingTag(self.clone(), format!("{}", k)).into())
5151
}
5252

5353
/// Get text contained by an XML Element

src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct SVDError {
1212

1313
// TODO: Expand and make more complex output possible.
1414
// We can use the `Element` to output name (if available) and etc.
15+
#[allow(clippy::large_enum_variant)]
1516
#[derive(Clone, Debug, PartialEq, Eq, Fail)]
1617
pub enum SVDErrorKind {
1718
#[fail(display = "Unknown endianness `{}`", _0)]

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub(crate) fn new_element(name: &str, text: Option<String>) -> Element {
8383
name: String::from(name),
8484
attributes: HashMap::new(),
8585
children: Vec::new(),
86-
text: text,
86+
text,
8787
}
8888
}
8989

src/svd/bitrange.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ impl Parse for BitRange {
3333
let text = range
3434
.text
3535
.as_ref()
36-
.ok_or(SVDErrorKind::Other(format!("text missing")))?; // TODO: Make into a proper error, text empty or something similar
37-
// TODO: If the `InvalidBitRange` enum was an error we could context into here somehow so that
38-
// the output would be similar to the parse error
36+
.ok_or_else(|| SVDErrorKind::Other("text missing".to_string()))?; // TODO: Make into a proper error, text empty or something similar
37+
// TODO: If the `InvalidBitRange` enum was an error we could context into here somehow so that
38+
// the output would be similar to the parse error
3939
if !text.starts_with('[') {
4040
return Err(
4141
SVDErrorKind::InvalidBitRange(tree.clone(), InvalidBitRange::Syntax).into(),
@@ -51,21 +51,19 @@ impl Parse for BitRange {
5151
(
5252
parts
5353
.next()
54-
.ok_or(SVDErrorKind::InvalidBitRange(
55-
tree.clone(),
56-
InvalidBitRange::Syntax,
57-
))?
54+
.ok_or_else(|| {
55+
SVDErrorKind::InvalidBitRange(tree.clone(), InvalidBitRange::Syntax)
56+
})?
5857
.parse::<u32>()
5958
.context(SVDErrorKind::InvalidBitRange(
6059
tree.clone(),
6160
InvalidBitRange::ParseError,
6261
))?,
6362
parts
6463
.next()
65-
.ok_or(SVDErrorKind::InvalidBitRange(
66-
tree.clone(),
67-
InvalidBitRange::Syntax,
68-
))?
64+
.ok_or_else(|| {
65+
SVDErrorKind::InvalidBitRange(tree.clone(), InvalidBitRange::Syntax)
66+
})?
6967
.parse::<u32>()
7068
.context(SVDErrorKind::InvalidBitRange(
7169
tree.clone(),
@@ -116,7 +114,7 @@ impl Parse for BitRange {
116114
Ok(BitRange {
117115
offset: start,
118116
width: end - start + 1,
119-
range_type: range_type,
117+
range_type,
120118
})
121119
}
122120
}

src/svd/device.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Parse for Device {
3737
fn parse(tree: &Element) -> Result<Device, SVDError> {
3838
Ok(Device {
3939
name: tree.get_child_text("name")?,
40-
schema_version: tree.attributes.get("schemaVersion").map(|s| s.clone()),
40+
schema_version: tree.attributes.get("schemaVersion").cloned(),
4141
cpu: parse::optional::<Cpu>("cpu", tree)?,
4242
version: tree.get_child_text_opt("version")?,
4343
description: tree.get_child_text_opt("description")?,

src/svd/enumeratedvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Parse for EnumeratedValue {
4343
fn parse(tree: &Element) -> Result<EnumeratedValue, SVDError> {
4444
if tree.name != "enumeratedValue" {
4545
return Err(
46-
SVDErrorKind::NotExpectedTag(tree.clone(), format!("enumeratedValue")).into(),
46+
SVDErrorKind::NotExpectedTag(tree.clone(), "enumeratedValue".to_string()).into(),
4747
);
4848
}
4949
let name = tree.get_child_text("name")?;

src/svd/enumeratedvalues.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ impl Parse for EnumeratedValues {
4848
.enumerate()
4949
.map(|(e, t)| {
5050
if t.name == "enumeratedValue" {
51-
EnumeratedValue::parse(t).context(SVDErrorKind::Other(
52-
format!("Parsing enumerated value #{}", e).into(),
53-
))
51+
EnumeratedValue::parse(t).context(SVDErrorKind::Other(format!(
52+
"Parsing enumerated value #{}",
53+
e
54+
)))
5455
} else {
55-
Err(
56-
SVDErrorKind::NotExpectedTag(t.clone(), format!("enumeratedValue"))
57-
.into(),
56+
Err(SVDErrorKind::NotExpectedTag(
57+
t.clone(),
58+
"enumeratedValue".to_string(),
5859
)
60+
.into())
5961
}
6062
})
6163
.collect();

src/svd/field.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl Parse for Field {
3838
type Error = SVDError;
3939
fn parse(tree: &Element) -> Result<Field, SVDError> {
4040
if tree.name != "field" {
41-
return Err(SVDErrorKind::NotExpectedTag(tree.clone(), format!("field")).into());
41+
return Err(SVDErrorKind::NotExpectedTag(tree.clone(), "field".to_string()).into());
4242
}
4343
let name = tree.get_child_text("name")?;
4444
Field::_parse(tree, name.clone())

src/svd/interrupt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl Parse for Interrupt {
3636
type Error = SVDError;
3737
fn parse(tree: &Element) -> Result<Interrupt, SVDError> {
3838
if tree.name != "interrupt" {
39-
return Err(SVDErrorKind::NotExpectedTag(tree.clone(), format!("interrupt")).into());
39+
return Err(SVDErrorKind::NotExpectedTag(tree.clone(), "interrupt".to_string()).into());
4040
}
4141
let name = tree.get_child_text("name")?;
4242
Interrupt::_parse(tree, name.clone())

src/svd/peripheral.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ impl Parse for Peripheral {
4444

4545
fn parse(tree: &Element) -> Result<Peripheral, SVDError> {
4646
if tree.name != "peripheral" {
47-
return Err(SVDErrorKind::NotExpectedTag(tree.clone(), format!("peripheral")).into());
47+
return Err(
48+
SVDErrorKind::NotExpectedTag(tree.clone(), "peripheral".to_string()).into(),
49+
);
4850
}
4951
let name = tree.get_child_text("name")?;
5052
Peripheral::_parse(tree, name.clone())
@@ -84,9 +86,8 @@ impl Peripheral {
8486
.filter(|t| t.name == "interrupt")
8587
.enumerate()
8688
.map(|(e, i)| {
87-
Interrupt::parse(i).context(SVDErrorKind::Other(
88-
format!("Parsing interrupt #{}", e).into(),
89-
))
89+
Interrupt::parse(i)
90+
.context(SVDErrorKind::Other(format!("Parsing interrupt #{}", e)))
9091
})
9192
.collect();
9293
interrupt?

0 commit comments

Comments
 (0)