Stream: t-lang

Topic: Option, Option<&str>, PartialEq,and pattern matching


Josh Triplett (Feb 03 2020 at 07:02, on Zulip):

I understand the reasons why we can't have a fully general impl PartialEq<Option<RHS>> for Option<LHS> where LHS: PartialEq<RHS>.
But is there some specific reason we can't have the more specific impl PartialEq<Option<&str>> for Option<String> and vice versa?

Josh Triplett (Feb 03 2020 at 07:03, on Zulip):

Would even that narrow impl break backwards compatibility?

Josh Triplett (Feb 03 2020 at 07:03, on Zulip):

(Or break too many existing programs even if type inference stability rules allow us to make that change?)

Josh Triplett (Feb 03 2020 at 07:04, on Zulip):

Related: is there some fundamental reason we can't match an Option<String> against a pattern like Some("foo"), using a similar mechanism?

nikomatsakis (Feb 06 2020 at 19:30, on Zulip):

Not sure about the former, but I don't think there's a fundamental reason we can't have the latter

nikomatsakis (Feb 06 2020 at 19:30, on Zulip):

Apart from not having any such mechanism

nikomatsakis (Feb 06 2020 at 19:30, on Zulip):

It might interact some with inference in corner cases

Last update: Jun 07 2020 at 10:05UTC