yew icon indicating copy to clipboard operation
yew copied to clipboard

Can't use `Self` in generic when deriving `Properties`

Open Victor-N-Suadicani opened this issue 8 months ago • 0 comments

Problem

Example code should explain the problem:

use std::marker::PhantomData;

use yew::prelude::*;

#[derive(PartialEq, Eq)]
struct Generic<T>(PhantomData<T>);

// This works fine.
#[derive(Properties, PartialEq, Eq)]
struct Properties1 {
    gen: Generic<Properties1>,
}

// This doesn't work, even though it's equivalent.
#[derive(Properties, PartialEq, Eq)]
struct Properties2 {
    gen: Generic<Self>,
}

Steps To Reproduce Steps to reproduce the behavior:

  1. Compile above code without Properties2.
  2. Observe that it compiles.
  3. Run above code with Properties2.
  4. Observe that it does not compile.

Expected behavior The code with Properties2 should compile as it is equivalent to the first one. Probably the problem lies in the Self keyword being misunderstood as the fields are put into a different struct.

Environment:

  • Yew version: v0.21
  • Rust version: 1.74.1

Victor-N-Suadicani avatar Dec 11 '23 10:12 Victor-N-Suadicani