Skip to content

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

Closed

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?

Activity

  1. added
    C-bugCategory: This is a bug.
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    on Nov 20, 2025
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Nov 20, 2025
  3. added
    S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
    on Nov 20, 2025
  4. theemathas commented on Nov 20, 2025

    @theemathas
    ContributorAuthor

    Bisection results:

    searched toolchains 064cc81354a940e297a1be4dfa9e26759c8431be through f435972085b697a1ece8ee6a1ac76efff8d1df7b
    
    
    ********************************************************************************
    Regression in 21a13b8864a7dd614e9a96afd57b58c7fcf0bd6b
    ********************************************************************************
    
    Attempting to search unrolled perf builds
    Found commits ["1d14c616", "ba8f00d9", "196d798a", "69e8b5e1", "3ac23352"]
    installing 1d14c61677c25ed1ce05d1460b27ffdd93e49fce
    uninstalling 1d14c61677c25ed1ce05d1460b27ffdd93e49fce
    installing ba8f00d9c8f62c468d9e3afc4f48dff026e746da
    uninstalling ba8f00d9c8f62c468d9e3afc4f48dff026e746da
    installing 196d798afa1c6d8ef56fd0c50da732bfaafcebd6
    uninstalling 196d798afa1c6d8ef56fd0c50da732bfaafcebd6
    installing 69e8b5e177df0c8d4da415cd457f6f129a3da461
    uninstalling 69e8b5e177df0c8d4da415cd457f6f129a3da461
    installing 3ac23352136cc99fd425c8ca6c40235197979e56
    uninstalling 3ac23352136cc99fd425c8ca6c40235197979e56
    ERROR: none of the toolchains satisfied the predicate
    

    Seems like it regressed in #147101. cc @yotamofek

  5. theemathas commented on Nov 20, 2025

    @theemathas
    ContributorAuthor

    My guess is that, comparing two BTreeSets with different sizes used to not look at the set contents if the number of elements are unequal. In beta, it now looks at the actual set contents without checking the number of elements first. So, this is likely a performance regression, even for correctly-written code.

  6. added and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Nov 20, 2025
  7. workingjubilee commented on Nov 20, 2025

    @workingjubilee
    Member

    cc @jdonszelmann also as reviewer

  8. 7 remaining items

  9. added a commit that references this issue on Dec 2, 2025
  10. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Dec 4, 2025
  11. added 2 commits that reference this issue on Dec 16, 2025
  12. added a commit that references this issue on Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-collectionsArea: `std::collections`A-iteratorsArea: IteratorsC-bugCategory: This is a bug.P-mediumMedium priorityS-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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions