Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types used in remote derive are dead code #976

Closed
dtolnay opened this issue Jul 3, 2017 · 1 comment
Closed

Types used in remote derive are dead code #976

dtolnay opened this issue Jul 3, 2017 · 1 comment

Comments

@dtolnay
Copy link
Member

dtolnay commented Jul 3, 2017

Remote derive structs exist only to tell serde_derive what are the fields of the real struct. As such, no code uses the fields of the remote derive struct.

#[macro_use]
extern crate serde_derive;

extern crate serde;

#[derive(Serialize)]
#[serde(remote = "S")]
struct SDef {
    a: u32,
}

struct S {
    a: u32,
}

#[derive(Serialize)]
struct W {
    #[serde(with = "SDef")]
    s: S,
}

fn main() {}
warning: field is never used: `a`
 --> src/main.rs:9:5
  |
9 |     a: u32,
  |     ^^^^^^
  |
  = note: #[warn(dead_code)] on by default

Let's emit some silly code along with the derive to use each field so the user doesn't need to put #[allow(dead_code)] on every remote derive struct.

@dtolnay
Copy link
Member Author

dtolnay commented Jul 3, 2017

Things to be careful about:

  • Should work for non-public structs.
  • Should work for structs with fields of non-public type.
  • Should work for structs with generic type parameters.
  • Should work for structs with type parameters bound by a non-public trait.
  • Should work for structs with lifetime parameters.
  • All of the above but for enums.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant