1
0
Fork 0
mirror of https://codeberg.org/icewind/bitbuffer.git synced 2026-06-03 16:44:06 +02:00

clippy fixes

This commit is contained in:
Robin Appelman 2023-11-11 22:03:10 +01:00
commit 834c3f2f95
9 changed files with 57 additions and 68 deletions

View file

@ -41,7 +41,7 @@ impl EnumParam {
.discriminant_bits
.ok_or_else(|| {
Error::new(
span.clone(),
span,
"'discriminant_bits' attribute is required when deriving `BinRead` for enums",
)
})?

View file

@ -68,7 +68,7 @@ impl ToTokens for Size {
fn to_tokens(&self, tokens: &mut TokenStream) {
match self {
Size::Expression(expr, span) => {
let span = span.clone();
let span = *span;
tokens.append_all(quote_spanned! {span => {
#[allow(clippy::unnecessary_cast)]
let __size = (#expr) as usize;
@ -77,7 +77,7 @@ impl ToTokens for Size {
});
}
Size::Bits(bits, span) => {
let span = span.clone();
let span = *span;
tokens.append_all(quote_spanned! {span => {
__stream.read_int::<usize>(#bits)?
}
@ -236,9 +236,7 @@ impl InputParams {
}
}
pub fn generics_for_impl<'a>(
&'a self,
) -> (ImplGenerics<'a>, TypeGenerics<'a>, Option<&'a WhereClause>) {
pub fn generics_for_impl(&self) -> (ImplGenerics, TypeGenerics, Option<&WhereClause>) {
// we need these separate generics to only add out Endianness param to the 'impl'
let (_, ty_generics, where_clause) = self.generics.split_for_impl();
let (impl_generics, _, _) = self.generics_with_endianness.split_for_impl();
@ -247,14 +245,11 @@ impl InputParams {
}
pub fn endianness(&self) -> Ident {
Ident::new(
self.endianness.as_deref().unwrap_or_else(|| "_E"),
self.span,
)
Ident::new(self.endianness.as_deref().unwrap_or("_E"), self.span)
}
}
const BARE_ATTRS: &'static [&'static str] = &[
const BARE_ATTRS: &[&str] = &[
"size",
"size_bits",
"discriminant_bits",
@ -279,8 +274,8 @@ fn parse_attrs<T: Parse + Default + Merge>(attrs: &[Attribute]) -> Result<T> {
});
let wrapped = Attribute {
pound_token: attr.pound_token,
style: attr.style.clone(),
bracket_token: attr.bracket_token.clone(),
style: attr.style,
bracket_token: attr.bracket_token,
meta: wrapped_meta,
};
wrapped.parse_args()

View file

@ -114,17 +114,11 @@ impl VariantParam {
.collect::<Result<Vec<FieldParam>>>()?;
// align and size attributes on the variant go to the first field
match (fields.first_mut(), align) {
(Some(field), Alignment::Auto) => {
field.align = align;
}
_ => {}
if let (Some(field), Alignment::Auto) = (fields.first_mut(), align) {
field.align = align;
}
match (fields.first_mut(), size) {
(Some(field), Some(size)) => {
field.size = Some(size);
}
_ => {}
if let (Some(field), Some(size)) = (fields.first_mut(), size) {
field.size = Some(size);
}
VariantBody::Fields(fields)
};