-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Illegal Eq derive in an enum with Option<f64> #103157
Comments
I have played around a bit with the example and got pub struct Wrap<T> {
inner: T,
}
impl<T> PartialEq for Wrap<T>
where
T: PartialEq,
{
fn eq(&self, other: &Self) -> bool {
self.inner.eq(&other.inner)
}
}
impl<T> Eq for Wrap<T> where T: Eq {}
#[derive(PartialEq, Eq)]
pub struct SuperWrap<T> {
thing: Wrap<T>,
float: Wrap<f64>
}
fn reflexivity<T>(a: &T) where T: Eq {
assert!(a == a)
}
fn main() {
let a = SuperWrap {
thing: Wrap { inner: 42_u64 },
float: Wrap { inner: f64::NAN },
};
reflexivity(&a);
} You can reproduce this in the Playground. As you can see, the compiler is tricked into thinking that
I have little experience with |
Expanding the macro yields a impl ::core::cmp::Eq for Value {
#[inline]
#[doc(hidden)]
#[no_coverage]
fn assert_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<Option<bool>>;
}
} looks like it only asserts @rustbot claim |
Gonna hand it over to you @fuzzypixelz as discussed on zulip |
@rustbot claim |
On 1.63.0 this failed to compile, as expected (godbolt):
@rustbot label regression-from-stable-to-stable |
this was recently introduced when @nnethercote was doing derive optimizations. |
I'll take a look today, thanks for the report. |
Don't worry, we've found the issue already, just wanted to let you know. |
See #103176 for the fix. |
WG-prioritization assigning priority a posteriori (Zulip discussion) mostly to help tracking the fix progress. @rustbot label -I-prioritize +P-high |
…ath, r=spastorino Fix `TyKind::is_simple_path` Fixes rust-lang#103157. r? `@spastorino`
PR rust-lang#98758 introduced code to avoid redundant assertions in derived code like this: ``` let _: ::core::clone::AssertParamIsClone<u32>; let _: ::core::clone::AssertParamIsClone<u32>; ``` But the predicate `is_simple_path` introduced as part of this failed to account for generic arguments. Therefore the deriving code erroneously considers types like `Option<bool>` and `Option<f32>` to be the same. This commit fixes `is_simple_path`. Fixes rust-lang#103157. (cherry picked from commit 9a23f60)
PR rust-lang#98758 introduced code to avoid redundant assertions in derived code like this: ``` let _: ::core::clone::AssertParamIsClone<u32>; let _: ::core::clone::AssertParamIsClone<u32>; ``` But the predicate `is_simple_path` introduced as part of this failed to account for generic arguments. Therefore the deriving code erroneously considers types like `Option<bool>` and `Option<f32>` to be the same. This commit fixes `is_simple_path`. Fixes rust-lang#103157.
I tried this code:
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:Meta
rustc --version --verbose
:It's reproducible in Playground in Stable, Beta and Nightly.
The text was updated successfully, but these errors were encountered: