Skip to content

Conversation

nham
Copy link
Contributor

@nham nham commented Jul 13, 2014

cc #15294

Does it make sense to just implement PartialOrd for every type that implements Set? There is a well-defined partial order on sets based on set inclusion. I'm thinking something like this:

impl<T, S: Set<T>> PartialOrd for S {
    fn partial_cmp(&self, other: &S) -> Option<Ordering> {
        match (self.is_subset(other), other.is_subset(self)) {
            (true, true) => Some(Equal),
            (true, false) => Some(Less),
            (false, true) => Some(Greater),
            (false, false) => None
        }
    }
}

@nham nham changed the title Implement Hash for HashMap and HashSet and PartialOrd for HashSet Implement Hash for HashMap and HashSet, PartialOrd for HashSet Jul 13, 2014
@nham nham changed the title Implement Hash for HashMap and HashSet, PartialOrd for HashSet Implement Hash for HashMap and HashSet, and PartialOrd for HashSet Jul 13, 2014
@thestinger
Copy link
Contributor

I don't think so. We've been consistent in using PartialOrd and Ord as lexicographic orderings, including for types like TreeSet. You can't have it both ways, and it would be incredibly confusing to have it use one definition for some types (HashSet) and another definition for others (TreeSet).

@nham
Copy link
Contributor Author

nham commented Jul 13, 2014

Hmm, you're right. I don't know why I thought this would work. I will nix the Hash implementations for now, I need to study the code more closely.

@nham nham changed the title Implement Hash for HashMap and HashSet, and PartialOrd for HashSet Implement PartialOrd for HashSet Jul 13, 2014
@nham
Copy link
Contributor Author

nham commented Jul 13, 2014

@thestinger Okay, I see what you mean. So to keep it in alignment with the way TreeSet works, for example, we'd need some way to iterate through the HashSet in order, and then we could use the same comparison method that TreeSet uses.

@nham
Copy link
Contributor Author

nham commented Jul 13, 2014

Although this seems counterintuitive to me. If I'm comparing two sets, I would expect the usual partial order from math.

@nham nham closed this Jul 21, 2014
flip1995 pushed a commit to flip1995/rust that referenced this pull request Oct 6, 2025
…t-lang#15647)

Fixes rust-lang/rust-clippy#13365

Pretty much the exact approach described in
rust-lang/rust-clippy#13365 (comment),
thank you @Jarcho!
r? @Jarcho

changelog: [`collapsible_if`]: respect `#[expect]` on inner `if`
changelog: [`collapsible_else_if`]: respect `#[expect]` on inner `if`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants