clippy: add if_not_else clippy lint (#10524)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Thomas Coratger
2024-08-26 03:58:06 -07:00
committed by GitHub
parent 1b1e835fb1
commit 709e7b73ce
21 changed files with 133 additions and 134 deletions

View File

@ -57,10 +57,10 @@ impl<'a> EnumHandler<'a> {
FieldTypes::EnumUnnamedField((next_ftype, use_alt_impl)) => {
// This variant is of the type `EnumVariant(UnnamedField)`
let field_type = format_ident!("{next_ftype}");
let from_compact_ident = if !use_alt_impl {
format_ident!("from_compact")
} else {
let from_compact_ident = if *use_alt_impl {
format_ident!("specialized_from_compact")
} else {
format_ident!("from_compact")
};
// Unnamed type
@ -98,10 +98,10 @@ impl<'a> EnumHandler<'a> {
if let Some(next_field) = self.fields_iterator.peek() {
match next_field {
FieldTypes::EnumUnnamedField((_, use_alt_impl)) => {
let to_compact_ident = if !use_alt_impl {
format_ident!("to_compact")
} else {
let to_compact_ident = if *use_alt_impl {
format_ident!("specialized_to_compact")
} else {
format_ident!("to_compact")
};
// Unnamed type

View File

@ -155,15 +155,15 @@ fn build_struct_field_flags(
/// Returns the total number of bytes used by the flags struct and how many unused bits.
fn pad_flag_struct(total_bits: u8, field_flags: &mut Vec<TokenStream2>) -> (u8, u8) {
let remaining = 8 - total_bits % 8;
if remaining != 8 {
if remaining == 8 {
(total_bits / 8, 0)
} else {
let bsize = format_ident!("B{remaining}");
field_flags.push(quote! {
#[skip]
unused: #bsize ,
});
((total_bits + remaining) / 8, remaining)
} else {
(total_bits / 8, 0)
}
}

View File

@ -46,10 +46,10 @@ impl<'a> StructHandler<'a> {
fn to(&mut self, field_descriptor: &StructFieldDescriptor) {
let (name, ftype, is_compact, use_alt_impl) = field_descriptor;
let to_compact_ident = if !use_alt_impl {
format_ident!("to_compact")
} else {
let to_compact_ident = if *use_alt_impl {
format_ident!("specialized_to_compact")
} else {
format_ident!("to_compact")
};
// Should only happen on wrapper structs like `Struct(pub Field)`
@ -108,10 +108,10 @@ impl<'a> StructHandler<'a> {
(format_ident!("{name}"), format_ident!("{name}_len"))
};
let from_compact_ident = if !use_alt_impl {
format_ident!("from_compact")
} else {
let from_compact_ident = if *use_alt_impl {
format_ident!("specialized_from_compact")
} else {
format_ident!("from_compact")
};
// ! Be careful before changing the following assert ! Especially if the type does not