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

Commit 3bf1a9e0 authored by Martin Geisler's avatar Martin Geisler Committed by Henri Chataing
Browse files

pdl: Update sources to match tm-mainline-prod

- Fix Rust 1.59.0 compilation errors
- Fix clippy warnings

Tag: #feature
Bug: 228306436
Test: cargo test
Change-Id: Ie56d765863551e5f853ff02a473cfe469dd3efd7
parent 68768066
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ pub mod ast {
    use serde::Serialize;

    /// Field and declaration size information.
    #[derive(Default, Debug, Clone, Copy)]
    #[derive(Debug, Clone, Copy)]
    #[allow(unused)]
    pub enum Size {
        /// Constant size in bits.
@@ -22,10 +22,17 @@ pub mod ast {
        Dynamic,
        /// The size cannot be determined statically or at runtime.
        /// The packet assumes the largest possible size.
        #[default]
        Unknown,
    }

    // TODO: use derive(Default) when UWB is using Rust 1.62.0.
    #[allow(clippy::derivable_impls)]
    impl Default for Size {
        fn default() -> Size {
            Size::Unknown
        }
    }

    #[derive(Debug, Serialize, Default, Clone, PartialEq)]
    pub struct Annotation;

+1 −1
Original line number Diff line number Diff line
@@ -426,7 +426,7 @@ fn generate_packet_decl(
        let named_fields = {
            let mut names =
                parent_packet_scope.iter_fields().filter_map(ast::Field::id).collect::<Vec<_>>();
            names.sort();
            names.sort_unstable();
            names
        };

+4 −3
Original line number Diff line number Diff line
@@ -318,15 +318,16 @@ impl<'a> FieldParser<'a> {
                    }
                });
            }
            (ElementWidth::Unknown, ArrayShape::Static(_)) => {
            (ElementWidth::Unknown, ArrayShape::Static(count)) => {
                // The element width is not known, but the array
                // element count is known statically. Parse elements
                // item by item as an array.
                let count = syn::Index::from(*count);
                self.code.push(quote! {
                    // TODO(mgeisler): use
                    // https://doc.rust-lang.org/std/array/fn.try_from_fn.html
                    // when stabilized.
                    let #id = std::array::from_fn(|_| #parse_element.unwrap());
                    let #id = [0; #count].map(|_| #parse_element.unwrap());
                });
            }
            (ElementWidth::Unknown, ArrayShape::CountField(count_field)) => {
@@ -365,7 +366,7 @@ impl<'a> FieldParser<'a> {
                    // TODO(mgeisler): use
                    // https://doc.rust-lang.org/std/array/fn.try_from_fn.html
                    // when stabilized.
                    let #id = std::array::from_fn(|_| #parse_element.unwrap());
                    let #id = [0; #count].map(|_| #parse_element.unwrap());
                });
            }
            (ElementWidth::Static(_), ArrayShape::CountField(count_field)) => {
+5 −5
Original line number Diff line number Diff line
@@ -51,12 +51,12 @@ struct Opt {
    input_file: String,
}

fn main() -> std::process::ExitCode {
fn main() -> Result<(), String> {
    let opt = Opt::parse();

    if opt.version {
        println!("Packet Description Language parser version 1.0");
        return std::process::ExitCode::SUCCESS;
        return Ok(());
    }

    let mut sources = ast::SourceDatabase::new();
@@ -72,7 +72,7 @@ fn main() -> std::process::ExitCode {
                                .lock(),
                        )
                        .expect("Could not print analyzer diagnostics");
                    return std::process::ExitCode::FAILURE;
                    return Err(String::from("Analysis failed"));
                }
            };

@@ -94,14 +94,14 @@ fn main() -> std::process::ExitCode {
                    )
                }
            }
            std::process::ExitCode::SUCCESS
            Ok(())
        }

        Err(err) => {
            let writer = termcolor::StandardStream::stderr(termcolor::ColorChoice::Always);
            let config = term::Config::default();
            term::emit(&mut writer.lock(), &config, &sources, &err).expect("Could not print error");
            std::process::ExitCode::FAILURE
            Err(String::from("Error while parsing input"))
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ impl BarData {
                got: bytes.get().remaining(),
            });
        }
        let x = std::array::from_fn(|_| {
        let x = [0; 5].map(|_| {
            Foo::from_u32(bytes.get_mut().get_uint(3) as u32)
                .ok_or_else(|| Error::InvalidEnumValueError {
                    obj: "Bar".to_string(),
Loading