Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6470489a authored by Martin Geisler's avatar Martin Geisler
Browse files

pdl: Skip unnecessary conforms method computations

This avoids a lint warning since the “>= 0” comparison is known to
always be true.

Test: atest pdl_tests
Change-Id: I480c9a8e7ae499e2038eb5a9dd032521c14fe957
parent 39f3a4b2
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -170,11 +170,16 @@ fn generate_packet_decl(
        })
    });

    let conforms = if packet_size_bytes.index == 0 {
        quote! { true }
    } else {
        quote! { bytes.len() >= #packet_size_bytes }
    };

    code.push_str(&quote_block! {
        impl #data_name {
            fn conforms(bytes: &[u8]) -> bool {
                // TODO(mgeisler): skip when packet_size_bytes == 0.
                bytes.len() >= #packet_size_bytes
                #conforms
            }

            fn parse(bytes: &[u8]) -> Result<Self> {
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ pub struct FooBuilder {}

impl FooData {
    fn conforms(bytes: &[u8]) -> bool {
        bytes.len() >= 0
        true
    }
    fn parse(bytes: &[u8]) -> Result<Self> {
        Ok(Self {})