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

Commit 97436526 authored by Martin Geisler's avatar Martin Geisler Committed by Cherrypicker Worker
Browse files

pdl: Use explicit type when converting enum value

This fixes a compilation error when I compile the generated code
locally while having the Serde feature enabled:

    error[E0283]: type annotations needed
        --> tests/le/mod.rs:1488:45
         |
    1488 |         if (chunk & 0x7f) as u8 != Enum7::A.into() {
         |                                 --          ^^^^
         |                                 |
         |                                 type must be known at this point
         |
         = note: multiple `impl`s satisfying `u8: PartialEq<_>` found in the following crates: `core`, `serde_json`:
                 - impl PartialEq for u8;
                 - impl PartialEq<Value> for u8;

Tag: #feature
Bug: 228306436
Test: atest pdl_tests pdl_rust_generator_tests_{le,be} pdl_generated_files_compile
(cherry picked from https://android-review.googlesource.com/q/commit:0edd07378446075a2c17ab355393747560fd3813)
Merged-In: I01e0ed4bcb3117005453d92299e586ba1913bc3d
Change-Id: I01e0ed4bcb3117005453d92299e586ba1913bc3d
parent db57f167
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ impl<'a> FieldParser<'a> {
                    let enum_id = format_ident!("{enum_id}");
                    let tag_id = format_ident!("{}", tag_id.to_upper_camel_case());
                    quote! {
                        if #v != #enum_id::#tag_id.into()  {
                        if #v != #value_type::from(#enum_id::#tag_id)  {
                            return Err(Error::InvalidFixedValue {
                                expected: #value_type::from(#enum_id::#tag_id) as u64,
                                actual: #v as u64,
+1 −1
Original line number Diff line number Diff line
@@ -150,7 +150,7 @@ impl FooData {
            });
        }
        let chunk = bytes.get_mut().get_u64();
        if (chunk & 0x7f) as u8 != Enum7::A.into() {
        if (chunk & 0x7f) as u8 != u8::from(Enum7::A) {
            return Err(Error::InvalidFixedValue {
                expected: u8::from(Enum7::A) as u64,
                actual: (chunk & 0x7f) as u8 as u64,
+1 −1
Original line number Diff line number Diff line
@@ -150,7 +150,7 @@ impl FooData {
            });
        }
        let chunk = bytes.get_mut().get_u64_le();
        if (chunk & 0x7f) as u8 != Enum7::A.into() {
        if (chunk & 0x7f) as u8 != u8::from(Enum7::A) {
            return Err(Error::InvalidFixedValue {
                expected: u8::from(Enum7::A) as u64,
                actual: (chunk & 0x7f) as u8 as u64,