rust-derivative icon indicating copy to clipboard operation
rust-derivative copied to clipboard

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

Open mcarton opened this issue 4 years ago • 0 comments

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

mcarton avatar Jan 19 '21 23:01 mcarton