Closed
Description
I tried this code:
#[derive(PartialEq, Eq)]
pub enum Value {
Boolean(Option<bool>),
Float(Option<f64>),
}
fn main() {
let a = Value::Float(Some(f64::NAN));
// Eq should always have a == a
// https://doc.rust-lang.org/std/cmp/trait.Eq.html
assert!(a == a);
}
I expected to see this happen: code fails to compile.
Instead, this happened: code compiles, and assertion fails.
Changing order of enum variants to make Float
go first fixes the issue:
// error[E0277] the trait bound `f64: Eq` is not satisfied
#[derive(PartialEq, Eq)]
-- in this derive macro expansion
pub enum Value {
Float(Option<f64>),
Boolean(Option<bool>),
}
Meta
rustc --version --verbose
:
rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: aarch64-apple-darwin
release: 1.64.0
LLVM version: 14.0.6
It's reproducible in Playground in Stable, Beta and Nightly.