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

Comments

Projects
None yet
5 participants
@petrochenkov
Copy link
Contributor

petrochenkov commented Feb 27, 2015

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

This comment has been minimized.

Copy link
Contributor Author

petrochenkov commented Feb 28, 2015

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.

@Gankro

This comment has been minimized.

Copy link
Contributor

Gankro commented Feb 28, 2015

Default type parameters do not currently drive inference, iirc.

@aturon

This comment has been minimized.

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

This comment has been minimized.

Copy link

bluss commented Feb 9, 2016

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

@petrochenkov

This comment has been minimized.

Copy link
Contributor Author

petrochenkov commented Jan 19, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.