Skip to content

Serde generates strange bounds on generics #938

@kryptan

Description

@kryptan

Given the following code:

#[derive(Serialize)]
struct A<T> {
    b: B<T>,
}

serde generates the following bound: where T: _serde::Serialize while I would expect it to generate where B<T>: _serde::Serialize. Generated bound is wrong in some cases, e.g. if B is implemented as follows:

#[derive(Serialize)]
struct B<T> {
    #[serde(skip_serializing)]
    b: T,
}

I'm currently writing my own custom-derive plugin for other purposes and I'm just putting the same bound on every field type. Serde, instead, uses some complex code to figure out what bounds to use and I'm curious why is it necessary.

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