1
0
Fork 0
mirror of https://codeberg.org/icewind/bitbuffer.git synced 2026-06-03 08:34:07 +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

@ -270,5 +270,5 @@ trait DeriveParams: Sized {
}
fn err<R, Msg: Display>(msg: Msg, span: Span) -> Result<R> {
return Err(Error::new(span, msg));
Err(Error::new(span, msg))
}

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)
};

View file

@ -26,7 +26,7 @@ pub fn derive_encode_enum(params: &EnumParam, unchecked: bool) -> TokenStream {
Ok(#ident::#variant_name)
},
VariantBody::Fields(fields) => {
read_struct_or_enum(&variant_path, fields, span.clone(), unchecked)
read_struct_or_enum(&variant_path, fields, span, unchecked)
}
};

View file

@ -37,7 +37,7 @@ impl SizeHint for VariantParam {
fn size_hint(&self) -> TokenStream {
match &self.body {
VariantBody::Unit => quote!(Some(0)),
VariantBody::Fields(fields) => product_size_hint(&fields, self.span),
VariantBody::Fields(fields) => product_size_hint(fields, self.span),
}
}
}

View file

@ -45,7 +45,7 @@ pub fn derive_encode_enum(params: &EnumParam) -> TokenStream {
#path => {},
}
}
VariantBody::Fields(fields) => write_enum_variant(path, &fields, span),
VariantBody::Fields(fields) => write_enum_variant(path, fields, span),
}
});