From 5802b07e2ed0b6a14c8aceae84e8f6cd35498bd8 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Tue, 24 Oct 2023 19:21:42 +0100 Subject: [PATCH] use double underscores to indicate temporary variables --- build/binder.rs | 1 + build/parser.rs | 24 ++++++++++++------------ src/lib.rs | 14 +++++++------- src/utils.rs | 2 +- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/build/binder.rs b/build/binder.rs index be68f7a9c3..099ef24e9b 100644 --- a/build/binder.rs +++ b/build/binder.rs @@ -11,6 +11,7 @@ pub fn generate(modules: Vec, out: &mut W) { #[allow(clippy::field_reassign_with_default)] #[allow(non_snake_case)] #[allow(clippy::unnecessary_cast)] + #[allow(clippy::bad_bit_mask)] #[cfg(feature = #module)] pub mod #module_ident; } diff --git a/build/parser.rs b/build/parser.rs index 2436502314..20a883a2eb 100644 --- a/build/parser.rs +++ b/build/parser.rs @@ -500,13 +500,13 @@ impl MavMessage { fn emit_serialize_vars(&self) -> TokenStream { let ser_vars = self.fields.iter().map(|f| f.rust_writer()); quote! { - let mut _tmp = BytesMut::new(bytes); + let mut __tmp = BytesMut::new(bytes); #(#ser_vars)* if matches!(version, MavlinkVersion::V2) { - let len = _tmp.len(); - crate::remove_trailing_zeroes(&mut bytes[..len]) + let len = __tmp.len(); + crate::remove_trailing_zeroes(&bytes[..len]) } else { - _tmp.len() + __tmp.len() } } } @@ -525,21 +525,21 @@ impl MavMessage { } } else { quote! { - let avail_len = _input.len(); + let avail_len = __input.len(); let mut payload_buf = [0; Self::ENCODED_LEN]; let mut buf = if avail_len < Self::ENCODED_LEN { //copy available bytes into an oversized buffer filled with zeros - payload_buf[0..avail_len].copy_from_slice(_input); + payload_buf[0..avail_len].copy_from_slice(__input); Bytes::new(&payload_buf) } else { // fast zero copy - Bytes::new(_input) + Bytes::new(__input) }; - let mut _struct = Self::default(); + let mut __struct = Self::default(); #(#deser_vars)* - Ok(_struct) + Ok(__struct) } } } @@ -604,7 +604,7 @@ impl MavMessage { const EXTRA_CRC: u8 = #extra_crc; const ENCODED_LEN: usize = #msg_encoded_len; - fn deser(_version: MavlinkVersion, _input: &[u8]) -> Result { + fn deser(_version: MavlinkVersion, __input: &[u8]) -> Result { #deser_vars } @@ -692,7 +692,7 @@ impl MavField { } let ts = TokenStream::from_str(&name).unwrap(); let name = quote!(#ts); - let buf = format_ident!("_tmp"); + let buf = format_ident!("__tmp"); self.mavtype.rust_writer(&name, buf) } @@ -700,7 +700,7 @@ impl MavField { fn rust_reader(&self) -> TokenStream { let _name = TokenStream::from_str(&self.name).unwrap(); - let name = quote!(_struct.#_name); + let name = quote!(__struct.#_name); let buf = format_ident!("buf"); if let Some(enum_name) = &self.enumtype { // TODO: handle enum arrays properly, rather than just generating diff --git a/src/lib.rs b/src/lib.rs index 248ea9c1e4..8acb6dce89 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -191,7 +191,7 @@ impl MavFrame { let msg_id = match version { MavlinkVersion::V2 => buf.get_u24_le(), - MavlinkVersion::V1 => buf.get_u8() as u32, + MavlinkVersion::V1 => buf.get_u8().into(), }; match M::parse(version, msg_id, buf.remaining_bytes()) { @@ -498,10 +498,10 @@ impl MAVLinkV2MessageRaw { let payload_length: usize = self.payload_length().into(); // Signature to ensure the link is tamper-proof. - let signature_size = if (self.incompatibility_flags() & MAVLINK_IFLAG_SIGNED) != 0 { - Self::SIGNATURE_SIZE - } else { + let signature_size = if (self.incompatibility_flags() & MAVLINK_IFLAG_SIGNED) == 0 { 0 + } else { + Self::SIGNATURE_SIZE }; &mut self.0 @@ -521,10 +521,10 @@ impl MAVLinkV2MessageRaw { pub fn raw_bytes(&self) -> &[u8] { let payload_length = self.payload_length() as usize; - let signature_size = if (self.incompatibility_flags() & MAVLINK_IFLAG_SIGNED) != 0 { - Self::SIGNATURE_SIZE - } else { + let signature_size = if (self.incompatibility_flags() & MAVLINK_IFLAG_SIGNED) == 0 { 0 + } else { + Self::SIGNATURE_SIZE }; &self.0[..(1 + Self::HEADER_SIZE + payload_length + signature_size + 2)] diff --git a/src/utils.rs b/src/utils.rs index 58adfc6729..486c2ea0bb 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -4,7 +4,7 @@ /// /// There must always be at least one remaining byte even if it is a /// zero byte. -pub(crate) fn remove_trailing_zeroes(data: &mut [u8]) -> usize { +pub(crate) fn remove_trailing_zeroes(data: &[u8]) -> usize { let mut len = data.len(); for b in data[1..].iter().rev() {