From 7bf774d1d162db1c07797b5d8edc8cf18354351b Mon Sep 17 00:00:00 2001 From: EdJoPaTo Date: Thu, 11 Sep 2025 19:37:17 +0200 Subject: [PATCH 1/6] build: put lint check on the function itself --- Cargo.toml | 4 +--- src/checksum.rs | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index efc3349..6d1cec5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,10 @@ [package] authors = ["Bennet Hattesen "] categories = ["encoding"] -edition = "2024" description = "Slipmux de- and encoding" +edition = "2024" homepage = "https://github.com/teufelchen1/slipmux" keywords = ["slip", "serial", "uart", "coap", "no_std"] - license = "MIT OR Apache-2.0" name = "slipmux" readme = "README.md" @@ -26,7 +25,6 @@ cargo_common_metadata = "warn" let_underscore_untyped = "warn" str_to_string = "warn" -cast_possible_truncation = "allow" option-if-let-else = "allow" single_match_else = "allow" diff --git a/src/checksum.rs b/src/checksum.rs index 0a06b00..d91598c 100644 --- a/src/checksum.rs +++ b/src/checksum.rs @@ -57,6 +57,7 @@ const FCS_LOOKUP: [u16; 256] = [ 0x3de3, 0x2c6a, 0x1ef1, 0x0f78, ]; +#[expect(clippy::cast_possible_truncation, reason = "truncation is wanted")] pub const fn fcs16_byte(fcs: u16, byte: u8) -> u16 { (fcs >> 8) ^ FCS_LOOKUP[(fcs as u8 ^ byte) as usize] } From 460b04960c8ab61c86f7b1a10074a06f609fee2c Mon Sep 17 00:00:00 2001 From: EdJoPaTo Date: Thu, 11 Sep 2025 19:41:14 +0200 Subject: [PATCH 2/6] build: prefer expect lint over allow lint --- Cargo.toml | 1 + src/decoder.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6d1cec5..7863597 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ unsafe_code = "forbid" [lints.clippy] pedantic = { level = "warn", priority = -1 } nursery = { level = "warn", priority = -1 } +allow_attributes = "warn" cargo_common_metadata = "warn" let_underscore_untyped = "warn" str_to_string = "warn" diff --git a/src/decoder.rs b/src/decoder.rs index cba5654..b1084a0 100644 --- a/src/decoder.rs +++ b/src/decoder.rs @@ -79,8 +79,8 @@ impl Decoder { /// /// Will return `Err` if either an unkown frame type is encountered OR the checksum of a /// configuration frame is bad OR a frame got aborted. - #[allow(clippy::match_same_arms)] - #[allow(clippy::too_many_lines)] + #[expect(clippy::match_same_arms)] + #[expect(clippy::too_many_lines)] pub fn decode( &mut self, byte: u8, From 95c99a4ef376beb026991780c85c6e86dbb254da Mon Sep 17 00:00:00 2001 From: EdJoPaTo Date: Thu, 11 Sep 2025 19:44:32 +0200 Subject: [PATCH 3/6] refactor: clippy::min_ident_chars --- Cargo.toml | 1 + src/encode.rs | 6 +++--- src/framehandler.rs | 20 ++++++++++---------- src/lib.rs | 4 ++-- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7863597..4ec7243 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ nursery = { level = "warn", priority = -1 } allow_attributes = "warn" cargo_common_metadata = "warn" let_underscore_untyped = "warn" +min_ident_chars = "warn" str_to_string = "warn" option-if-let-else = "allow" diff --git a/src/encode.rs b/src/encode.rs index 0296fe2..48b5463 100644 --- a/src/encode.rs +++ b/src/encode.rs @@ -46,9 +46,9 @@ pub fn encode_buffered(input: Slipmux) -> Vec { } let mut buffer: Vec = vec![]; let length = match input { - Slipmux::Diagnostic(s) => { - buffer.resize(space_requirement(s.len()), 0); - encode(FrameType::Diagnostic, s.as_bytes(), &mut buffer) + Slipmux::Diagnostic(str) => { + buffer.resize(space_requirement(str.len()), 0); + encode(FrameType::Diagnostic, str.as_bytes(), &mut buffer) } Slipmux::Configuration(conf) => { const CHECKSUM_BYTES: usize = 2; diff --git a/src/framehandler.rs b/src/framehandler.rs index 99c8b61..7b9d8a6 100644 --- a/src/framehandler.rs +++ b/src/framehandler.rs @@ -206,8 +206,8 @@ impl FrameHandler for BufferedFrameHandler { self.subhandler.packet_buffer.clear(); } } - Some(e) => { - self.results.push(Err(e)); + Some(error) => { + self.results.push(Err(error)); self.subhandler.diagnostic_buffer.clear(); self.subhandler.configuration_buffer.clear(); self.subhandler.packet_buffer.clear(); @@ -404,7 +404,7 @@ mod tests { assert_eq!(results.len(), 1); let frame = results.pop().unwrap(); match frame.unwrap() { - Slipmux::Diagnostic(s) => assert_eq!(s, "Hello World!"), + Slipmux::Diagnostic(str) => assert_eq!(str, "Hello World!"), _ => unreachable!(), } } @@ -440,7 +440,7 @@ mod tests { assert_eq!(results.len(), 1); let frame = results.pop().unwrap(); match frame.unwrap() { - Slipmux::Configuration(s) => assert_eq!(s, b"Hello World!"), + Slipmux::Configuration(config) => assert_eq!(config, b"Hello World!"), _ => unreachable!(), } } @@ -506,7 +506,7 @@ mod tests { assert_eq!(results.len(), 1); let frame = results.pop().unwrap(); match frame.unwrap() { - Slipmux::Diagnostic(s) => assert_eq!(s, "Hello World!"), + Slipmux::Diagnostic(str) => assert_eq!(str, "Hello World!"), _ => unreachable!(), } } @@ -544,7 +544,7 @@ mod tests { assert_eq!(results.len(), 1); let frame = results.pop().unwrap(); match frame.unwrap() { - Slipmux::Diagnostic(s) => assert_eq!(s, "Hello World!"), + Slipmux::Diagnostic(str) => assert_eq!(str, "Hello World!"), _ => unreachable!(), } } @@ -607,8 +607,8 @@ mod tests { for results in results_arr { for slipframe in results { match slipframe { - Ok(Slipmux::Diagnostic(s)) => { - assert_eq!(s, "Hello World!"); + Ok(Slipmux::Diagnostic(str)) => { + assert_eq!(str, "Hello World!"); } Ok(Slipmux::Configuration(_conf)) => { // Do stuff @@ -695,13 +695,13 @@ mod tests { assert_eq!(results.len(), 2); let frame = results.pop().unwrap(); match frame.unwrap() { - Slipmux::Diagnostic(s) => assert_eq!(s, "Hello World!"), + Slipmux::Diagnostic(str) => assert_eq!(str, "Hello World!"), _ => unreachable!(), } let frame = results.pop().unwrap(); match frame { Ok(_) => unreachable!(), - Err(e) => assert!(matches!(e, Error::Abort)), + Err(error) => assert!(matches!(error, Error::Abort)), } } } diff --git a/src/lib.rs b/src/lib.rs index b1c6444..be695aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -260,8 +260,8 @@ mod tests { assert_eq!(3, frames.len()); for slipframe in frames { match slipframe { - Ok(Slipmux::Diagnostic(s)) => { - assert_eq!(s, "Hello World!"); + Ok(Slipmux::Diagnostic(str)) => { + assert_eq!(str, "Hello World!"); } Ok(Slipmux::Configuration(conf)) => { assert_eq!(conf, Packet::new().to_bytes().unwrap()); From 50ded6a504605cf21c7cc9ca4006528cdd2549f8 Mon Sep 17 00:00:00 2001 From: EdJoPaTo Date: Fri, 12 Dec 2025 00:36:30 +0100 Subject: [PATCH 4/6] fixup! refactor: clippy::min_ident_chars --- src/encode.rs | 6 +++--- src/framehandler.rs | 12 ++++++------ src/lib.rs | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/encode.rs b/src/encode.rs index 48b5463..ba1a819 100644 --- a/src/encode.rs +++ b/src/encode.rs @@ -46,9 +46,9 @@ pub fn encode_buffered(input: Slipmux) -> Vec { } let mut buffer: Vec = vec![]; let length = match input { - Slipmux::Diagnostic(str) => { - buffer.resize(space_requirement(str.len()), 0); - encode(FrameType::Diagnostic, str.as_bytes(), &mut buffer) + Slipmux::Diagnostic(message) => { + buffer.resize(space_requirement(message.len()), 0); + encode(FrameType::Diagnostic, message.as_bytes(), &mut buffer) } Slipmux::Configuration(conf) => { const CHECKSUM_BYTES: usize = 2; diff --git a/src/framehandler.rs b/src/framehandler.rs index 7b9d8a6..82ec4bd 100644 --- a/src/framehandler.rs +++ b/src/framehandler.rs @@ -404,7 +404,7 @@ mod tests { assert_eq!(results.len(), 1); let frame = results.pop().unwrap(); match frame.unwrap() { - Slipmux::Diagnostic(str) => assert_eq!(str, "Hello World!"), + Slipmux::Diagnostic(message) => assert_eq!(message, "Hello World!"), _ => unreachable!(), } } @@ -506,7 +506,7 @@ mod tests { assert_eq!(results.len(), 1); let frame = results.pop().unwrap(); match frame.unwrap() { - Slipmux::Diagnostic(str) => assert_eq!(str, "Hello World!"), + Slipmux::Diagnostic(message) => assert_eq!(message, "Hello World!"), _ => unreachable!(), } } @@ -544,7 +544,7 @@ mod tests { assert_eq!(results.len(), 1); let frame = results.pop().unwrap(); match frame.unwrap() { - Slipmux::Diagnostic(str) => assert_eq!(str, "Hello World!"), + Slipmux::Diagnostic(message) => assert_eq!(message, "Hello World!"), _ => unreachable!(), } } @@ -607,8 +607,8 @@ mod tests { for results in results_arr { for slipframe in results { match slipframe { - Ok(Slipmux::Diagnostic(str)) => { - assert_eq!(str, "Hello World!"); + Ok(Slipmux::Diagnostic(message)) => { + assert_eq!(message, "Hello World!"); } Ok(Slipmux::Configuration(_conf)) => { // Do stuff @@ -695,7 +695,7 @@ mod tests { assert_eq!(results.len(), 2); let frame = results.pop().unwrap(); match frame.unwrap() { - Slipmux::Diagnostic(str) => assert_eq!(str, "Hello World!"), + Slipmux::Diagnostic(message) => assert_eq!(message, "Hello World!"), _ => unreachable!(), } let frame = results.pop().unwrap(); diff --git a/src/lib.rs b/src/lib.rs index be695aa..172614e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -260,8 +260,8 @@ mod tests { assert_eq!(3, frames.len()); for slipframe in frames { match slipframe { - Ok(Slipmux::Diagnostic(str)) => { - assert_eq!(str, "Hello World!"); + Ok(Slipmux::Diagnostic(message)) => { + assert_eq!(message, "Hello World!"); } Ok(Slipmux::Configuration(conf)) => { assert_eq!(conf, Packet::new().to_bytes().unwrap()); From ae290e5943d47b2be167a933423673e0cbbd06e7 Mon Sep 17 00:00:00 2001 From: EdJoPaTo Date: Fri, 12 Dec 2025 13:14:08 +0100 Subject: [PATCH 5/6] fixup! build: prefer expect lint over allow lint --- src/encode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/encode.rs b/src/encode.rs index 7300d6c..bfdb50f 100644 --- a/src/encode.rs +++ b/src/encode.rs @@ -185,7 +185,7 @@ impl<'input> ChunkedEncoder<'input> { break; } } else { - #[allow( + #[expect( clippy::redundant_else, clippy::if_not_else, reason = "reflects logical decision tree" From 46353e83bb83d5333b6bc988321a7266000e94f5 Mon Sep 17 00:00:00 2001 From: EdJoPaTo Date: Fri, 12 Dec 2025 13:14:29 +0100 Subject: [PATCH 6/6] fixup! build: put lint check on the function itself --- src/encode.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/encode.rs b/src/encode.rs index bfdb50f..37d8f34 100644 --- a/src/encode.rs +++ b/src/encode.rs @@ -135,6 +135,7 @@ impl<'input> ChunkedEncoder<'input> { /// Advance whichever slice was just selected in [`Self::slice_to_encode()`] by some amount of /// bytes. + #[expect(clippy::cast_possible_truncation)] // TODO: should this be fixed? fn advance_slice(&mut self, amount: usize) { if !self.header.is_empty() { self.header = &self.header[amount..];