Skip to content

PartialEq between reference and non-reference type? #1332

Open
@LukasKalbertodt

Description

@LukasKalbertodt

I'm not sure, if that's intended, but it's "impossible" to compare a reference type with a non-reference type via PartialEq. Short example code:

let a = 3;
let b = 4;
&a == &b; // works
a == &b;   // doesn't work

This should work in my opinion. There already are these impls in std (I removed some noise -- original):

impl<A, B> PartialEq<&    B> for &    A where A: PartialEq<B>
impl<A, B> PartialEq<&mut B> for &mut A where A: PartialEq<B>
impl<A, B> PartialEq<&mut B> for &    A where A: PartialEq<B>
impl<A, B> PartialEq<&    B> for &mut A where A: PartialEq<B>

The third line in my example works because of this.

Why not something like this?

impl<A, B> PartialEq<&B> for  A where A: PartialEq<B>
impl<A, B> PartialEq< B> for &A where A: PartialEq<B>

Or do I misunderstand something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the RFC.T-libs-apiRelevant to the library API team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions