Repository navigation
1.92 regression: Behavior change in PartialEq impl of BTreeSet? #149122
Copy link
Copy link
Closed
Labels
A-collectionsArea: `std::collections`Area: `std::collections`A-iteratorsArea: IteratorsArea: IteratorsC-bugCategory: This is a bug.Category: This is a bug.P-mediumMedium priorityMedium priorityS-has-bisectionStatus: A bisection has been found for this issueStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: 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.Relevant to the library team, which will review and decide on the PR/issue.perf-regressionPerformance regression.Performance regression.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.
Milestone
Description
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?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-collectionsArea: `std::collections`Area: `std::collections`A-iteratorsArea: IteratorsArea: IteratorsC-bugCategory: This is a bug.Category: This is a bug.P-mediumMedium priorityMedium priorityS-has-bisectionStatus: A bisection has been found for this issueStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: 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.Relevant to the library team, which will review and decide on the PR/issue.perf-regressionPerformance regression.Performance regression.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.
Activity
theemathas commentedon Nov 20, 2025
Bisection results:
Seems like it regressed in #147101. cc @yotamofek
theemathas commentedon Nov 20, 2025
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.workingjubilee commentedon Nov 20, 2025
cc @jdonszelmann also as reviewer
7 remaining items
Auto merge of #149125 - zachs18:btreemap-eq-perf, r=workingjubilee
Auto merge of #149125 - zachs18:btreemap-eq-perf, r=workingjubilee
Auto merge of #149125 - zachs18:btreemap-eq-perf, r=workingjubilee
Auto merge of #149125 - zachs18:btreemap-eq-perf, r=workingjubilee
Auto merge of #149125 - zachs18:btreemap-eq-perf, r=workingjubilee
Auto merge of #149125 - zachs18:btreemap-eq-perf, r=workingjubilee
Auto merge of rust-lang#149125 - zachs18:btreemap-eq-perf, r=workingj…
Auto merge of #149125 - zachs18:btreemap-eq-perf, r=workingjubilee
Auto merge of #149125 - zachs18:btreemap-eq-perf, r=workingjubilee
Auto merge of rust-lang#149125 - zachs18:btreemap-eq-perf, r=workingj…
Auto merge of #149125 - zachs18:btreemap-eq-perf, r=workingjubilee
Auto merge of #149125 - zachs18:btreemap-eq-perf, r=workingjubilee
Auto merge of #149125 - zachs18:btreemap-eq-perf, r=workingjubilee