Skip to content

Commit 4b8b02b

Browse files
committed
Fix clippy lints in util.rs and use rustfmt
Signed-off-by: Daniel Egger <daniel@eggers-club.de>
1 parent 6987ca9 commit 4b8b02b

File tree

1 file changed

+41
-21
lines changed

1 file changed

+41
-21
lines changed

src/util.rs

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::borrow::Cow;
22

3-
use inflections::Inflect;
3+
use crate::quote::{ToTokens, TokenStreamExt};
44
use crate::svd::{Access, Cluster, Register, RegisterCluster};
5-
use proc_macro2::{TokenStream, Ident, Span, Literal};
6-
use crate::quote::{TokenStreamExt, ToTokens};
5+
use inflections::Inflect;
6+
use proc_macro2::{Ident, Literal, Span, TokenStream};
77

88
use crate::errors::*;
99

@@ -165,19 +165,19 @@ pub fn escape_brackets(s: &str) -> String {
165165
if acc == "" {
166166
x.to_string()
167167
} else if acc.ends_with('\\') {
168-
acc.to_owned() + "[" + &x.to_string()
168+
acc + "[" + &x.to_string()
169169
} else {
170-
acc.to_owned() + "\\[" + &x.to_string()
170+
acc + "\\[" + &x.to_string()
171171
}
172172
})
173173
.split(']')
174174
.fold("".to_string(), |acc, x| {
175175
if acc == "" {
176176
x.to_string()
177177
} else if acc.ends_with('\\') {
178-
acc.to_owned() + "]" + &x.to_string()
178+
acc + "]" + &x.to_string()
179179
} else {
180-
acc.to_owned() + "\\]" + &x.to_string()
180+
acc + "\\]" + &x.to_string()
181181
}
182182
})
183183
}
@@ -202,9 +202,15 @@ pub fn access_of(register: &Register) -> Access {
202202
Access::ReadOnly
203203
} else if fields.iter().all(|f| f.access == Some(Access::WriteOnce)) {
204204
Access::WriteOnce
205-
} else if fields.iter().all(|f| f.access == Some(Access::ReadWriteOnce)) {
205+
} else if fields
206+
.iter()
207+
.all(|f| f.access == Some(Access::ReadWriteOnce))
208+
{
206209
Access::ReadWriteOnce
207-
} else if fields.iter().all(|f| f.access == Some(Access::WriteOnly) || f.access == Some(Access::WriteOnce)) {
210+
} else if fields
211+
.iter()
212+
.all(|f| f.access == Some(Access::WriteOnly) || f.access == Some(Access::WriteOnce))
213+
{
208214
Access::WriteOnly
209215
} else {
210216
Access::ReadWrite
@@ -217,7 +223,12 @@ pub fn access_of(register: &Register) -> Access {
217223

218224
/// Turns `n` into an unsuffixed separated hex token
219225
pub fn hex(n: u64) -> TokenStream {
220-
let (h4, h3, h2, h1) = ((n >> 48) & 0xffff, (n >> 32) & 0xffff, (n >> 16) & 0xffff, n & 0xffff);
226+
let (h4, h3, h2, h1) = (
227+
(n >> 48) & 0xffff,
228+
(n >> 32) & 0xffff,
229+
(n >> 16) & 0xffff,
230+
n & 0xffff,
231+
);
221232
syn::parse_str::<syn::Lit>(
222233
&(if h4 != 0 {
223234
format!("0x{:04x}_{:04x}_{:04x}_{:04x}", h4, h3, h2, h1)
@@ -231,8 +242,10 @@ pub fn hex(n: u64) -> TokenStream {
231242
format!("0x{:02x}", h1 & 0xff)
232243
} else {
233244
"0".to_string()
234-
})
235-
).unwrap().into_token_stream()
245+
}),
246+
)
247+
.unwrap()
248+
.into_token_stream()
236249
}
237250

238251
/// Turns `n` into an unsuffixed token
@@ -245,7 +258,10 @@ pub fn unsuffixed(n: u64) -> TokenStream {
245258
pub fn unsuffixed_or_bool(n: u64, width: u32) -> TokenStream {
246259
if width == 1 {
247260
let mut t = TokenStream::new();
248-
t.append(Ident::new(if n == 0 { "false" } else { "true" }, Span::call_site()));
261+
t.append(Ident::new(
262+
if n == 0 { "false" } else { "true" },
263+
Span::call_site(),
264+
));
249265
t
250266
} else {
251267
unsuffixed(n)
@@ -266,10 +282,11 @@ impl U32Ext for u32 {
266282
9..=16 => Ident::new("u16", span),
267283
17..=32 => Ident::new("u32", span),
268284
33..=64 => Ident::new("u64", span),
269-
_ => Err(format!(
270-
"can't convert {} bits into a Rust integral type",
271-
*self
272-
))?,
285+
_ => {
286+
return Err(
287+
format!("can't convert {} bits into a Rust integral type", *self).into(),
288+
)
289+
}
273290
})
274291
}
275292

@@ -280,10 +297,13 @@ impl U32Ext for u32 {
280297
9..=16 => 16,
281298
17..=32 => 32,
282299
33..=64 => 64,
283-
_ => Err(format!(
284-
"can't convert {} bits into a Rust integral type width",
285-
*self
286-
))?,
300+
_ => {
301+
return Err(format!(
302+
"can't convert {} bits into a Rust integral type width",
303+
*self
304+
)
305+
.into())
306+
}
287307
})
288308
}
289309
}

0 commit comments

Comments
 (0)