Skip to content

Can't use Self in generic when deriving Properties #3557

@Victor-N-Suadicani

Description

@Victor-N-Suadicani

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions