-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Factual error in PartialEq
documentation
#91843
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
Comments
I assume this is because auto(de)ref kicks in for the method version but not the operator version. |
Yes (and experimenting with changing that is what #44762 is about). |
The reference on comparison operators clarifies:
|
But that's also counterfactual! // Commented code does not compile
fn main() {
let v = 1;
let x: *const u32 = &v;
let y: &u32 = &1;
let _ = dbg!(x == y);
// let _ = dbg!(PartialEq::eq(x, y));
// let _ = dbg!(PartialEq::eq(x, &y));
// let _ = dbg!(PartialEq::eq(&x, y));
// let _ = dbg!(PartialEq::eq(&x, &y));
let _ = dbg!(PartialEq::eq(&x, &(y as _)));
// But that can't be a desugaring...
// let _ = dbg!(v == y);
let _ = dbg!(&v == y);
// let _ = dbg!(PartialEq::eq(&v, &(y as _)));
} Operator resolution is its own thing with many niche differences and, in my opinion, all phrasing like "equivalent to" / "can be written as" / "is the same as" / "desugars" should be replaced with something more like "is notionally" / "is like" / etc, perhaps with a list of exceptions you're likely to hit. Another example from the reference is compound assignment (
Even modulo the exceptions they did cover, the remaining cases are not equivalent because // commented code does not compile
use core::num::Wrapping;
fn main() {
let n = &mut [Wrapping(0)][..];
n[0] += n[0];
// std::ops::AddAssign::add_assign(&mut n[0], n[0]);
} |
@QuineDot it seems to me that you have accumulated enough knowledge around this issue to create a good PR for this. The documentation lives here: https://github.com/rust-lang/rust/blob/master/library/core/src/cmp.rs. |
The documentation for
PartialEq
states:This is not true, as #44762 illustrates, as well as this URLO-inspired example:
The other operator's documentation don't have this error.
Shl
(andShr
) also explicitly note some differences in inference between operators and the method call.@rustbot label +A-docs
The text was updated successfully, but these errors were encountered: