Skip to content

@rust-attr(derive(serde::Serialize, serde::Deserialize)) not working when adding a list property in a struct #10996

@uAtomicBoolean

Description

@uAtomicBoolean

Bug Description

An error will be raised during compilation when adding @rust-attr(derive(serde::Serialize, serde::Deserialize)) on a struct that has a list property (with the serde feature enabled).
Using @rust-attr(cfg_attr(feature="serde", derive(Serialize, Deserialize))) will remove the error when building the slint files but display warnings during compilation.
However, the error will still be raised if we try to serialize/deserialize the struct in the rust code.

The error:

   Compiling slint-rust-template v0.1.0 (E:\Programmation\slint-rust-template)
error[E0277]: the trait bound `ModelRc<slint::SharedString>: serde::Serialize` is not satisfied
    --> E:\Programmation\slint-rust-template\target\debug\build\slint-rust-template-ec625021f24eae21\out\app-window.rs:6:17
     |
   6 |      # [derive (serde :: Serialize , serde :: Deserialize)] # [derive (Default , PartialEq , Debug , Clone)] pub struct r#DocPage {
     |                 ^^^^^^^^^^^^^^^^^^ the trait `Serialize` is not implemented for `ModelRc<slint::SharedString>`
   7 |          pub r#content : sp :: ModelRc < sp :: SharedString > , pub r#description : sp :: SharedString , pub r#title : sp :: SharedString }
     |          --- required by a bound introduced by this call
     |
     = note: for local types consider adding `#[derive(serde::Serialize)]` to your `ModelRc<slint::SharedString>` type
     = note: for types from other crates check whether the crate offers a `serde` feature flag
     = help: the following other types implement trait `Serialize`:
               &'a T
               &'a mut T
               ()
               (T,)
               (T0, T1)
               (T0, T1, T2)
               (T0, T1, T2, T3)
               (T0, T1, T2, T3, T4)
             and 170 others
note: required by a bound in `slint_generatedAppWindow::_::_serde::ser::SerializeStruct::serialize_field`
    --> C:\Users\atomicboolean\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\serde_core-1.0.228\src\ser\mod.rs:1917:21
     |
1915 |     fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error>
     |        --------------- required by a bound in this associated function
1916 |     where
1917 |         T: ?Sized + Serialize;
     |                     ^^^^^^^^^ required by this bound in `SerializeStruct::serialize_field`
     = note: this error originates in the derive macro `serde::Serialize` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `ModelRc<slint::SharedString>: serde::Deserialize<'de>` is not satisfied
    --> E:\Programmation\slint-rust-template\target\debug\build\slint-rust-template-ec625021f24eae21\out\app-window.rs:7:26
     |
   7 |          pub r#content : sp :: ModelRc < sp :: SharedString > , pub r#description : sp :: SharedString , pub r#title : sp :: SharedString }
     |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `ModelRc<slint::SharedString>`
     |
     = note: for local types consider adding `#[derive(serde::Deserialize)]` to your `ModelRc<slint::SharedString>` type
     = note: for types from other crates check whether the crate offers a `serde` feature flag
     = help: the following other types implement trait `Deserialize<'de>`:
               &'a [u8]
               &'a std::path::Path
               &'a str
               ()
               (T,)
               (T0, T1)
               (T0, T1, T2)
               (T0, T1, T2, T3)
             and 183 others
note: required by a bound in `next_element`
    --> C:\Users\atomicboolean\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\serde_core-1.0.228\src\de\mod.rs:1771:12
     |
1769 |     fn next_element<T>(&mut self) -> Result<Option<T>, Self::Error>
     |        ------------ required by a bound in this associated function
1770 |     where
1771 |         T: Deserialize<'de>,
     |            ^^^^^^^^^^^^^^^^ required by this bound in `SeqAccess::next_element`

error[E0277]: the trait bound `ModelRc<slint::SharedString>: serde::Deserialize<'de>` is not satisfied
    --> E:\Programmation\slint-rust-template\target\debug\build\slint-rust-template-ec625021f24eae21\out\app-window.rs:7:26
     |
   7 |          pub r#content : sp :: ModelRc < sp :: SharedString > , pub r#description : sp :: SharedString , pub r#title : sp :: SharedString }
     |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `ModelRc<slint::SharedString>`
     |
     = note: for local types consider adding `#[derive(serde::Deserialize)]` to your `ModelRc<slint::SharedString>` type
     = note: for types from other crates check whether the crate offers a `serde` feature flag
     = help: the following other types implement trait `Deserialize<'de>`:
               &'a [u8]
               &'a std::path::Path
               &'a str
               ()
               (T,)
               (T0, T1)
               (T0, T1, T2)
               (T0, T1, T2, T3)
             and 183 others
note: required by a bound in `next_value`
    --> C:\Users\atomicboolean\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\serde_core-1.0.228\src\de\mod.rs:1916:12
     |
1914 |     fn next_value<V>(&mut self) -> Result<V, Self::Error>
     |        ---------- required by a bound in this associated function
1915 |     where
1916 |         V: Deserialize<'de>,
     |            ^^^^^^^^^^^^^^^^ required by this bound in `MapAccess::next_value`

error[E0277]: the trait bound `ModelRc<slint::SharedString>: serde::Deserialize<'de>` is not satisfied
  --> E:\Programmation\slint-rust-template\target\debug\build\slint-rust-template-ec625021f24eae21\out\app-window.rs:6:38
   |
 6 |      # [derive (serde :: Serialize , serde :: Deserialize)] # [derive (Default , PartialEq , Debug , Clone)] pub struct r#DocPage {
   |                                      ^^^^^^^^^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `ModelRc<slint::SharedString>`
   |
   = note: for local types consider adding `#[derive(serde::Deserialize)]` to your `ModelRc<slint::SharedString>` type
   = note: for types from other crates check whether the crate offers a `serde` feature flag
   = help: the following other types implement trait `Deserialize<'de>`:
             &'a [u8]
             &'a std::path::Path
             &'a str
             ()
             (T,)
             (T0, T1)
             (T0, T1, T2)
             (T0, T1, T2, T3)
           and 183 others
note: required by a bound in `slint_generatedAppWindow::_::_serde::__private228::de::missing_field`
  --> C:\Users\atomicboolean\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\serde-1.0.228\src\private\de.rs:26:8
   |
24 | pub fn missing_field<'de, V, E>(field: &'static str) -> Result<V, E>
   |        ------------- required by a bound in this function
25 | where
26 |     V: Deserialize<'de>,
   |        ^^^^^^^^^^^^^^^^ required by this bound in `missing_field`
   = note: this error originates in the derive macro `serde::Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
error: could not compile `slint-rust-template` (bin "slint-rust-template") due to 4 previous errors

Reproducible Code (if applicable)

@rust-addr(derive(serde::Serialize, serde::Deserialize))
export struct Content {
    lines: [string]
}

serde-bug.zip

Environment Details

  • Slint Version: 1.15.1
  • Platform/OS: Windows 10
  • Programming Language: Rust
  • Backend/Renderer: default

Product Impact

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    need triagingIssue that the owner of the area still need to triage

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions