Skip to content
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

Heterogeneous comparisons for Option #917

Closed
petrochenkov opened this issue Feb 27, 2015 · 5 comments
Closed

Heterogeneous comparisons for Option #917

petrochenkov opened this issue Feb 27, 2015 · 5 comments
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.

Comments

@petrochenkov
Copy link
Contributor

It would be useful to be able to compare Option<T> with Option<U> if T and U are comparable themselves. I.e.

impl<A, B> PartialEq<Option<B>> for Option<A> where A: PartialEq<B> { ... }

assert!(Some(String::from_str("str")) == Some("str"))

Heterogeneous comparisons for Option are clear and unambiguous and there are precedents - some other basic library types, like Vec or [T] support heterogeneous comparisons too.

cc @aturon
cc rust-lang/rust#22838

@huonw huonw added the A-libs label Feb 28, 2015
@petrochenkov
Copy link
Contributor Author

For some reason after this change Some("str") == None can't infer the type of None despite the fact that PartialEq has default type parameter.
At the same time Some(0u8) == None still can infer the type of None.

@Gankra
Copy link
Contributor

Gankra commented Feb 28, 2015

Default type parameters do not currently drive inference, iirc.

@aturon
Copy link
Member

aturon commented Feb 28, 2015

There is an issue open for generalizing comparison across all types in std. This is mainly a matter of what's been implemented, rather than a strong philosophical stance.

cc rust-lang/rust#20927 as well.

@bluss
Copy link
Member

bluss commented Feb 9, 2016

Potentially leads to widespread type inference regressions, when x == y can not hint the type for y anymore.

@petrochenkov
Copy link
Contributor Author

Closing in favor of more general rust-lang/rust#20063.

@petrochenkov petrochenkov added the T-libs-api Relevant to the library API team, which will review and decide on the RFC. label Jan 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

5 participants