rust-lang / rust-lang/rfcs

More general PartialEq implementation for Option

Open
#1,239 5 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-libs
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

Currently, only the case where T == U is covered. Presumably this is because of derive limitations, since this impl is indeed derived in libcore.

I believe it should be possible and correct to provide the following impl:

impl<T, U> PartialEq<Option<U>> for Option<T> where T: PartialEq<U>, U: PartialEq<T> {
    fn eq(&self, rhs: &Option<U>) -> bool {
        match (self, rhs) {
            (&Some(ref lhs), &Some(ref rhs)) if lhs == rhs => true,
            (&None, &None) => true,
            _ => false
        }
    }
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Option PartialEq implementation in libcore and the linked Option::eq documentation. Compare the existing same-type case with the proposed cross-type implementation, then check whether Rust's trait rules permit it. Done means the supported PartialEq behavior is clearly established and covered by the relevant core tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.