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

Commit 482fad05 authored by Martin Geisler's avatar Martin Geisler Committed by David Duarte
Browse files

pdl: Fix Rust 1.59.0 compilation errors

This is for integration with UWB.

Tag: #feature
Bug: 228306436
Test: m pdl
Change-Id: Idfbf269d253f93786a63ebdb810c6200da0d2c45
Merged-In: Id7d13f0534bbb837899e01bd8ff04ab48617597f
parent 21bcadc8
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -11,7 +11,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.
@@ -21,10 +21,15 @@ pub mod ast {
        Dynamic,
        /// The size cannot be determined statically or at runtime.
        /// The packet assumes the largest possible size.
        #[default]
        Unknown,
    }

    impl Default for Size {
        fn default() -> Size {
            Size::Unknown
        }
    }

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

+4 −3
Original line number Diff line number Diff line
@@ -319,15 +319,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)) => {
@@ -366,7 +367,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)) => {
+8 −2
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ pub mod ast {
    use serde::Serialize;

    // Field and declaration size information.
    #[derive(Default, Debug, Clone)]
    #[derive(Debug, Clone)]
    #[allow(unused)]
    pub enum Size {
        // Constant size in bits.
@@ -17,10 +17,16 @@ 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.
    impl Default for Size {
        fn default() -> Size {
            Size::Unknown
        }
    }

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

+5 −5
Original line number Diff line number Diff line
@@ -50,12 +50,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();
@@ -71,7 +71,7 @@ fn main() -> std::process::ExitCode {
                                .lock(),
                        )
                        .expect("Could not print analyzer diagnostics");
                    return std::process::ExitCode::FAILURE;
                    return Err(String::from("Analysis failed"));
                }
            };

@@ -93,14 +93,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
@@ -110,7 +110,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