mcarton / rust-derivative

A set of alternative `derive` attributes for Rust
Apache License 2.0
420 stars 46 forks source link

`derivative(Eq)` doesn't require fields to implement `Eq` #85

Open mcarton opened 3 years ago

mcarton commented 3 years ago

The following compiles but shouldn't because Error is only PartialEq and not Eq:

#[derive(derivative::Derivative)]
#[derivative(PartialEq)]
struct Error;

#[derive(derivative::Derivative)]
#[derivative(PartialEq, Eq)]
struct Struct {
    x: Error,
}

fn main() {}

(Permalink to the playground)

Similarly

#[derive(PartialEq, Eq)]
struct Struct {
    x: f32,
}

shouldn't compile.

rustc enforces this using secret methods: https://github.com/rust-lang/rust/issues/13101