From dfd7abe185a7200946bd8429e097ccbd73ea6a4a Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Tue, 29 Nov 2022 07:13:58 -0600 Subject: [PATCH] rust/clippy: fix lint: type_complexity Convert a DNS sub-parser to use a return type rather than a large tuple. For mqtt, allow the lint for now, but remove the global allow. --- rust/src/dns/parser.rs | 36 +++++++++++++++++++++++------------- rust/src/lib.rs | 1 - rust/src/mqtt/parser.rs | 1 + 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/rust/src/dns/parser.rs b/rust/src/dns/parser.rs index 94b1762db2..197d761d65 100644 --- a/rust/src/dns/parser.rs +++ b/rust/src/dns/parser.rs @@ -120,26 +120,36 @@ fn dns_parse_answer<'a>( let mut answers = Vec::new(); let mut input = slice; + struct Answer<'a> { + name: Vec, + rrtype: u16, + rrclass: u16, + ttl: u32, + data: &'a [u8], + } + fn subparser<'a>( i: &'a [u8], message: &'a [u8], - ) -> IResult<&'a [u8], (Vec, u16, u16, u32, &'a [u8])> { + ) -> IResult<&'a [u8], Answer<'a>> { let (i, name) = dns_parse_name(i, message)?; let (i, rrtype) = be_u16(i)?; let (i, rrclass) = be_u16(i)?; let (i, ttl) = be_u32(i)?; let (i, data) = length_data(be_u16)(i)?; - Ok((i, (name, rrtype, rrclass, ttl, data))) + let answer = Answer { + name, + rrtype, + rrclass, + ttl, + data, + }; + Ok((i, answer)) } for _ in 0..count { match subparser(input, message) { Ok((rem, val)) => { - let name = val.0; - let rrtype = val.1; - let rrclass = val.2; - let ttl = val.3; - let data = val.4; - let n = match rrtype { + let n = match val.rrtype { DNS_RECORD_TYPE_TXT => { // For TXT records we need to run the parser // multiple times. Set n high, to the maximum @@ -155,15 +165,15 @@ fn dns_parse_answer<'a>( } }; let result: IResult<&'a [u8], Vec> = - many_m_n(1, n, complete(|b| dns_parse_rdata(b, message, rrtype)))(data); + many_m_n(1, n, complete(|b| dns_parse_rdata(b, message, val.rrtype)))(val.data); match result { Ok((_, rdatas)) => { for rdata in rdatas { answers.push(DNSAnswerEntry { - name: name.clone(), - rrtype, - rrclass, - ttl, + name: val.name.clone(), + rrtype: val.rrtype, + rrclass: val.rrclass, + ttl: val.ttl, data: rdata, }); } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index d7c323cda2..12e4a796ed 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -29,7 +29,6 @@ // To be fixed, but remove the noise for now. #![allow(clippy::match_like_matches_macro)] #![allow(clippy::module_inception)] -#![allow(clippy::type_complexity)] #[macro_use] extern crate bitflags; diff --git a/rust/src/mqtt/parser.rs b/rust/src/mqtt/parser.rs index 26984be118..78ef4ba01e 100644 --- a/rust/src/mqtt/parser.rs +++ b/rust/src/mqtt/parser.rs @@ -174,6 +174,7 @@ pub fn parse_fixed_header(i: &[u8]) -> IResult<&[u8], FixedHeader> { } #[inline] +#[allow(clippy::type_complexity)] fn parse_connect_variable_flags(i: &[u8]) -> IResult<&[u8], (u8, u8, u8, u8, u8, u8, u8)> { bits(tuple(( take_bits(1u8),