Skip to content

Conversation

@ShoyuVanilla
Copy link
Member

It says that PartialEq for &T implementation calls core::ptr::eq<T> but this is not true as &T does not implement PartialEq unless T implements PartialEq; the following code is not compiled.

struct Foo;

fn main() {
    let a = Foo;
    let b = Foo;
    assert!(&a == &b);
}
error[E0369]: binary operation `==` cannot be applied to type `&Foo`
 --> src/main.rs:6:16
  |
6 |     assert!(&a == &b);
  |             -- ^^ -- &Foo
  |             |
  |             &Foo
  |
note: an implementation of `PartialEq` might be missing for `Foo`
 --> src/main.rs:1:1
  |
1 | struct Foo;
  | ^^^^^^^^^^ must implement `PartialEq`
help: consider annotating `Foo` with `#[derive(PartialEq)]`
  |
1 + #[derive(PartialEq)]
2 | struct Foo;
  |

For more information about this error, try `rustc --explain E0369`.

And even if it implements PartialEq, it does not actually call core::ptr::eq<T> for the reference comparision.

#[derive(PartialEq)]
struct Foo;

fn main() {
    let a = Foo;
    let b = Foo;
    assert!(&a == &b);
    assert!(!std::ptr::eq::<Foo>(&a, &b));
}

@rustbot
Copy link
Collaborator

rustbot commented Feb 20, 2025

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 20, 2025
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you may be misinterpreting what the parentheses are trying to say. Specifically:

rather than comparing the values they point to (which is what the PartialEq for &T implementation does)

This is saying that core::ptr::eq::<T> does not compare the values that the references point to, and is saying that PartialEq for &T does compare the values that the references point to.

The wording on master is not incorrect as far as I can tell.

@ShoyuVanilla
Copy link
Member Author

I think you may be misinterpreting what the parentheses are trying to say. Specifically:

rather than comparing the values they point to (which is what the PartialEq for &T implementation does)

This is saying that core::ptr::eq::<T> does not compare the values that the references point to, and is saying that PartialEq for &T does compare the values that the references point to.

The wording on master is not incorrect as far as I can tell.

Oh, what a silly misreading 😅 thanks!

@ShoyuVanilla ShoyuVanilla deleted the patch-1 branch February 20, 2025 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants