Skip to content

1.92 regression: Behavior change in PartialEq impl of BTreeSet? #149122

@theemathas

Description

@theemathas

Test failure found in the beta crater run:

[INFO] [stdout] thread 'atom::tests::test_possible_states_eq' (22) panicked at src/value.rs:63:18:
[INFO] [stdout] can't compare values String("a") and Number(0)

https://crater-reports.s3.amazonaws.com/beta-1.92-4/beta-2025-11-10/gh/ttaubert.tlc/log.txt

Minimized reproducer:

use std::cmp::Ordering;
use std::collections::BTreeSet;

#[derive(Debug)]
pub(crate) enum Value {
    One,
    Two(i32),
}

impl Ord for Value {
    fn cmp(&self, other: &Value) -> Ordering {
        match (self, other) {
            (Value::One, Value::One) => Ordering::Equal,
            (Value::Two(x), Value::Two(y)) => x.cmp(y),
            _ => panic!("can't compare values {:?} and {:?}", self, other),
        }
    }
}

impl PartialOrd for Value {
    fn partial_cmp(&self, other: &Value) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl PartialEq for Value {
    fn eq(&self, other: &Value) -> bool {
        match (self, other) {
            (Value::One, Value::One) => true,
            (Value::Two(x), Value::Two(y)) => x == y,
            _ => panic!("can't compare values {:?} and {:?}", self, other),
        }
    }
}

impl Eq for Value {}

fn main() {
    let lhs = BTreeSet::from([Value::One]);
    let rhs = BTreeSet::from([Value::Two(1), Value::Two(2)]);
    let _ = lhs == rhs;
}

This code runs without errors on stable, but panics on beta.

It's reasonable to say that this code should have panicked in the first place, but still, it's strange that the behavior changed. So, maybe this needs some investigation on what happened?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-collectionsArea: `std::collections`A-iteratorsArea: IteratorsC-bugCategory: This is a bug.I-prioritizeIssue: Indicates that prioritization has been requested for this issue.S-has-bisectionStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-libsRelevant to the library team, which will review and decide on the PR/issue.perf-regressionPerformance regression.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions