Skip to content

Commit 2ed3a52

Browse files
committed
zephyr-build: Fix clippy warnings
These are all straightforward source transformations, suggested by clippy, that make the code more idiomatic Rust. Signed-off-by: David Brown <[email protected]>
1 parent a88ec3b commit 2ed3a52

File tree

5 files changed

+27
-37
lines changed

5 files changed

+27
-37
lines changed

zephyr-build/src/devicetree.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
//! different ways:
66
//!
77
//! - Canonical DTS. There is a single DTS file (`build/zephyr/zephyr.dts`) that contains the final
8-
//! tree, but still in DTS format (the DTB file would have information discarded).
8+
//! tree, but still in DTS format (the DTB file would have information discarded).
99
//!
1010
//! - Generated. The C header `devicetree_generated.h` contains all of the definitions. This isn't
11-
//! a particularly friendly file to read or parse, but it does have one piece of information that is
12-
//! not represented anywhere else: the mapping between devicetree nodes and their "ORD" index. The
13-
//! device nodes in the system are indexed by this number, and we need this in order to be able to
14-
//! reference the nodes from Rust.
11+
//! a particularly friendly file to read or parse, but it does have one piece of information that is
12+
//! not represented anywhere else: the mapping between devicetree nodes and their "ORD" index. The
13+
//! device nodes in the system are indexed by this number, and we need this in order to be able to
14+
//! reference the nodes from Rust.
1515
//!
1616
//! Beyond the ORD field, it seems easier to deal with the DTS file itself. Parsing is fairly
1717
//! straightforward, as it is a subset of the DTS format, and we only have to be able to deal with

zephyr-build/src/devicetree/augment.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,10 @@ fn parent_compatible(node: &Node, names: &[String], level: usize) -> bool {
112112
// runs on the host, so the stack is easier.
113113
if level == 0 {
114114
names.iter().any(|n| node.is_compatible(n))
115+
} else if let Some(parent) = node.parent.borrow().as_ref() {
116+
parent_compatible(parent, names, level - 1)
115117
} else {
116-
if let Some(parent) = node.parent.borrow().as_ref() {
117-
parent_compatible(parent, names, level - 1)
118-
} else {
119-
false
120-
}
118+
false
121119
}
122120
}
123121

zephyr-build/src/devicetree/output.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl DeviceTree {
2222
// Root is a little special. Since we don't want a module for this (it will be provided
2323
// above where it is included, so it can get documentation and attributes), we use None for
2424
// the name.
25-
self.node_walk(self.root.as_ref(), None, &augments)
25+
self.node_walk(self.root.as_ref(), None, augments)
2626
}
2727

2828
// Write, to the given writer, CFG lines so that Rust code can conditionalize based on the DT.
@@ -98,14 +98,11 @@ impl DeviceTree {
9898
match value {
9999
Value::Words(ref words) => {
100100
if words.len() == 1 {
101-
match &words[0] {
102-
Word::Number(n) => {
103-
let tag = dt_to_upper_id(&prop.name);
104-
return quote! {
105-
pub const #tag: u32 = #n;
106-
};
107-
}
108-
_ => (),
101+
if let Word::Number(n) = &words[0] {
102+
let tag = dt_to_upper_id(&prop.name);
103+
return quote! {
104+
pub const #tag: u32 = #n;
105+
};
109106
}
110107
}
111108
}
@@ -173,15 +170,13 @@ impl Property {
173170
// If this property is a single top-level phandle, output that a that path is valid. It isn't a
174171
// real node, but acts like one.
175172
fn output_path<W: Write>(&self, write: &mut W, name: &str) -> Result<()> {
176-
if let Some(value) = self.get_single_value() {
177-
if let Value::Phandle(_) = value {
178-
writeln!(
179-
write,
180-
"cargo:rustc-cfg=dt=\"{}::{}\"",
181-
name,
182-
fix_id(&self.name)
183-
)?;
184-
}
173+
if let Some(Value::Phandle(_)) = self.get_single_value() {
174+
writeln!(
175+
write,
176+
"cargo:rustc-cfg=dt=\"{}::{}\"",
177+
name,
178+
fix_id(&self.name)
179+
)?;
185180
}
186181
Ok(())
187182
}

zephyr-build/src/devicetree/parse.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<'a> TreeBuilder<'a> {
6060
println!("Root: {:?} {}", name, ord);
6161
*/
6262

63-
let mut name = LazyName::new(path, route.to_owned(), &self.ords);
63+
let mut name = LazyName::new(path, route.to_owned(), self.ords);
6464
let mut labels = Vec::new();
6565
let mut properties = Vec::new();
6666
let mut children = Vec::new();
@@ -79,7 +79,7 @@ impl<'a> TreeBuilder<'a> {
7979
}
8080
Rule::node => {
8181
let child_path = name.path_ref();
82-
children.push(self.walk_node(pair, child_path, &name.route_ref()));
82+
children.push(self.walk_node(pair, child_path, name.route_ref()));
8383
}
8484
r => panic!("node: {:?}", r),
8585
}
@@ -140,7 +140,7 @@ fn decode_property(node: Pair<'_, Rule>) -> Property {
140140
}
141141
}
142142

143-
fn decode_words<'i>(node: Pair<'i, Rule>) -> Vec<Word> {
143+
fn decode_words(node: Pair<'_, Rule>) -> Vec<Word> {
144144
let mut value = Vec::new();
145145
for pair in node.into_inner() {
146146
match pair.as_rule() {
@@ -151,7 +151,7 @@ fn decode_words<'i>(node: Pair<'i, Rule>) -> Vec<Word> {
151151
}
152152
Rule::decimal_number => {
153153
let text = pair.as_str();
154-
let num = u32::from_str_radix(text, 10).unwrap();
154+
let num = text.parse::<u32>().unwrap();
155155
value.push(Word::Number(num));
156156
}
157157
Rule::phandle => {
@@ -165,7 +165,7 @@ fn decode_words<'i>(node: Pair<'i, Rule>) -> Vec<Word> {
165165
value
166166
}
167167

168-
fn decode_bytes<'i>(node: Pair<'i, Rule>) -> Vec<u8> {
168+
fn decode_bytes(node: Pair<'_, Rule>) -> Vec<u8> {
169169
let mut value = Vec::new();
170170
for pair in node.into_inner() {
171171
match pair.as_rule() {

zephyr-build/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ pub fn dt_cfgs() {
135135

136136
/// Determine if `rustfmt` is in the path, and can be excecuted. Returns false on any kind of error.
137137
pub fn has_rustfmt() -> bool {
138-
match Command::new("rustfmt").arg("--version").status() {
139-
Ok(st) if st.success() => true,
140-
_ => false,
141-
}
138+
matches!(Command::new("rustfmt").arg("--version").status(), Ok(st) if st.success())
142139
}
143140

144141
/// Attempt to write the contents to a file, using rustfmt. If there is an error running rustfmt,

0 commit comments

Comments
 (0)